itemgroup.h and ItemGroupList typedef

This commit is contained in:
Perttu Ahola 2012-03-04 14:22:35 +02:00
parent 0b21618a05
commit 07ed57476f
7 changed files with 17 additions and 28 deletions

@ -724,7 +724,7 @@ void Oerkki1SAO::punch(ServerActiveObject *puncher, float time_from_last_punch)
m_speed_f += dir*12*BS; m_speed_f += dir*12*BS;
// "Material" groups of the object // "Material" groups of the object
std::map<std::string, int> groups; ItemGroupList groups;
groups["snappy"] = 1; groups["snappy"] = 1;
groups["choppy"] = 1; groups["choppy"] = 1;
groups["fleshy"] = 3; groups["fleshy"] = 3;
@ -1419,7 +1419,7 @@ void MobV2SAO::punch(ServerActiveObject *puncher, float time_from_last_punch)
// "Material" groups of the object // "Material" groups of the object
std::map<std::string, int> groups; ItemGroupList groups;
groups["snappy"] = 1; groups["snappy"] = 1;
groups["choppy"] = 1; groups["choppy"] = 1;
groups["fleshy"] = 3; groups["fleshy"] = 3;

@ -25,23 +25,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <set> #include <set>
#include <map> #include "itemgroup.h"
class IGameDef; class IGameDef;
struct ToolCapabilities; struct ToolCapabilities;
/*
Some helpers
*/
static inline int itemgroup_get(const std::map<std::string, int> &groups,
const std::string &name)
{
std::map<std::string, int>::const_iterator i = groups.find(name);
if(i == groups.end())
return 0;
return i->second;
}
/* /*
Base item definition Base item definition
*/ */
@ -78,7 +65,7 @@ struct ItemDefinition
bool liquids_pointable; bool liquids_pointable;
// May be NULL. If non-NULL, deleted by destructor // May be NULL. If non-NULL, deleted by destructor
ToolCapabilities *tool_capabilities; ToolCapabilities *tool_capabilities;
std::map<std::string, int> groups; ItemGroupList groups;
/* /*
Cached stuff Cached stuff

@ -154,7 +154,7 @@ void ContentFeatures::serialize(std::ostream &os)
writeU8(os, 2); // version writeU8(os, 2); // version
os<<serializeString(name); os<<serializeString(name);
writeU16(os, groups.size()); writeU16(os, groups.size());
for(std::map<std::string, int>::const_iterator for(ItemGroupList::const_iterator
i = groups.begin(); i != groups.end(); i++){ i = groups.begin(); i != groups.end(); i++){
os<<serializeString(i->first); os<<serializeString(i->first);
writeS16(os, i->second); writeS16(os, i->second);

@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#ifndef SERVER #ifndef SERVER
#include "tile.h" #include "tile.h"
#endif #endif
#include "itemgroup.h"
class IItemDefManager; class IItemDefManager;
class ITextureSource; class ITextureSource;
class IGameDef; class IGameDef;
@ -148,7 +149,7 @@ struct ContentFeatures
*/ */
std::string name; // "" = undefined node std::string name; // "" = undefined node
std::map<std::string, int> groups; // Same as in itemdef ItemGroupList groups; // Same as in itemdef
// Visual definition // Visual definition
enum NodeDrawType drawtype; enum NodeDrawType drawtype;

@ -182,7 +182,7 @@ void ServerRemotePlayer::punch(ServerActiveObject *puncher,
} }
// "Material" groups of the player // "Material" groups of the player
std::map<std::string, int> groups; ItemGroupList groups;
groups["choppy"] = 2; groups["choppy"] = 2;
groups["fleshy"] = 3; groups["fleshy"] = 3;

@ -68,7 +68,7 @@ void ToolCapabilities::deSerialize(std::istream &is)
} }
} }
DigParams getDigParams(const std::map<std::string, int> &groups, DigParams getDigParams(const ItemGroupList &groups,
const ToolCapabilities *tp, float time_from_last_punch) const ToolCapabilities *tp, float time_from_last_punch)
{ {
//infostream<<"getDigParams"<<std::endl; //infostream<<"getDigParams"<<std::endl;
@ -123,13 +123,13 @@ DigParams getDigParams(const std::map<std::string, int> &groups,
return DigParams(result_diggable, result_time, wear_i); return DigParams(result_diggable, result_time, wear_i);
} }
DigParams getDigParams(const std::map<std::string, int> &groups, DigParams getDigParams(const ItemGroupList &groups,
const ToolCapabilities *tp) const ToolCapabilities *tp)
{ {
return getDigParams(groups, tp, 1000000); return getDigParams(groups, tp, 1000000);
} }
HitParams getHitParams(const std::map<std::string, int> &groups, HitParams getHitParams(const ItemGroupList &groups,
const ToolCapabilities *tp, float time_from_last_punch) const ToolCapabilities *tp, float time_from_last_punch)
{ {
DigParams digprop = getDigParams(groups, tp, DigParams digprop = getDigParams(groups, tp,
@ -145,7 +145,7 @@ HitParams getHitParams(const std::map<std::string, int> &groups,
return HitParams(hp, wear); return HitParams(hp, wear);
} }
HitParams getHitParams(const std::map<std::string, int> &groups, HitParams getHitParams(const ItemGroupList &groups,
const ToolCapabilities *tp) const ToolCapabilities *tp)
{ {
return getHitParams(groups, tp, 1000000); return getHitParams(groups, tp, 1000000);

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <map> #include <map>
#include "itemgroup.h"
struct ToolGroupCap struct ToolGroupCap
{ {
@ -84,10 +85,10 @@ struct DigParams
{} {}
}; };
DigParams getDigParams(const std::map<std::string, int> &groups, DigParams getDigParams(const ItemGroupList &groups,
const ToolCapabilities *tp, float time_from_last_punch); const ToolCapabilities *tp, float time_from_last_punch);
DigParams getDigParams(const std::map<std::string, int> &groups, DigParams getDigParams(const ItemGroupList &groups,
const ToolCapabilities *tp); const ToolCapabilities *tp);
struct HitParams struct HitParams
@ -101,10 +102,10 @@ struct HitParams
{} {}
}; };
HitParams getHitParams(const std::map<std::string, int> &groups, HitParams getHitParams(const ItemGroupList &groups,
const ToolCapabilities *tp, float time_from_last_punch); const ToolCapabilities *tp, float time_from_last_punch);
HitParams getHitParams(const std::map<std::string, int> &groups, HitParams getHitParams(const ItemGroupList &groups,
const ToolCapabilities *tp); const ToolCapabilities *tp);
#endif #endif