summaryrefslogtreecommitdiffstats
path: root/source/MobCensus.h
blob: 8aa8f3a6cdb1b1f5f18c96c1c34e22dbf1314669 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

#pragma once

#include "MobProximityCounter.h"
#include "MobFamilyCollecter.h"

class cChunk;
class cMonster;

// 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
//
// as side effect : it also collect the chunks that are elligible for spawning
// as side effect 2 : it also know the caps for mobs number and can compare census to this numbers
class cMobCensus
{
public :
	cMobCensus();

protected :
	cMobProximityCounter m_ProximityCounter;
	cMobFamilyCollecter m_MobFamilyCollecter;

	typedef const std::map<cMonster::eFamily,int> tCapMultipliersMap;
	static tCapMultipliersMap& m_CapMultipliers();

	std::set<cChunk*> m_EligibleForSpawnChunks;

	// count the chunks that are elligible to spawn (for now, the loaded valide not null chunks)
	int getChunkNb();

public:
	typedef const std::map<cMonster::eFamily,int> tMobSpawnRate;
	static tMobSpawnRate& m_SpawnRate();

	// return the nested proximity counter
	cMobProximityCounter& getProximityCounter();

public :
	// collect an elligible Chunk for Mob Spawning
	// MG TODO : code the correct rule (not loaded chunk but short distant from players)
	void CollectSpawnableChunk(cChunk& a_Chunk);
	
	// collect a mob - it's distance to player, it's family ...
	void CollectMob(cMonster& a_Monster, cChunk& a_Chunk, double a_Distance);

	// return true if the family is caped (i.e. there is more mobs of this family than max)
	bool isCaped(cMonster::eFamily a_MobFamily);

	// log the results of census
	void logd();

protected : 
	static tCapMultipliersMap CapMultiplierInitializerBeforeCx11();
	static tCapMultipliersMap MobSpawnRateInitializerBeforeCx11();
};