Code edits in EngineUtils.cpp

Added comments to some defines in Enums.h.
This commit is contained in:
NovaRain
2021-02-09 22:07:35 +08:00
parent 3567ec791c
commit fb84e557fe
3 changed files with 74 additions and 61 deletions
+18 -21
View File
@@ -56,31 +56,28 @@ Queue* QueueFind(GameObject* object, long type) {
long AnimCodeByWeapon(GameObject* weapon) {
if (weapon != nullptr) {
Proto* proto = GetProto(weapon->protoId);
if (proto != nullptr && proto->item.type == item_type_weapon) {
Proto* proto = nullptr;
if (GetProto(weapon->protoId, proto) && proto->item.type == item_type_weapon) {
return proto->item.weapon.animationCode;
}
}
return 0;
}
Proto* GetProto(long pid) {
Proto* protoPtr;
if (fo::func::proto_ptr(pid, &protoPtr) != -1) {
return protoPtr;
}
return nullptr;
bool GetProto(long pid, Proto* outProto) {
return (fo::func::proto_ptr(pid, &outProto) != -1);
}
bool CritterCopyProto(long pid, long* &proto_dst) {
fo::Proto* protoPtr;
if (fo::func::proto_ptr(pid, &protoPtr) == -1) {
fo::Proto* proto = nullptr;
bool result = GetProto(pid, proto);
if (result) {
proto_dst = reinterpret_cast<long*>(new int32_t[104]);
std::memcpy(proto_dst, proto, 416);
} else {
proto_dst = nullptr;
return false;
}
proto_dst = reinterpret_cast<long*>(new long[104]);
memcpy(proto_dst, protoPtr, 416);
return true;
return result;
}
void SkillGetTags(long* result, long num) {
@@ -165,21 +162,21 @@ long __fastcall IsRadInfluence() {
}
bool IsNpcFlag(fo::GameObject* npc, long flag) {
Proto* protoPtr;
if (fo::func::proto_ptr(npc->protoId, &protoPtr) != -1) {
return (protoPtr->critter.critterFlags & (1 << flag)) != 0;
Proto* proto = nullptr;;
if (GetProto(npc->protoId, proto)) {
return (proto->critter.critterFlags & (1 << flag)) != 0;
}
return false;
}
void ToggleNpcFlag(fo::GameObject* npc, long flag, bool set) {
Proto* protoPtr;
if (fo::func::proto_ptr(npc->protoId, &protoPtr) != -1) {
Proto* proto = nullptr;;
if (GetProto(npc->protoId, proto)) {
long bit = (1 << flag);
if (set) {
protoPtr->critter.critterFlags |= bit;
proto->critter.critterFlags |= bit;
} else {
protoPtr->critter.critterFlags &= ~bit;
proto->critter.critterFlags &= ~bit;
}
}
}
+9 -2
View File
@@ -53,8 +53,15 @@ Queue* QueueFind(GameObject* object, long type);
// returns weapon animation code
long AnimCodeByWeapon(GameObject* weapon);
// returns pointer to prototype by PID, or nullptr on failure
Proto* GetProto(long pid);
// returns False if the prototype does not exist, or pointer to prototype by PID in the outProto argument
bool GetProto(long pid, Proto* outProto);
// returns pointer to prototype by PID, or nullptr on get failure
// NOTE: not an efficient construction
__forceinline Proto* GetProto(long pid) {
Proto* proto = nullptr;;
return GetProto(pid, proto) ? proto : nullptr;
}
bool CritterCopyProto(long pid, long* &proto_dst);
+24 -15
View File
@@ -515,10 +515,10 @@ enum Stat : long
STAT_rad_resist = 31,
STAT_poison_resist = 32,
// poison_resist MUST be the last derived stat
// nonderived stats
// non-derived stats
STAT_age = 33,
STAT_gender = 34,
// gender MUST be the last nonderived stat
// gender MUST be the last non-derived stat
STAT_current_hp = 35,
STAT_current_poison = 36,
STAT_current_rad = 37,
@@ -738,6 +738,14 @@ enum RollResult
ROLL_CRITICAL_SUCCESS = 0x3,
};
enum CombatStateFlag : long
{
InCombat = 1,
EnemyOutOfRange = 2,
IsFleeing = 4,
ReTarget = 8 // sfall flag
};
namespace Fields {
enum CommonObj : long
{
@@ -805,13 +813,14 @@ namespace WinFlags {
namespace AIpref {
enum distance : long
{
stay_close = 0,
charge = 1,
snipe = 2,
on_your_own = 3,
stay = 4
stay_close = 0, // the attacker will stay at a distance no more than 5 hexes from the player (defined in ai_move_steps_closer, cai_perform_distance_prefs)
charge = 1, // AI will always try to get close to its target before or after attack
snipe = 2, // when the distance between the attacker and the target decreases, the attacker will try to move away from the target to a distance of up to 10 hexes
on_your_own = 3, // no special behavior defined for this
stay = 4 // the attacker will, if possible, stay at the hex where the combat started (defined in ai_move_steps_closer, ai_move_away)
};
// presets for party members
enum disposition : long
{
none = -1,
@@ -824,11 +833,11 @@ namespace AIpref {
enum class attack_who : long
{
whomever_attacking_me = 0,
strongest = 1,
weakest = 2,
whomever = 3,
closest = 4,
whomever_attacking_me = 0, // attack the target that the player is attacking (only for party members)
strongest = 1, // attack stronger targets (will switch to stronger ones in combat)
weakest = 2, // attack weaker targets
whomever = 3, // anyone
closest = 4, // only attack near targets
};
enum class run_away_mode : long
@@ -850,13 +859,13 @@ namespace AIpref {
ranged_over_melee = 3,
ranged = 4,
unarmed = 5,
unarmed_over_thrown = 6, // not available in party member control panel
random = 7 // not available in party member control panel
unarmed_over_thrown = 6, // not available for party member in control panel
random = 7 // not available for party member in control panel
};
enum class area_attack_mode : long
{
no_pref = -1, // special logic for NPC (not available in party member control panel)
no_pref = -1, // special logic for NPC (not available for party member in control panel)
always = 0,
sometimes = 1, // use random value from cap.secondary_freq
be_sure = 2, // 85% hit chance