Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / server / src / ai_service / nf_helpers.h
blobdc9c7c34559b5d8f3fcb3e67d548da1067d8a8f3
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef RYAI_NF_HELPERS_H
18 #define RYAI_NF_HELPERS_H
20 extern AITYPES::CPropertySet readSet(std::string strings, std::string separator = "|");
22 extern AIVM::IScriptContext* spawnNewGroup(CStateInstance* entity, AIVM::CScriptStack& stack, CAIInstance* aiInstance, CAIVector const& spawnPosition, sint32 baseLevel, double dispersionRadius);
23 extern void getZoneWithFlags_helper(CStateInstance* entity, AIVM::CScriptStack& stack, CAIInstance* const aiInstance, CZoneScorer const& scorer);
25 //----------------------------------------------------------------------------
26 class CZoneScorerMandatoryAndOneOfPlusExcept
27 : public CZoneScorer
29 public:
30 CZoneScorerMandatoryAndOneOfPlusExcept(AITYPES::CPropertySet const& oneOfSet, AITYPES::CPropertySet const& mandatorySet, AITYPES::CPropertySet const& exceptSet, CNpcZone const* zone)
31 : CZoneScorer()
32 , _oneOfSet(oneOfSet)
33 , _mandatorySet(mandatorySet)
34 , _exceptSet(exceptSet)
35 , _zone(zone)
39 float getScore(CNpcZone const& zone) const
41 if (&zone==_zone)
42 return -1.f;
43 if (!zone.properties().containsPartOfNotStrict(_oneOfSet))
44 return -1.f;
45 if (!zone.properties().containsAllOf(_mandatorySet))
46 return -1.f;
47 if (zone.properties().containsPartOfStrict(_exceptSet))
48 return -1.f;
49 return zone.getFreeAreaScore();
51 private:
52 AITYPES::CPropertySet _oneOfSet;
53 AITYPES::CPropertySet _mandatorySet;
54 AITYPES::CPropertySet _exceptSet;
55 CNpcZone const* _zone;
58 class CZoneScorerMandatoryAndOneOfAndDist
59 : public CZoneScorer
61 public:
62 CZoneScorerMandatoryAndOneOfAndDist(AITYPES::CPropertySet const& oneOfSet, AITYPES::CPropertySet const& mandatorySet, AITYPES::CPropertySet const& exceptSet, CAIVector const& pos)
63 : CZoneScorer()
64 , _oneOfSet(oneOfSet)
65 , _mandatorySet(mandatorySet)
66 , _exceptSet(exceptSet)
67 , _Pos(pos)
71 float getScore(CNpcZone const& zone) const
73 if (!zone.properties().containsPartOfNotStrict(_oneOfSet))
74 return -1.f;
75 if (!zone.properties().containsAllOf(_mandatorySet))
76 return -1.f;
77 if (zone.properties().containsPartOfStrict(_exceptSet))
78 return -1.f;
79 return 1.f/getDist(zone);
81 virtual float getParam(CNpcZone const& zone) const { return getDist(zone); };
82 private:
83 float getDist(CNpcZone const& zone) const
85 return (float)zone.midPos().quickDistTo(_Pos)+0.0001f;
87 AITYPES::CPropertySet _oneOfSet;
88 AITYPES::CPropertySet _mandatorySet;
89 AITYPES::CPropertySet _exceptSet;
90 CAIVector _Pos;
93 class CZoneScorerMandatoryAndOneOfAndDistAndSpace
94 : public CZoneScorerMandatoryAndOneOfAndDist
96 public:
97 CZoneScorerMandatoryAndOneOfAndDistAndSpace(AITYPES::CPropertySet const& oneOfSet, AITYPES::CPropertySet const& mandatorySet, AITYPES::CPropertySet const& exceptSet, CAIVector const& pos)
98 : CZoneScorerMandatoryAndOneOfAndDist(oneOfSet, mandatorySet, exceptSet, pos)
102 float getScore(CNpcZone const& zone) const
104 return (float)(zone.getFreeAreaScore()*CZoneScorerMandatoryAndOneOfAndDist::getScore(zone));
108 //----------------------------------------------------------------------------
109 // Ugly but no time, to refactor ..
111 class CDoOnFamily
113 public:
114 CDoOnFamily() { }
115 virtual ~CDoOnFamily() { }
116 virtual void doOnFamily(CFamilyBehavior *fb) const = 0;
117 virtual void doOnCellZone(CCellZone *cz) const = 0;
120 extern bool doOnFamily(std::vector<std::string> const& args, CDoOnFamily* fam);
122 //----------------------------------------------------------------------------
123 class CDoOnFamilyCopyDynEnergy
124 :public CDoOnFamily
126 public:
127 CDoOnFamilyCopyDynEnergy(size_t indexSrc, size_t indexDest)
129 _IndexSrc = indexSrc;
130 _IndexDest = indexDest;
131 if (_IndexSrc>3 || _IndexDest>3)
132 nlwarning("CDoOnFamilyCopyDynEnergy: index out of bounds (0-3)");
133 nlassert(_IndexSrc<4 && _IndexDest<4);
136 void doOnFamily(CFamilyBehavior* fb) const
138 float value = fb->getModifier((uint32)_IndexSrc);
139 fb->setModifier(value, (uint32)_IndexDest);
141 void doOnCellZone(CCellZone* cz) const { }
143 private:
144 size_t _IndexSrc;
145 size_t _IndexDest;
148 //----------------------------------------------------------------------------
149 class CDoOnFamilySetDynEnergy
150 :public CDoOnFamily
152 public:
153 CDoOnFamilySetDynEnergy (size_t index, float value)
155 _index=index;
156 _value=value;
159 void doOnFamily(CFamilyBehavior *fb) const
161 if (_value==-1) // not for affectation.
162 return;
164 if (_index==std::numeric_limits<size_t>::max()) // all indexs ?
166 for (uint32 nrjIndex=0;nrjIndex<4;nrjIndex++)
167 fb->setModifier (_value, nrjIndex);
168 return;
170 fb->setModifier (_value, (uint32)_index);
172 void doOnCellZone(CCellZone *cz) const { }
174 private:
175 size_t _index;
176 float _value;
179 #endif