From d2eb58f27780a3c65fedd0d21d152ee8866ebb86 Mon Sep 17 00:00:00 2001 From: mgueydan Date: Sat, 7 Sep 2013 22:19:56 +0200 Subject: Adding mob census (sorry this is a big commit as work was done before git integration i couldn't split it more) --- source/MobProximityCounter.h | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 source/MobProximityCounter.h (limited to 'source/MobProximityCounter.h') diff --git a/source/MobProximityCounter.h b/source/MobProximityCounter.h new file mode 100644 index 000000000..d033f1b7f --- /dev/null +++ b/source/MobProximityCounter.h @@ -0,0 +1,65 @@ + +#pragma once + +#include + +class cChunk; +class cEntity; + + +// This class is used to collect, for each Mob, what is the distance of the closest player +// it was first being designed in order to make mobs spawn / despawn / act +// as the behaviour and even life of mobs depends on the distance to closest player +class cMobProximityCounter +{ +protected : + // structs used for later maps (see m_MonsterToDistance and m_DistanceToMonster) + struct sDistanceAndChunk + { + sDistanceAndChunk(double a_Distance, cChunk& a_Chunk) : m_Distance(a_Distance), m_Chunk(a_Chunk) {} + double m_Distance; + cChunk& m_Chunk; + }; + struct sMonsterAndChunk + { + sMonsterAndChunk(cEntity& a_Monster, cChunk& a_Chunk) : m_Monster(a_Monster), m_Chunk(a_Chunk) {} + cEntity& m_Monster; + cChunk& m_Chunk; + }; + +public : + typedef std::map tMonsterToDistance; + typedef std::multimap tDistanceToMonster; + +protected : + // this map is filled during collection phase, it will be later transformed into DistanceToMonster + tMonsterToDistance m_MonsterToDistance; + + // this map is generated after collection phase, in order to access monster by distance to player + tDistanceToMonster m_DistanceToMonster; + + // this are the collected chuncks. Used to determinate the number of elligible chunck for spawning. + std::set m_EligibleForSpawnChunks; + +protected : + // transform monsterToDistance map (that was usefull for collecting) into distanceToMonster + // that will be usefull for picking up. + void convertMaps(); + +public : + // count a mob on a specified chunck with specified distance to an unkown player + // if the distance is shortest than the one collected, this become the new closest + // distance and the chunck become the "hosting" chunk (that is the one that will perform the action) + void CollectMob(cEntity& a_Monster, cChunk& a_Chunk, double a_Distance); + + // return the mobs that are within the range of distance of the closest player they are + // that means that if a mob is 30 m from a player and 150 m from another one. It will be + // in the range [0..50] but not in [100..200] + struct sIterablePair{ + tDistanceToMonster::const_iterator m_Begin; + tDistanceToMonster::const_iterator m_End; + int m_Count; + }; + sIterablePair getMobWithinThosesDistances(double a_DistanceMin, double a_DistanceMax); + +}; -- cgit v1.2.3 From b4bb2553445d44dc8ca03bb33d801cf620f71898 Mon Sep 17 00:00:00 2001 From: mgueydan Date: Sun, 8 Sep 2013 12:25:07 +0200 Subject: Replacing chunCk by chunk --- source/MobProximityCounter.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/MobProximityCounter.h') diff --git a/source/MobProximityCounter.h b/source/MobProximityCounter.h index d033f1b7f..8a67139aa 100644 --- a/source/MobProximityCounter.h +++ b/source/MobProximityCounter.h @@ -38,7 +38,7 @@ protected : // this map is generated after collection phase, in order to access monster by distance to player tDistanceToMonster m_DistanceToMonster; - // this are the collected chuncks. Used to determinate the number of elligible chunck for spawning. + // this are the collected chunks. Used to determinate the number of elligible chunk for spawning. std::set m_EligibleForSpawnChunks; protected : @@ -47,9 +47,9 @@ protected : void convertMaps(); public : - // count a mob on a specified chunck with specified distance to an unkown player + // count a mob on a specified chunk with specified distance to an unkown player // if the distance is shortest than the one collected, this become the new closest - // distance and the chunck become the "hosting" chunk (that is the one that will perform the action) + // distance and the chunk become the "hosting" chunk (that is the one that will perform the action) void CollectMob(cEntity& a_Monster, cChunk& a_Chunk, double a_Distance); // return the mobs that are within the range of distance of the closest player they are -- cgit v1.2.3