Skip to content

Instantly share code, notes, and snippets.

@ranisalt
Last active September 11, 2017 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ranisalt/a238128104b7af3a17f1 to your computer and use it in GitHub Desktop.
Save ranisalt/a238128104b7af3a17f1 to your computer and use it in GitHub Desktop.
Passive monsters
From 8e70099afb04023b40f1ac4c4ac999cc22d11def Mon Sep 17 00:00:00 2001
From: Ranieri Althoff <ranisalt+otland@gmail.com>
Date: Mon, 20 Jul 2015 03:15:34 -0300
Subject: [PATCH] Enable monster passive behavior
---
src/luascript.cpp | 13 +++++++++++++
src/luascript.h | 1 +
src/monster.cpp | 4 ++++
src/monster.h | 3 +++
src/monsters.cpp | 3 +++
src/monsters.h | 1 +
6 files changed, 25 insertions(+)
diff --git a/src/luascript.cpp b/src/luascript.cpp
index b856a3f..5271569 100644
--- a/src/luascript.cpp
+++ b/src/luascript.cpp
@@ -2460,6 +2460,7 @@ void LuaScriptInterface::registerFunctions()
registerMethod("MonsterType", "isSummonable", LuaScriptInterface::luaMonsterTypeIsSummonable);
registerMethod("MonsterType", "isIllusionable", LuaScriptInterface::luaMonsterTypeIsIllusionable);
registerMethod("MonsterType", "isHostile", LuaScriptInterface::luaMonsterTypeIsHostile);
+ registerMethod("MonsterType", "isPassive", LuaScriptInterface::luaMonsterTypeIsPassive);
registerMethod("MonsterType", "isPushable", LuaScriptInterface::luaMonsterTypeIsPushable);
registerMethod("MonsterType", "isHealthShown", LuaScriptInterface::luaMonsterTypeIsHealthShown);
@@ -11297,6 +11298,18 @@ int LuaScriptInterface::luaMonsterTypeIsHostile(lua_State* L)
return 1;
}
+int LuaScriptInterface::luaMonsterTypeIsPassive(lua_State* L)
+{
+ // monsterType:isPassive()
+ MonsterType* monsterType = getUserdata<MonsterType>(L, 1);
+ if (monsterType) {
+ pushBoolean(L, monsterType->isPassive);
+ } else {
+ lua_pushnil(L);
+ }
+ return 1;
+}
+
int LuaScriptInterface::luaMonsterTypeIsPushable(lua_State* L)
{
// monsterType:isPushable()
diff --git a/src/luascript.h b/src/luascript.h
index 3a8aad2..e29a270 100644
--- a/src/luascript.h
+++ b/src/luascript.h
@@ -1176,6 +1176,7 @@ class LuaScriptInterface
static int luaMonsterTypeIsSummonable(lua_State* L);
static int luaMonsterTypeIsIllusionable(lua_State* L);
static int luaMonsterTypeIsHostile(lua_State* L);
+ static int luaMonsterTypeIsPassive(lua_State* L);
static int luaMonsterTypeIsPushable(lua_State* L);
static int luaMonsterTypeIsHealthShown(lua_State* L);
diff --git a/src/monster.cpp b/src/monster.cpp
index c33bf3c..498e4b0 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -640,6 +640,10 @@ bool Monster::selectTarget(Creature* creature)
return false;
}
+ if (isPassive() && !hasBeenAttacked(creature->getID())) {
+ return false;
+ }
+
auto it = std::find(targetList.begin(), targetList.end(), creature);
if (it == targetList.end()) {
//Target not found in our target list.
diff --git a/src/monster.h b/src/monster.h
index bb1afd9..2e20f55 100644
--- a/src/monster.h
+++ b/src/monster.h
@@ -113,6 +113,9 @@ class Monster final : public Creature
bool isHostile() const {
return mType->isHostile;
}
+ bool isPassive() const {
+ return mType->isPassive;
+ }
bool canSee(const Position& pos) const final;
bool canSeeInvisibility() const final {
return isImmune(CONDITION_INVISIBLE);
diff --git a/src/monsters.cpp b/src/monsters.cpp
index 82c9889..9ca5f6b 100644
--- a/src/monsters.cpp
+++ b/src/monsters.cpp
@@ -82,6 +82,7 @@ void MonsterType::reset()
isConvinceable = false;
isAttackable = true;
isHostile = true;
+ isPassive = false;
lightLevel = 0;
lightColor = 0;
@@ -809,6 +810,8 @@ bool Monsters::loadMonster(const std::string& file, const std::string& monsterNa
mType->isAttackable = attr.as_bool();
} else if (strcasecmp(attrName, "hostile") == 0) {
mType->isHostile = attr.as_bool();
+ } else if (strcasecmp(attrName, "passive") == 0) {
+ mType->isPassive = attr.as_bool();
} else if (strcasecmp(attrName, "illusionable") == 0) {
mType->isIllusionable = attr.as_bool();
} else if (strcasecmp(attrName, "convinceable") == 0) {
diff --git a/src/monsters.h b/src/monsters.h
index 01a6b89..af534cd 100644
--- a/src/monsters.h
+++ b/src/monsters.h
@@ -156,6 +156,7 @@ class MonsterType
bool isConvinceable;
bool isAttackable;
bool isHostile;
+ bool isPassive;
bool hiddenHealth;
void createLoot(Container* corpse);
--
2.5.0
@Anderson0xFF
Copy link

my monsters.cpp ne has isHostile = true;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment