diff --git a/src/Entities.hpp b/src/Entities.hpp index a4fe3ed..f69fc4a 100644 --- a/src/Entities.hpp +++ b/src/Entities.hpp @@ -6,6 +6,7 @@ #include enum class EntityType { + INVALID, PLAYER, SIMPLE_NPC, COMBAT_NPC, @@ -17,11 +18,11 @@ enum class EntityType { class Chunk; struct Entity { - EntityType type; - int x, y, z; - uint64_t instanceID; - ChunkPos chunkPos; - std::set viewableChunks; + EntityType type = EntityType::INVALID; + int x = 0, y = 0, z = 0; + uint64_t instanceID = 0; + ChunkPos chunkPos = {}; + std::set viewableChunks = {}; // destructor must be virtual, apparently virtual ~Entity() {} @@ -74,12 +75,11 @@ struct EntityRef { */ class BaseNPC : public Entity { public: - sNPCAppearanceData appearanceData; + sNPCAppearanceData appearanceData = {}; //NPCClass npcClass; - int playersInView; + int playersInView = 0; - BaseNPC() {}; BaseNPC(int x, int y, int z, int angle, uint64_t iID, int t, int id) { // XXX appearanceData.iX = x; appearanceData.iY = y; @@ -109,9 +109,32 @@ public: virtual void disappearFromViewOf(CNSocket *sock) override; }; +struct CombatNPC : public BaseNPC { + int maxHealth = 0; + int spawnX = 0; + int spawnY = 0; + int spawnZ = 0; + int level = 0; + + void (*_stepAI)() = nullptr; + + // XXX + CombatNPC(int x, int y, int z, int angle, uint64_t iID, int t, int id, int maxHP) : + BaseNPC(x, y, z, angle, iID, t, id), + maxHealth(maxHP) + {} + + virtual void stepAI() { + if (_stepAI != nullptr) + _stepAI(); + } +}; + +// Mob is in MobAI.hpp, Player is in Player.hpp + // TODO: decouple from BaseNPC struct Egg : public BaseNPC { - bool summoned; + bool summoned = false; bool dead = false; time_t deadUntil; @@ -132,17 +155,3 @@ struct Bus : public BaseNPC { virtual void enterIntoViewOf(CNSocket *sock) override; virtual void disappearFromViewOf(CNSocket *sock) override; }; - -#if 0 -struct NPC : public Entity { - void (*_stepAI)(); - - virtual void stepAI() {} -}; - -struct CombatNPC : public Entity { -}; - -struct Mob : public CombatNPC { -}; -#endif diff --git a/src/MobAI.hpp b/src/MobAI.hpp index b964681..789239f 100644 --- a/src/MobAI.hpp +++ b/src/MobAI.hpp @@ -11,51 +11,45 @@ enum class MobState { DEAD }; -struct Mob : public BaseNPC { +struct Mob : public CombatNPC { // general - MobState state; - int maxHealth; - int spawnX; - int spawnY; - int spawnZ; - int level; + MobState state = MobState::INACTIVE; - std::unordered_map unbuffTimes; + std::unordered_map unbuffTimes = {}; // dead time_t killedTime = 0; - time_t regenTime; + time_t regenTime = 0; bool summoned = false; bool despawned = false; // for the sake of death animations // roaming - int idleRange; - const int sightRange; + int idleRange = 0; + const int sightRange = 0; time_t nextMovement = 0; bool staticPath = false; - int roamX, roamY, roamZ; + int roamX = 0, roamY = 0, roamZ = 0; // combat CNSocket *target = nullptr; time_t nextAttack = 0; time_t lastDrainTime = 0; int skillStyle = -1; // -1 for nothing, 0-2 for corruption, -2 for eruption - int hitX, hitY, hitZ; // for use in ability targeting + int hitX = 0, hitY = 0, hitZ = 0; // for use in ability targeting // drop - int dropType; + int dropType = 0; // group int groupLeader = 0; - int offsetX, offsetY; - int groupMember[4] = {0, 0, 0, 0}; + int offsetX = 0, offsetY = 0; + int groupMember[4] = {}; // temporary; until we're sure what's what - nlohmann::json data; + nlohmann::json data = {}; Mob(int x, int y, int z, int angle, uint64_t iID, int t, nlohmann::json d, int32_t id) - : BaseNPC(x, y, z, angle, iID, t, id), - maxHealth(d["m_iHP"]), + : CombatNPC(x, y, z, angle, iID, t, id, d["m_iHP"]), sightRange(d["m_iSightRange"]) { state = MobState::ROAMING; diff --git a/src/Player.hpp b/src/Player.hpp index 8b7b724..c486012 100644 --- a/src/Player.hpp +++ b/src/Player.hpp @@ -12,86 +12,80 @@ #define PC_MAXHEALTH(level) (925 + 75 * (level)) struct Player : public Entity { - int accountId; - int accountLevel; // permission level (see CN_ACCOUNT_LEVEL enums) - int64_t SerialKey; - int32_t iID; - uint64_t FEKey; + int accountId = 0; + int accountLevel = 0; // permission level (see CN_ACCOUNT_LEVEL enums) + int64_t SerialKey = 0; + int32_t iID = 0; + uint64_t FEKey = 0; - int level; - int HP; - int slot; // player slot, not nano slot - int16_t mentor; - int32_t money; - int32_t fusionmatter; - int32_t batteryW; - int32_t batteryN; - sPCStyle PCStyle; - sPCStyle2 PCStyle2; - sNano Nanos[NANO_COUNT]; // acquired nanos - int equippedNanos[3]; - int activeNano; // active nano (index into Nanos) - int8_t iPCState; - int32_t iWarpLocationFlag; - int64_t aSkywayLocationFlag[2]; - int32_t iConditionBitFlag; - int32_t iSelfConditionBitFlag; - int8_t iSpecialState; + int level = 0; + int HP = 0; + int slot = 0; // player slot, not nano slot + int16_t mentor = 0; + int32_t money = 0; + int32_t fusionmatter = 0; + int32_t batteryW = 0; + int32_t batteryN = 0; + sPCStyle PCStyle = {}; + sPCStyle2 PCStyle2 = {}; + sNano Nanos[NANO_COUNT] = {}; // acquired nanos + int equippedNanos[3] = {}; + int activeNano = 0; // active nano (index into Nanos) + int8_t iPCState = 0; + int32_t iWarpLocationFlag = 0; + int64_t aSkywayLocationFlag[2] = {}; + int32_t iConditionBitFlag = 0; + int32_t iSelfConditionBitFlag = 0; + int8_t iSpecialState = 0; - //int x, y, z; in superclass - int angle; - int lastX, lastY, lastZ, lastAngle; - int recallX, recallY, recallZ, recallInstance; // also Lair entrances - //uint64_t instanceID; in superclass - sItemBase Equip[AEQUIP_COUNT]; - sItemBase Inven[AINVEN_COUNT]; - sItemBase Bank[ABANK_COUNT]; - sItemTrade Trade[12]; - int32_t moneyInTrade; - bool isTrading; - bool isTradeConfirm; + int angle = 0; + int lastX = 0, lastY = 0, lastZ = 0, lastAngle = 0; + int recallX = 0, recallY = 0, recallZ = 0, recallInstance = 0; // also Lair entrances + sItemBase Equip[AEQUIP_COUNT] = {}; + sItemBase Inven[AINVEN_COUNT] = {}; + sItemBase Bank[ABANK_COUNT] = {}; + sItemTrade Trade[12] = {}; + int32_t moneyInTrade = 0; + bool isTrading = false; + bool isTradeConfirm = false; - bool inCombat; - bool onMonkey; - int nanoDrainRate; - int healCooldown; + bool inCombat = false; + bool onMonkey = false; + int nanoDrainRate = 0; + int healCooldown = 0; - int pointDamage; - int groupDamage; - int fireRate; - int defense; + int pointDamage = 0; + int groupDamage = 0; + int fireRate = 0; + int defense = 0; - int64_t aQuestFlag[16]; - int tasks[ACTIVE_MISSION_COUNT]; - int RemainingNPCCount[ACTIVE_MISSION_COUNT][3]; - sItemBase QInven[AQINVEN_COUNT]; - int32_t CurrentMissionID; + int64_t aQuestFlag[16] = {}; + int tasks[ACTIVE_MISSION_COUNT] = {}; + int RemainingNPCCount[ACTIVE_MISSION_COUNT][3] = {}; + sItemBase QInven[AQINVEN_COUNT] = {}; + int32_t CurrentMissionID = 0; - sTimeLimitItemDeleteInfo2CL toRemoveVehicle; + sTimeLimitItemDeleteInfo2CL toRemoveVehicle = {}; - int32_t iIDGroup; - int groupCnt; - int32_t groupIDs[4]; - int32_t iGroupConditionBitFlag; + int32_t iIDGroup = 0; + int groupCnt = 0; + int32_t groupIDs[4] = {}; + int32_t iGroupConditionBitFlag = 0; - bool notify; - bool hidden; - bool unwarpable; + bool notify = false; + bool hidden = false; + bool unwarpable = false; - bool buddiesSynced; - int64_t buddyIDs[50]; - bool isBuddyBlocked[50]; + bool buddiesSynced = false; + int64_t buddyIDs[50] = {}; + bool isBuddyBlocked[50] = {}; - uint64_t iFirstUseFlag[2]; + uint64_t iFirstUseFlag[2] = {}; + time_t lastHeartbeat = 0; - // in superclass: - //ChunkPos chunkPos; - //std::set viewableChunks; - time_t lastHeartbeat; - - int suspicionRating; - time_t lastShot; - std::vector buyback; + int suspicionRating = 0; + time_t lastShot = 0; + std::vector buyback = {}; Player() { type = EntityType::PLAYER; } diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index 657c943..83075da 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -57,8 +57,8 @@ void PlayerManager::removePlayer(CNSocket* key) { // save player to DB Database::updatePlayer(plr); - EntityRef ref = {key}; // remove player visually and untrack + EntityRef ref = {key}; Chunking::removeEntityFromChunks(Chunking::getViewableChunks(plr->chunkPos), ref); Chunking::untrackEntity(plr->chunkPos, ref);