diff --git a/src/Abilities.cpp b/src/Abilities.cpp index d0c2a44..e07f913 100644 --- a/src/Abilities.cpp +++ b/src/Abilities.cpp @@ -142,7 +142,7 @@ bool doDebuff(CNSocket *sock, sSkillResult_Buff *respdata, int i, int32_t target } BaseNPC* npc = NPCManager::NPCs[targetID]; - if (npc->kind != EntityType::MOB) { + if (npc->kind != EntityKind::MOB) { std::cout << "[WARN] doDebuff: NPC is not a mob" << std::endl; return false; } @@ -213,7 +213,7 @@ bool doDamageNDebuff(CNSocket *sock, sSkillResult_Damage_N_Debuff *respdata, int } BaseNPC* npc = NPCManager::NPCs[targetID]; - if (npc->kind != EntityType::MOB) { + if (npc->kind != EntityKind::MOB) { std::cout << "[WARN] doDamageNDebuff: NPC is not a mob" << std::endl; return false; } @@ -281,7 +281,7 @@ bool doDamage(CNSocket *sock, sSkillResult_Damage *respdata, int i, int32_t targ } BaseNPC* npc = NPCManager::NPCs[targetID]; - if (npc->kind != EntityType::MOB) { + if (npc->kind != EntityKind::MOB) { std::cout << "[WARN] doDamage: NPC is not a mob" << std::endl; return false; } @@ -337,7 +337,7 @@ bool doLeech(CNSocket *sock, sSkillResult_Heal_HP *healdata, int i, int32_t targ } BaseNPC* npc = NPCManager::NPCs[targetID]; - if (npc->kind != EntityType::MOB) { + if (npc->kind != EntityKind::MOB) { std::cout << "[WARN] doLeech: NPC is not a mob" << std::endl; return false; } @@ -463,7 +463,7 @@ bool doHeal(Mob* mob, sSkillResult_Heal_HP* respdata, int i, int32_t targetID, i } BaseNPC* npc = NPCManager::NPCs[targetID]; - if (npc->kind != EntityType::MOB) { + if (npc->kind != EntityKind::MOB) { std::cout << "[WARN] doHeal: NPC is not a mob" << std::endl; return false; } diff --git a/src/Chunking.cpp b/src/Chunking.cpp index d26fe8d..6e96c0a 100644 --- a/src/Chunking.cpp +++ b/src/Chunking.cpp @@ -54,7 +54,7 @@ void Chunking::trackEntity(ChunkPos chunkPos, const EntityRef& ref) { chunks[chunkPos]->entities.insert(ref); - if (ref.type == EntityType::PLAYER) + if (ref.kind == EntityKind::PLAYER) chunks[chunkPos]->nplayers++; } @@ -66,7 +66,7 @@ void Chunking::untrackEntity(ChunkPos chunkPos, const EntityRef& ref) { chunk->entities.erase(ref); // gone - if (ref.type == EntityType::PLAYER) + if (ref.kind == EntityKind::PLAYER) chunks[chunkPos]->nplayers--; assert(chunks[chunkPos]->nplayers >= 0); @@ -89,19 +89,19 @@ void Chunking::addEntityToChunks(std::set chnks, const EntityRef& ref) { Entity *other = otherRef.getEntity(); // notify all visible players of the existence of this Entity - if (alive && otherRef.type == EntityType::PLAYER) { + if (alive && otherRef.kind == EntityKind::PLAYER) { ent->enterIntoViewOf(otherRef.sock); } // notify this *player* of the existence of all visible Entities - if (ref.type == EntityType::PLAYER && other->isExtant()) { + if (ref.kind == EntityKind::PLAYER && other->isExtant()) { other->enterIntoViewOf(ref.sock); } // for mobs, increment playersInView - if (ref.type == EntityType::MOB && otherRef.type == EntityType::PLAYER) + if (ref.kind == EntityKind::MOB && otherRef.kind == EntityKind::PLAYER) ((Mob*)ent)->playersInView++; - if (otherRef.type == EntityType::MOB && ref.type == EntityType::PLAYER) + if (otherRef.kind == EntityKind::MOB && ref.kind == EntityKind::PLAYER) ((Mob*)other)->playersInView++; } } @@ -121,19 +121,19 @@ void Chunking::removeEntityFromChunks(std::set chnks, const EntityRef& r Entity *other = otherRef.getEntity(); // notify all visible players of the departure of this Entity - if (alive && otherRef.type == EntityType::PLAYER) { + if (alive && otherRef.kind == EntityKind::PLAYER) { ent->disappearFromViewOf(otherRef.sock); } // notify this *player* of the departure of all visible Entities - if (ref.type == EntityType::PLAYER && other->isExtant()) { + if (ref.kind == EntityKind::PLAYER && other->isExtant()) { other->disappearFromViewOf(ref.sock); } // for mobs, decrement playersInView - if (ref.type == EntityType::MOB && otherRef.type == EntityType::PLAYER) + if (ref.kind == EntityKind::MOB && otherRef.kind == EntityKind::PLAYER) ((Mob*)ent)->playersInView--; - if (otherRef.type == EntityType::MOB && ref.type == EntityType::PLAYER) + if (otherRef.kind == EntityKind::MOB && ref.kind == EntityKind::PLAYER) ((Mob*)other)->playersInView--; } } @@ -155,7 +155,7 @@ static void emptyChunk(ChunkPos chunkPos) { // unspawn all of the mobs/npcs std::set refs(chunk->entities); for (const EntityRef& ref : refs) { - if (ref.type == EntityType::PLAYER) + if (ref.kind == EntityKind::PLAYER) assert(0); // every call of this will check if the chunk is empty and delete it if so @@ -268,14 +268,14 @@ void Chunking::createInstance(uint64_t instanceID) { std::cout << "Creating instance " << instanceID << std::endl; for (ChunkPos &coords : templateChunks) { for (const EntityRef& ref : chunks[coords]->entities) { - if (ref.type == EntityType::PLAYER) + if (ref.kind == EntityKind::PLAYER) continue; int npcID = ref.id; BaseNPC* baseNPC = (BaseNPC*)ref.getEntity(); // make a copy of each NPC in the template chunks and put them in the new instance - if (baseNPC->kind == EntityType::MOB) { + if (baseNPC->kind == EntityKind::MOB) { if (((Mob*)baseNPC)->groupLeader != 0 && ((Mob*)baseNPC)->groupLeader != npcID) continue; // follower; don't copy individually diff --git a/src/Combat.cpp b/src/Combat.cpp index afcd4ff..9ad825d 100644 --- a/src/Combat.cpp +++ b/src/Combat.cpp @@ -58,7 +58,7 @@ int CombatNPC::takeDamage(EntityRef src, int amt) { return 0; // don't hurt a mob casting corruption if (mob->state == AIState::ROAMING) { - assert(mob->target == nullptr && src.type == EntityType::PLAYER); // players only for now + assert(mob->target == nullptr && src.kind == EntityKind::PLAYER); // players only for now mob->transition(AIState::COMBAT, src); if (mob->groupLeader != 0) @@ -247,7 +247,7 @@ static void pcAttackNpcs(CNSocket *sock, CNPacketData *data) { BaseNPC* npc = NPCManager::NPCs[targets[i]]; - if (npc->kind != EntityType::MOB) { + if (npc->kind != EntityKind::MOB) { std::cout << "[WARN] pcAttackNpcs: NPC is not a mob" << std::endl; return; } @@ -441,7 +441,7 @@ static void pcAttackChars(CNSocket *sock, CNPacketData *data) { return; } - int32_t *pktdata = (int32_t*)((uint8_t*)data->buf + sizeof(sP_CL2FE_REQ_PC_ATTACK_CHARs)); + sGM_PVPTarget* pktdata = (sGM_PVPTarget*)((uint8_t*)data->buf + sizeof(sP_CL2FE_REQ_PC_ATTACK_CHARs)); if (!validOutVarPacket(sizeof(sP_FE2CL_PC_ATTACK_CHARs_SUCC), pkt->iTargetCnt, sizeof(sAttackResult))) { std::cout << "[WARN] bad sP_FE2CL_PC_ATTACK_CHARs_SUCC packet size\n"; @@ -462,7 +462,6 @@ static void pcAttackChars(CNSocket *sock, CNPacketData *data) { for (int i = 0; i < pkt->iTargetCnt; i++) { ICombatant* target = nullptr; - sGM_PVPTarget* targdata = (sGM_PVPTarget*)(pktdata + i * 2); std::pair damage; if (pkt->iTargetCnt > 1) @@ -470,10 +469,10 @@ static void pcAttackChars(CNSocket *sock, CNPacketData *data) { else damage.first = plr->pointDamage; - if (targdata->eCT == 1) { // eCT == 1; attack player + if (pktdata[i].eCT == 1) { // eCT == 1; attack player for (auto& pair : PlayerManager::players) { - if (pair.second->iID == targdata->iID) { + if (pair.second->iID == pktdata[i].iID) { target = pair.second; break; } @@ -489,14 +488,14 @@ static void pcAttackChars(CNSocket *sock, CNPacketData *data) { } else { // eCT == 4; attack mob - if (NPCManager::NPCs.find(targdata->iID) == NPCManager::NPCs.end()) { + if (NPCManager::NPCs.find(pktdata[i].iID) == NPCManager::NPCs.end()) { // not sure how to best handle this std::cout << "[WARN] pcAttackChars: NPC ID not found" << std::endl; return; } - BaseNPC* npc = NPCManager::NPCs[targdata->iID]; - if (npc->kind != EntityType::MOB) { + BaseNPC* npc = NPCManager::NPCs[pktdata[i].iID]; + if (npc->kind != EntityKind::MOB) { std::cout << "[WARN] pcAttackChars: NPC is not a mob" << std::endl; return; } @@ -515,7 +514,7 @@ static void pcAttackChars(CNSocket *sock, CNPacketData *data) { damage.first = target->takeDamage(sock, damage.first); - respdata[i].eCT = targdata->eCT; + respdata[i].eCT = pktdata[i].eCT; respdata[i].iID = target->getID(); respdata[i].iDamage = damage.first; respdata[i].iHP = target->getCurrentHP(); @@ -698,7 +697,7 @@ static void projectileHit(CNSocket* sock, CNPacketData* data) { } BaseNPC* npc = NPCManager::NPCs[pktdata[i]]; - if (npc->kind != EntityType::MOB) { + if (npc->kind != EntityKind::MOB) { std::cout << "[WARN] projectileHit: NPC is not a mob" << std::endl; return; } diff --git a/src/CustomCommands.cpp b/src/CustomCommands.cpp index 4c2bb9e..36e0108 100644 --- a/src/CustomCommands.cpp +++ b/src/CustomCommands.cpp @@ -283,10 +283,10 @@ static void unsummonWCommand(std::string full, std::vector& args, C return; } - if (NPCManager::NPCs.find(npc->id) != NPCManager::NPCs.end() && NPCManager::NPCs[npc->id]->kind == EntityType::MOB) { + if (NPCManager::NPCs.find(npc->id) != NPCManager::NPCs.end() && NPCManager::NPCs[npc->id]->kind == EntityKind::MOB) { int leadId = ((Mob*)npc)->groupLeader; if (leadId != 0) { - if (NPCManager::NPCs.find(leadId) == NPCManager::NPCs.end() || NPCManager::NPCs[leadId]->kind != EntityType::MOB) { + if (NPCManager::NPCs.find(leadId) == NPCManager::NPCs.end() || NPCManager::NPCs[leadId]->kind != EntityKind::MOB) { std::cout << "[WARN] unsummonW: leader not found!" << std::endl; } Mob* leadNpc = (Mob*)NPCManager::NPCs[leadId]; @@ -294,7 +294,7 @@ static void unsummonWCommand(std::string full, std::vector& args, C if (leadNpc->groupMember[i] == 0) break; - if (NPCManager::NPCs.find(leadNpc->groupMember[i]) == NPCManager::NPCs.end() || NPCManager::NPCs[leadNpc->groupMember[i]]->kind != EntityType::MOB) { + if (NPCManager::NPCs.find(leadNpc->groupMember[i]) == NPCManager::NPCs.end() || NPCManager::NPCs[leadNpc->groupMember[i]]->kind != EntityKind::MOB) { std::cout << "[WARN] unsommonW: leader can't find a group member!" << std::endl; continue; } @@ -324,7 +324,7 @@ static void toggleAiCommand(std::string full, std::vector& args, CN // return all mobs to their spawn points for (auto& pair : NPCManager::NPCs) { - if (pair.second->kind != EntityType::MOB) + if (pair.second->kind != EntityKind::MOB) continue; Mob* mob = (Mob*)pair.second; @@ -609,7 +609,7 @@ static void summonGroupCommand(std::string full, std::vector& args, } BaseNPC *npc = NPCManager::summonNPC(x, y, z, plr->instanceID, type, wCommand); - if (team == 2 && i > 0 && npc->kind == EntityType::MOB) { + if (team == 2 && i > 0 && npc->kind == EntityKind::MOB) { leadNpc->groupMember[i-1] = npc->id; Mob* mob = (Mob*)NPCManager::NPCs[npc->id]; mob->groupLeader = leadNpc->id; @@ -624,7 +624,7 @@ static void summonGroupCommand(std::string full, std::vector& args, if (PLAYERID(plr->instanceID) != 0) { npc = NPCManager::summonNPC(plr->x, plr->y, plr->z, plr->instanceID, type, wCommand, true); - if (team == 2 && i > 0 && npc->kind == EntityType::MOB) { + if (team == 2 && i > 0 && npc->kind == EntityKind::MOB) { leadNpc->groupMember[i-1] = npc->id; Mob* mob = (Mob*)NPCManager::NPCs[npc->id]; mob->groupLeader = leadNpc->id; @@ -639,7 +639,7 @@ static void summonGroupCommand(std::string full, std::vector& args, Chat::sendServerMessage(sock, "/summonGroup(W): placed mob with type: " + std::to_string(type) + ", id: " + std::to_string(npc->id)); - if (i == 0 && team == 2 && npc->kind == EntityType::MOB) { + if (i == 0 && team == 2 && npc->kind == EntityKind::MOB) { type = type2; leadNpc = (Mob*)NPCManager::NPCs[npc->id]; leadNpc->groupLeader = leadNpc->id; @@ -694,7 +694,7 @@ static void lairUnlockCommand(std::string full, std::vector& args, int lastDist = INT_MAX; for (Chunk *chnk : Chunking::getViewableChunks(plr->chunkPos)) { for (const EntityRef& ref : chnk->entities) { - if (ref.type == EntityType::PLAYER) + if (ref.kind == EntityKind::PLAYER) continue; BaseNPC* npc = (BaseNPC*)ref.getEntity(); diff --git a/src/Eggs.cpp b/src/Eggs.cpp index f29d5cc..64e2f12 100644 --- a/src/Eggs.cpp +++ b/src/Eggs.cpp @@ -124,7 +124,7 @@ static void eggStep(CNServer* serv, time_t currTime) { // check dead eggs and eggs in inactive chunks for (auto npc : NPCManager::NPCs) { - if (npc.second->kind != EntityType::EGG) + if (npc.second->kind != EntityKind::EGG) continue; auto egg = (Egg*)npc.second; @@ -163,7 +163,7 @@ static void eggPickup(CNSocket* sock, CNPacketData* data) { return; } auto egg = (Egg*)eggRef.getEntity(); - if (egg->kind != EntityType::EGG) { + if (egg->kind != EntityKind::EGG) { std::cout << "[WARN] Player tried to open something other than an?!" << std::endl; return; } diff --git a/src/Entities.cpp b/src/Entities.cpp index ba6d136..ff63053 100644 --- a/src/Entities.cpp +++ b/src/Entities.cpp @@ -12,7 +12,7 @@ static_assert(std::is_standard_layout::value); static_assert(std::is_trivially_copyable::value); EntityRef::EntityRef(CNSocket *s) { - type = EntityType::PLAYER; + kind = EntityKind::PLAYER; sock = s; } @@ -20,11 +20,11 @@ EntityRef::EntityRef(int32_t i) { id = i; assert(NPCManager::NPCs.find(id) != NPCManager::NPCs.end()); - type = NPCManager::NPCs[id]->kind; + kind = NPCManager::NPCs[id]->kind; } bool EntityRef::isValid() const { - if (type == EntityType::PLAYER) + if (kind == EntityKind::PLAYER) return PlayerManager::players.find(sock) != PlayerManager::players.end(); return NPCManager::NPCs.find(id) != NPCManager::NPCs.end(); @@ -33,7 +33,7 @@ bool EntityRef::isValid() const { Entity *EntityRef::getEntity() const { assert(isValid()); - if (type == EntityType::PLAYER) + if (kind == EntityKind::PLAYER) return PlayerManager::getPlayer(sock); return NPCManager::NPCs[id]; diff --git a/src/Entities.hpp b/src/Entities.hpp index d1e46e5..d6423ee 100644 --- a/src/Entities.hpp +++ b/src/Entities.hpp @@ -6,7 +6,7 @@ #include #include -enum class EntityType : uint8_t { +enum class EntityKind : uint8_t { INVALID, PLAYER, SIMPLE_NPC, @@ -27,7 +27,7 @@ enum class AIState { class Chunk; struct Entity { - EntityType kind = EntityType::INVALID; + EntityKind kind = EntityKind::INVALID; int x = 0, y = 0, z = 0; uint64_t instanceID = 0; ChunkPos chunkPos = {}; @@ -44,7 +44,7 @@ struct Entity { }; struct EntityRef { - EntityType type; + EntityKind kind; union { CNSocket *sock; int32_t id; @@ -57,10 +57,10 @@ struct EntityRef { Entity *getEntity() const; bool operator==(const EntityRef& other) const { - if (type != other.type) + if (kind != other.kind) return false; - if (type == EntityType::PLAYER) + if (kind == EntityKind::PLAYER) return sock == other.sock; return id == other.id; @@ -68,21 +68,20 @@ struct EntityRef { // arbitrary ordering bool operator<(const EntityRef& other) const { - if (type == other.type) { - if (type == EntityType::PLAYER) + if (kind == other.kind) { + if (kind == EntityKind::PLAYER) return sock < other.sock; else return id < other.id; } - return type < other.type; + return kind < other.kind; } }; /* * Interfaces */ - class ICombatant { public: ICombatant() {} @@ -173,7 +172,7 @@ struct Egg : public BaseNPC { Egg(uint64_t iID, int t, int32_t id, bool summon) : BaseNPC(0, iID, t, id) { summoned = summon; - kind = EntityType::EGG; + kind = EntityKind::EGG; } virtual bool isExtant() override { return !dead; } @@ -185,7 +184,7 @@ struct Egg : public BaseNPC { struct Bus : public BaseNPC { Bus(int angle, uint64_t iID, int t, int id) : BaseNPC(angle, iID, t, id) { - kind = EntityType::BUS; + kind = EntityKind::BUS; loopingPath = true; } diff --git a/src/Missions.cpp b/src/Missions.cpp index 5a33354..890bec5 100644 --- a/src/Missions.cpp +++ b/src/Missions.cpp @@ -371,7 +371,7 @@ static void taskStart(CNSocket* sock, CNPacketData* data) { for (ChunkPos& chunkPos : Chunking::getChunksInMap(plr->instanceID)) { // check all NPCs in the instance Chunk* chunk = Chunking::chunks[chunkPos]; for (EntityRef ref : chunk->entities) { - if (ref.type != EntityType::PLAYER) { + if (ref.kind != EntityKind::PLAYER) { BaseNPC* npc = (BaseNPC*)ref.getEntity(); NPCPath* path = Transport::findApplicablePath(npc->id, npc->type, missionData->iTaskNum); if (path != nullptr) { diff --git a/src/MobAI.cpp b/src/MobAI.cpp index 2a7661b..e4be6e5 100644 --- a/src/MobAI.cpp +++ b/src/MobAI.cpp @@ -58,13 +58,13 @@ void MobAI::clearDebuff(Mob *mob) { } void MobAI::followToCombat(Mob *mob) { - if (NPCManager::NPCs.find(mob->groupLeader) != NPCManager::NPCs.end() && NPCManager::NPCs[mob->groupLeader]->kind == EntityType::MOB) { + if (NPCManager::NPCs.find(mob->groupLeader) != NPCManager::NPCs.end() && NPCManager::NPCs[mob->groupLeader]->kind == EntityKind::MOB) { Mob* leadMob = (Mob*)NPCManager::NPCs[mob->groupLeader]; for (int i = 0; i < 4; i++) { if (leadMob->groupMember[i] == 0) break; - if (NPCManager::NPCs.find(leadMob->groupMember[i]) == NPCManager::NPCs.end() || NPCManager::NPCs[leadMob->groupMember[i]]->kind != EntityType::MOB) { + if (NPCManager::NPCs.find(leadMob->groupMember[i]) == NPCManager::NPCs.end() || NPCManager::NPCs[leadMob->groupMember[i]]->kind != EntityKind::MOB) { std::cout << "[WARN] roamingStep: leader can't find a group member!" << std::endl; continue; } @@ -84,7 +84,7 @@ void MobAI::followToCombat(Mob *mob) { } void MobAI::groupRetreat(Mob *mob) { - if (NPCManager::NPCs.find(mob->groupLeader) == NPCManager::NPCs.end() || NPCManager::NPCs[mob->groupLeader]->kind != EntityType::MOB) + if (NPCManager::NPCs.find(mob->groupLeader) == NPCManager::NPCs.end() || NPCManager::NPCs[mob->groupLeader]->kind != EntityKind::MOB) return; Mob* leadMob = (Mob*)NPCManager::NPCs[mob->groupLeader]; @@ -92,7 +92,7 @@ void MobAI::groupRetreat(Mob *mob) { if (leadMob->groupMember[i] == 0) break; - if (NPCManager::NPCs.find(leadMob->groupMember[i]) == NPCManager::NPCs.end() || NPCManager::NPCs[leadMob->groupMember[i]]->kind != EntityType::MOB) { + if (NPCManager::NPCs.find(leadMob->groupMember[i]) == NPCManager::NPCs.end() || NPCManager::NPCs[leadMob->groupMember[i]]->kind != EntityKind::MOB) { std::cout << "[WARN] roamingStep: leader can't find a group member!" << std::endl; continue; } @@ -127,7 +127,7 @@ bool MobAI::aggroCheck(Mob *mob, time_t currTime) { Chunk* chunk = *it; for (const EntityRef& ref : chunk->entities) { // TODO: support targetting other CombatNPCs - if (ref.type != EntityType::PLAYER) + if (ref.kind != EntityKind::PLAYER) continue; CNSocket *s = ref.sock; @@ -304,7 +304,7 @@ static void useAbilities(Mob *mob, time_t currTime) { Chunk* chunk = *it; for (const EntityRef& ref : chunk->entities) { // TODO: see aggroCheck() - if (ref.type != EntityType::PLAYER) + if (ref.kind != EntityKind::PLAYER) continue; CNSocket *s= ref.sock; @@ -452,7 +452,7 @@ void Mob::deadStep(time_t currTime) { // if mob is a group leader/follower, spawn where the group is. if (groupLeader != 0) { - if (NPCManager::NPCs.find(groupLeader) != NPCManager::NPCs.end() && NPCManager::NPCs[groupLeader]->kind == EntityType::MOB) { + if (NPCManager::NPCs.find(groupLeader) != NPCManager::NPCs.end() && NPCManager::NPCs[groupLeader]->kind == EntityKind::MOB) { Mob* leaderMob = (Mob*)NPCManager::NPCs[groupLeader]; x = leaderMob->x + offsetX; y = leaderMob->y + offsetY; @@ -675,7 +675,7 @@ void Mob::roamingStep(time_t currTime) { if (groupMember[i] == 0) break; - if (NPCManager::NPCs.find(groupMember[i]) == NPCManager::NPCs.end() || NPCManager::NPCs[groupMember[i]]->kind != EntityType::MOB) { + if (NPCManager::NPCs.find(groupMember[i]) == NPCManager::NPCs.end() || NPCManager::NPCs[groupMember[i]]->kind != EntityKind::MOB) { std::cout << "[WARN] roamingStep: leader can't find a group member!" << std::endl; continue; } @@ -743,7 +743,7 @@ void Mob::onRoamStart() { } void Mob::onCombatStart(EntityRef src) { - assert(src.type == EntityType::PLAYER); + assert(src.kind == EntityKind::PLAYER); target = src.sock; nextMovement = getTime(); nextAttack = 0; @@ -774,7 +774,7 @@ void Mob::onDeath(EntityRef src) { killedTime = getTime(); // XXX: maybe introduce a shard-global time for each step? // check for the edge case where hitting the mob did not aggro it - if (src.type == EntityType::PLAYER && src.isValid()) { + if (src.kind == EntityKind::PLAYER && src.isValid()) { Player* plr = PlayerManager::getPlayer(src.sock); Items::DropRoll rolled; diff --git a/src/MobAI.hpp b/src/MobAI.hpp index dbb267b..8b59b2f 100644 --- a/src/MobAI.hpp +++ b/src/MobAI.hpp @@ -60,7 +60,7 @@ struct Mob : public CombatNPC { // NOTE: there appear to be discrepancies in the dump hp = maxHealth; - kind = EntityType::MOB; + kind = EntityKind::MOB; } // constructor for /summon diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index 990d2d1..6b3b253 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -83,7 +83,7 @@ void NPCManager::sendToViewable(BaseNPC *npc, void *buf, uint32_t type, size_t s for (auto it = npc->viewableChunks.begin(); it != npc->viewableChunks.end(); it++) { Chunk* chunk = *it; for (const EntityRef& ref : chunk->entities) { - if (ref.type == EntityType::PLAYER) + if (ref.kind == EntityKind::PLAYER) ref.sock->sendPacket(buf, type, size); } } @@ -275,7 +275,7 @@ BaseNPC* NPCManager::getNearestNPC(std::set* chunks, int X, int Y, int Z for (auto c = chunks->begin(); c != chunks->end(); c++) { // haha get it Chunk* chunk = *c; for (auto ent = chunk->entities.begin(); ent != chunk->entities.end(); ent++) { - if (ent->type == EntityType::PLAYER) + if (ent->kind == EntityKind::PLAYER) continue; BaseNPC* npcTemp = (BaseNPC*)ent->getEntity(); @@ -351,7 +351,7 @@ void NPCManager::queueNPCRemoval(int32_t id) { static void step(CNServer *serv, time_t currTime) { for (auto& pair : NPCs) { - if (pair.second->kind != EntityType::COMBAT_NPC && pair.second->kind != EntityType::MOB) + if (pair.second->kind != EntityKind::COMBAT_NPC && pair.second->kind != EntityKind::MOB) continue; auto npc = (CombatNPC*)pair.second; diff --git a/src/Player.hpp b/src/Player.hpp index b0c970a..c10446a 100644 --- a/src/Player.hpp +++ b/src/Player.hpp @@ -85,7 +85,7 @@ struct Player : public Entity, public ICombatant { time_t lastShot = 0; std::vector buyback = {}; - Player() { kind = EntityType::PLAYER; } + Player() { kind = EntityKind::PLAYER; } virtual void enterIntoViewOf(CNSocket *sock) override; virtual void disappearFromViewOf(CNSocket *sock) override; diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index cffe36a..15ecf41 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -354,7 +354,7 @@ void PlayerManager::sendToViewable(CNSocket* sock, void* buf, uint32_t type, siz for (auto it = plr->viewableChunks.begin(); it != plr->viewableChunks.end(); it++) { Chunk* chunk = *it; for (const EntityRef& ref : chunk->entities) { - if (ref.type != EntityType::PLAYER || ref.sock == sock) + if (ref.kind != EntityKind::PLAYER || ref.sock == sock) continue; ref.sock->sendPacket(buf, type, size); diff --git a/src/PlayerManager.hpp b/src/PlayerManager.hpp index 0ab2049..883cf74 100644 --- a/src/PlayerManager.hpp +++ b/src/PlayerManager.hpp @@ -43,7 +43,7 @@ namespace PlayerManager { for (auto it = plr->viewableChunks.begin(); it != plr->viewableChunks.end(); it++) { Chunk* chunk = *it; for (const EntityRef& ref : chunk->entities) { - if (ref.type != EntityType::PLAYER || ref.sock == sock) + if (ref.kind != EntityKind::PLAYER || ref.sock == sock) continue; ref.sock->sendPacket(pkt, type); diff --git a/src/TableData.cpp b/src/TableData.cpp index c30e86b..3bbd09d 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -1176,7 +1176,7 @@ void TableData::flush() { continue; int x, y, z; - if (npc->kind == EntityType::MOB) { + if (npc->kind == EntityKind::MOB) { Mob *m = (Mob*)npc; x = m->spawnX; y = m->spawnY; @@ -1209,7 +1209,7 @@ void TableData::flush() { int x, y, z; std::vector followers; - if (npc->kind == EntityType::MOB) { + if (npc->kind == EntityKind::MOB) { Mob* m = (Mob*)npc; x = m->spawnX; y = m->spawnY; @@ -1221,7 +1221,7 @@ void TableData::flush() { // add follower data to vector; go until OOB or until follower ID is 0 for (int i = 0; i < 4 && m->groupMember[i] > 0; i++) { - if (NPCManager::NPCs.find(m->groupMember[i]) == NPCManager::NPCs.end() || NPCManager::NPCs[m->groupMember[i]]->kind != EntityType::MOB) { + if (NPCManager::NPCs.find(m->groupMember[i]) == NPCManager::NPCs.end() || NPCManager::NPCs[m->groupMember[i]]->kind != EntityKind::MOB) { std::cout << "[WARN] Follower with ID " << m->groupMember[i] << " not found; skipping\n"; continue; } diff --git a/src/Transport.cpp b/src/Transport.cpp index 9fe2ccc..0374e00 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -257,13 +257,13 @@ static void stepNPCPathing() { } // skip if not simulating mobs - if (npc->kind == EntityType::MOB && !MobAI::simulateMobs) { + if (npc->kind == EntityKind::MOB && !MobAI::simulateMobs) { it++; continue; } // do not roam if not roaming - if (npc->kind == EntityType::MOB && ((Mob*)npc)->state != AIState::ROAMING) { + if (npc->kind == EntityKind::MOB && ((Mob*)npc)->state != AIState::ROAMING) { it++; continue; } @@ -280,7 +280,7 @@ static void stepNPCPathing() { // TODO: move walking logic into Entity stack switch (npc->kind) { - case EntityType::BUS: + case EntityKind::BUS: INITSTRUCT(sP_FE2CL_TRANSPORTATION_MOVE, busMove); busMove.eTT = 3; @@ -293,7 +293,7 @@ static void stepNPCPathing() { NPCManager::sendToViewable(npc, &busMove, P_FE2CL_TRANSPORTATION_MOVE, sizeof(sP_FE2CL_TRANSPORTATION_MOVE)); break; - case EntityType::MOB: + case EntityKind::MOB: MobAI::incNextMovement((Mob*)npc); /* fallthrough */ default: @@ -385,7 +385,7 @@ NPCPath* Transport::findApplicablePath(int32_t id, int32_t type, int taskID) { void Transport::constructPathNPC(int32_t id, NPCPath* path) { BaseNPC* npc = NPCManager::NPCs[id]; - if (npc->kind == EntityType::MOB) + if (npc->kind == EntityKind::MOB) ((Mob*)(npc))->staticPath = true; npc->loopingPath = path->isLoop;