1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
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.
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
30 CZoneScorerMandatoryAndOneOfPlusExcept(AITYPES::CPropertySet
const& oneOfSet
, AITYPES::CPropertySet
const& mandatorySet
, AITYPES::CPropertySet
const& exceptSet
, CNpcZone
const* zone
)
33 , _mandatorySet(mandatorySet
)
34 , _exceptSet(exceptSet
)
39 float getScore(CNpcZone
const& zone
) const
43 if (!zone
.properties().containsPartOfNotStrict(_oneOfSet
))
45 if (!zone
.properties().containsAllOf(_mandatorySet
))
47 if (zone
.properties().containsPartOfStrict(_exceptSet
))
49 return zone
.getFreeAreaScore();
52 AITYPES::CPropertySet _oneOfSet
;
53 AITYPES::CPropertySet _mandatorySet
;
54 AITYPES::CPropertySet _exceptSet
;
55 CNpcZone
const* _zone
;
58 class CZoneScorerMandatoryAndOneOfAndDist
62 CZoneScorerMandatoryAndOneOfAndDist(AITYPES::CPropertySet
const& oneOfSet
, AITYPES::CPropertySet
const& mandatorySet
, AITYPES::CPropertySet
const& exceptSet
, CAIVector
const& pos
)
65 , _mandatorySet(mandatorySet
)
66 , _exceptSet(exceptSet
)
71 float getScore(CNpcZone
const& zone
) const
73 if (!zone
.properties().containsPartOfNotStrict(_oneOfSet
))
75 if (!zone
.properties().containsAllOf(_mandatorySet
))
77 if (zone
.properties().containsPartOfStrict(_exceptSet
))
79 return 1.f
/getDist(zone
);
81 virtual float getParam(CNpcZone
const& zone
) const { return getDist(zone
); };
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
;
93 class CZoneScorerMandatoryAndOneOfAndDistAndSpace
94 : public CZoneScorerMandatoryAndOneOfAndDist
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 ..
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
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 { }
148 //----------------------------------------------------------------------------
149 class CDoOnFamilySetDynEnergy
153 CDoOnFamilySetDynEnergy (size_t index
, float value
)
159 void doOnFamily(CFamilyBehavior
*fb
) const
161 if (_value
==-1) // not for affectation.
164 if (_index
==std::numeric_limits
<size_t>::max()) // all indexs ?
166 for (uint32 nrjIndex
=0;nrjIndex
<4;nrjIndex
++)
167 fb
->setModifier (_value
, nrjIndex
);
170 fb
->setModifier (_value
, (uint32
)_index
);
172 void doOnCellZone(CCellZone
*cz
) const { }