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) { long AnimCodeByWeapon(GameObject* weapon) {
if (weapon != nullptr) { if (weapon != nullptr) {
Proto* proto = GetProto(weapon->protoId); Proto* proto = nullptr;
if (proto != nullptr && proto->item.type == item_type_weapon) { if (GetProto(weapon->protoId, proto) && proto->item.type == item_type_weapon) {
return proto->item.weapon.animationCode; return proto->item.weapon.animationCode;
} }
} }
return 0; return 0;
} }
Proto* GetProto(long pid) { bool GetProto(long pid, Proto* outProto) {
Proto* protoPtr; return (fo::func::proto_ptr(pid, &outProto) != -1);
if (fo::func::proto_ptr(pid, &protoPtr) != -1) {
return protoPtr;
}
return nullptr;
} }
bool CritterCopyProto(long pid, long* &proto_dst) { bool CritterCopyProto(long pid, long* &proto_dst) {
fo::Proto* protoPtr; fo::Proto* proto = nullptr;
if (fo::func::proto_ptr(pid, &protoPtr) == -1) { 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; proto_dst = nullptr;
return false;
} }
proto_dst = reinterpret_cast<long*>(new long[104]); return result;
memcpy(proto_dst, protoPtr, 416);
return true;
} }
void SkillGetTags(long* result, long num) { void SkillGetTags(long* result, long num) {
@@ -165,21 +162,21 @@ long __fastcall IsRadInfluence() {
} }
bool IsNpcFlag(fo::GameObject* npc, long flag) { bool IsNpcFlag(fo::GameObject* npc, long flag) {
Proto* protoPtr; Proto* proto = nullptr;;
if (fo::func::proto_ptr(npc->protoId, &protoPtr) != -1) { if (GetProto(npc->protoId, proto)) {
return (protoPtr->critter.critterFlags & (1 << flag)) != 0; return (proto->critter.critterFlags & (1 << flag)) != 0;
} }
return false; return false;
} }
void ToggleNpcFlag(fo::GameObject* npc, long flag, bool set) { void ToggleNpcFlag(fo::GameObject* npc, long flag, bool set) {
Proto* protoPtr; Proto* proto = nullptr;;
if (fo::func::proto_ptr(npc->protoId, &protoPtr) != -1) { if (GetProto(npc->protoId, proto)) {
long bit = (1 << flag); long bit = (1 << flag);
if (set) { if (set) {
protoPtr->critter.critterFlags |= bit; proto->critter.critterFlags |= bit;
} else { } 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 // returns weapon animation code
long AnimCodeByWeapon(GameObject* weapon); long AnimCodeByWeapon(GameObject* weapon);
// returns pointer to prototype by PID, or nullptr on failure // returns False if the prototype does not exist, or pointer to prototype by PID in the outProto argument
Proto* GetProto(long pid); 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); bool CritterCopyProto(long pid, long* &proto_dst);
+47 -38
View File
@@ -205,29 +205,29 @@ enum class Material : long
namespace ObjectFlag { namespace ObjectFlag {
enum ObjectFlag : DWORD { enum ObjectFlag : DWORD {
Mouse_3d = 0x1, Mouse_3d = 0x1,
WalkThru = 0x4, WalkThru = 0x4,
Flat = 0x8, Flat = 0x8,
NoBlock = 0x10, NoBlock = 0x10,
Lighting = 0x20, Lighting = 0x20,
Temp = 0x400, Temp = 0x400,
MultiHex = 0x800, MultiHex = 0x800,
NoHighlight = 0x1000, NoHighlight = 0x1000,
Used = 0x2000, Used = 0x2000,
TransRed = 0x4000, TransRed = 0x4000,
TransNone = 0x8000, TransNone = 0x8000,
TransWall = 0x10000, TransWall = 0x10000,
TransGlass = 0x20000, TransGlass = 0x20000,
TransSteam = 0x40000, TransSteam = 0x40000,
TransEnergy = 0x80000, TransEnergy = 0x80000,
Left_Hand = 0x1000000, Left_Hand = 0x1000000,
Right_Hand = 0x2000000, Right_Hand = 0x2000000,
Worn = 0x4000000, Worn = 0x4000000,
HiddenItem = 0x8000000, HiddenItem = 0x8000000,
WallTransEnd = 0x10000000, WallTransEnd = 0x10000000,
LightThru = 0x20000000, LightThru = 0x20000000,
Seen = 0x40000000, Seen = 0x40000000,
ShootThru = 0x80000000, ShootThru = 0x80000000,
}; };
} }
@@ -314,7 +314,7 @@ enum ProtoId : long
//XXXXXXXXXXXXXXXXXXXXX //XXXXXXXXXXXXXXXXXXXXX
// Trait defines // // Trait defines //
#define TRAIT_PERK (0) #define TRAIT_PERK (0)
#define TRAIT_OBJECT (1) #define TRAIT_OBJECT (1)
#define TRAIT_TRAIT (2) #define TRAIT_TRAIT (2)
@@ -515,10 +515,10 @@ enum Stat : long
STAT_rad_resist = 31, STAT_rad_resist = 31,
STAT_poison_resist = 32, STAT_poison_resist = 32,
// poison_resist MUST be the last derived stat // poison_resist MUST be the last derived stat
// nonderived stats // non-derived stats
STAT_age = 33, STAT_age = 33,
STAT_gender = 34, STAT_gender = 34,
// gender MUST be the last nonderived stat // gender MUST be the last non-derived stat
STAT_current_hp = 35, STAT_current_hp = 35,
STAT_current_poison = 36, STAT_current_poison = 36,
STAT_current_rad = 37, STAT_current_rad = 37,
@@ -738,6 +738,14 @@ enum RollResult
ROLL_CRITICAL_SUCCESS = 0x3, ROLL_CRITICAL_SUCCESS = 0x3,
}; };
enum CombatStateFlag : long
{
InCombat = 1,
EnemyOutOfRange = 2,
IsFleeing = 4,
ReTarget = 8 // sfall flag
};
namespace Fields { namespace Fields {
enum CommonObj : long enum CommonObj : long
{ {
@@ -805,13 +813,14 @@ namespace WinFlags {
namespace AIpref { namespace AIpref {
enum distance : long enum distance : long
{ {
stay_close = 0, 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, charge = 1, // AI will always try to get close to its target before or after attack
snipe = 2, 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, on_your_own = 3, // no special behavior defined for this
stay = 4 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 enum disposition : long
{ {
none = -1, none = -1,
@@ -824,11 +833,11 @@ namespace AIpref {
enum class attack_who : long enum class attack_who : long
{ {
whomever_attacking_me = 0, whomever_attacking_me = 0, // attack the target that the player is attacking (only for party members)
strongest = 1, strongest = 1, // attack stronger targets (will switch to stronger ones in combat)
weakest = 2, weakest = 2, // attack weaker targets
whomever = 3, whomever = 3, // anyone
closest = 4, closest = 4, // only attack near targets
}; };
enum class run_away_mode : long enum class run_away_mode : long
@@ -850,13 +859,13 @@ namespace AIpref {
ranged_over_melee = 3, ranged_over_melee = 3,
ranged = 4, ranged = 4,
unarmed = 5, unarmed = 5,
unarmed_over_thrown = 6, // not available in party member control panel unarmed_over_thrown = 6, // not available for party member in control panel
random = 7 // not available in party member control panel random = 7 // not available for party member in control panel
}; };
enum class area_attack_mode : long 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, always = 0,
sometimes = 1, // use random value from cap.secondary_freq sometimes = 1, // use random value from cap.secondary_freq
be_sure = 2, // 85% hit chance be_sure = 2, // 85% hit chance