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/MobTypesManager.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 source/MobTypesManager.h (limited to 'source/MobTypesManager.h') diff --git a/source/MobTypesManager.h b/source/MobTypesManager.h new file mode 100644 index 000000000..0e628899e --- /dev/null +++ b/source/MobTypesManager.h @@ -0,0 +1,41 @@ + +#pragma once + +#include +#include "Mobs/Monster.h" // this is a side effect of declaring cMonster::eType inside cMonster MG TODO : make a namespace + +class cFastRandom; + +// this aggregate static functionnalities about mob types (some could call it helper) +// functionnalities are (in the first version) : +// - create a mob from its type (as enum) (in that way it is a compiler-proxy for mobs) +// - can transform MobTypes from enums to string and reciprocal +class cMobTypesManager +{ +public: + static const std::string& fromMobTypeToString(cMonster::eType a_MobType); + static cMonster::eType fromStringToMobType(const std::string&); + +public: + class NotAMonsterException : public std::exception {}; //MG TODO : check if this is this project way to do it + +protected : + typedef const std::map tMobTypes2Names; + static tMobTypes2Names& m_MobsTypes2Names(); + static tMobTypes2Names MobTypes2NamesInitializerBeforeCx11(); + + static cFastRandom& m_Random(); + +public : + /** create a new object of the specified mob. + Warning, new without delete here; + a_MobType is the type of the mob to be created + a_Size is the size (for mobs with size) + if a_Size is let to -1 for entities that need size, size will be random + assert or return null if mob type is not specified + assert if size < 1 or > 3 for entities that need size + */ + static cMonster* NewMonsterFromType(cMonster::eType a_MobType, int a_Size=-1); + +}; // tolua_export + -- cgit v1.2.3 From caa54af54640d1c94c57bc84b6b1e4eb2e7a6f3c Mon Sep 17 00:00:00 2001 From: mgueydan Date: Sun, 8 Sep 2013 01:21:43 +0200 Subject: Implementing the MobSpawner (not used yet) that contains spawning rules --- source/MobTypesManager.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source/MobTypesManager.h') diff --git a/source/MobTypesManager.h b/source/MobTypesManager.h index 0e628899e..a1b2dfddc 100644 --- a/source/MobTypesManager.h +++ b/source/MobTypesManager.h @@ -10,20 +10,23 @@ class cFastRandom; // functionnalities are (in the first version) : // - create a mob from its type (as enum) (in that way it is a compiler-proxy for mobs) // - can transform MobTypes from enums to string and reciprocal +// - return mob family from providen type class cMobTypesManager { public: static const std::string& fromMobTypeToString(cMonster::eType a_MobType); - static cMonster::eType fromStringToMobType(const std::string&); - -public: - class NotAMonsterException : public std::exception {}; //MG TODO : check if this is this project way to do it + static cMonster::eType fromStringToMobType(const std::string& a_MobTypeName); + static cMonster::eFamily getFamilyFromType(cMonster::eType a_MobType); protected : typedef const std::map tMobTypes2Names; static tMobTypes2Names& m_MobsTypes2Names(); static tMobTypes2Names MobTypes2NamesInitializerBeforeCx11(); + typedef const std::map tMobType2Family; //MG TODO : this is redundancy with cMonster::getFamily() methods. But almost all the management of MobType is redundancy in this project. Maybe is it optimization, or just historical TODO : understand and do something about it. + static tMobType2Family& m_MobsType2Family(); + static tMobType2Family MobType2FamilyInitializerBeforeCx11(); + static cFastRandom& m_Random(); public : -- cgit v1.2.3 From f12ac6b995f46acf76e61e7f83273ebfc18c090f Mon Sep 17 00:00:00 2001 From: mgueydan Date: Tue, 10 Sep 2013 15:09:45 +0200 Subject: Inside cMonster::getMobFamily() : replacing Polymorphism by Map, in order to remove redundancy --- source/MobTypesManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/MobTypesManager.h') diff --git a/source/MobTypesManager.h b/source/MobTypesManager.h index a1b2dfddc..941dac729 100644 --- a/source/MobTypesManager.h +++ b/source/MobTypesManager.h @@ -23,7 +23,7 @@ protected : static tMobTypes2Names& m_MobsTypes2Names(); static tMobTypes2Names MobTypes2NamesInitializerBeforeCx11(); - typedef const std::map tMobType2Family; //MG TODO : this is redundancy with cMonster::getFamily() methods. But almost all the management of MobType is redundancy in this project. Maybe is it optimization, or just historical TODO : understand and do something about it. + typedef const std::map tMobType2Family; static tMobType2Family& m_MobsType2Family(); static tMobType2Family MobType2FamilyInitializerBeforeCx11(); -- cgit v1.2.3