1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "nel/misc/variable.h"
22 #include "nel/misc/path.h"
23 #include "string_manager.h"
24 #include "input_output_service.h"
25 #include "game_share/skills.h"
26 #include "game_share/body.h"
27 #include "game_share/scores.h"
28 #include "game_share/characteristics.h"
29 #include "game_share/damage_types.h"
30 #include "game_share/power_types.h"
31 #include "game_share/ecosystem.h"
32 #include "game_share/people.h"
33 #include "game_share/roles.h"
34 #include "game_share/fame.h"
35 #include "game_share/ryzom_mirror_properties.h"
38 using namespace STRING_MANAGER
;
39 using namespace NLMISC
;
40 using namespace NLNET
;
44 extern CVariable
<bool> VerboseStringManager
;
45 #define LOG if (!VerboseStringManager) {} else nlinfo
48 const char *OperatorNames
[] =
60 // --------------- ParameterTraits class -------------------
62 void CStringManager::CParameterTraits::fillBitMemStream( const CCharacterInfos
*charInfo
,TLanguages language
, const TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
64 const CStringManager::CEntityWords
&ew
= SM
->getEntityWords(language
, ParamId
.Type
);
65 std::string rowName
= NLMISC::strlwr(getParameterId());
67 stringId
= ew
.getStringId(rowName
, rep
.Format
);
71 bool CStringManager::CParameterTraits::eval(CStringManager::TLanguages lang
,const CCharacterInfos
*charInfo
, const TCondition
&cond
) const
73 // Default eval only check in words column as property
74 const CStringManager::CEntityWords
&ew
= SM
->getEntityWords(lang
, ParamId
.Type
);
75 uint32 colIndex
= ew
.getColumnId(cond
.Property
);
76 if (colIndex
== 0xffffffff)
78 nlwarning("The column %s is unknown in words file for %s", cond
.Property
.c_str(), getParameterId().c_str());
82 // ok, this column exist, retrieve the row
83 uint32 rowIndex
= ew
.getRowId(NLMISC::strlwr(getParameterId()));
84 if (rowIndex
== 0xffffffff)
86 nlwarning("The entry in table for %s is unknown in words.", getParameterId().c_str());
90 uint32 stringId
= ew
.getStringId(rowIndex
, colIndex
);
91 std::string str
= NLMISC::toLowerAscii(SM
->getString(stringId
).toString());
93 LOG("SM : (paramTraits) eval condition for property %s [%s] %s [%s]", cond
.Property
.c_str(), str
.c_str(), OperatorNames
[cond
.Operator
], cond
.ReferenceStr
.c_str());
98 return str
== cond
.ReferenceStr
;
100 return str
!= cond
.ReferenceStr
;
102 return str
> cond
.ReferenceStr
;
104 return str
>= cond
.ReferenceStr
;
106 return str
< cond
.ReferenceStr
;
108 return str
<= cond
.ReferenceStr
;
110 nlwarning("Operator %s is not applicable to property %s", OperatorNames
[cond
.Operator
], cond
.Property
.c_str());
116 class CParameterTraitsEntity
: public CStringManager::CParameterTraits
119 CStringManager::CParameterTraits
*clone()
121 return new CParameterTraitsEntity(STRING_MANAGER::entity
, "entity");
124 CParameterTraitsEntity(STRING_MANAGER::TParamType type
, const std::string
&typeName
)
125 : CParameterTraits(type
, typeName
)
127 bool extractFromMessage(NLNET::CMessage
&message
, bool debug
)
130 if (param
.serialParam(debug
, message
, ParamId
.Type
))
132 EId
= param
.getEId();
133 _AIAlias
= param
.getAIAlias();
138 EId
= CEntityId::Unknown
;
143 const std::string
&getParameterId() const
145 static std::string empty
;
146 // special case for fauna entity
147 if (EId
.getType() == RYZOMID::creature
|| EId
.getType() == RYZOMID::npc
)
149 const NLMISC::CSheetId
&sheetId
= SM
->getSheetId(EId
);
150 if (sheetId
== NLMISC::CSheetId::Unknown
)
152 nlwarning("The sheet id for creature entity %s is unknown !", EId
.toString().c_str());
156 const CStringManager::TSheetInfo
&si
= SM
->getSheetInfo(sheetId
);
160 // TODO : We need to found the name of the entity.
163 // just a wrapper to base class
164 bool eval(CStringManager::TLanguages lang
,const CCharacterInfos
*charInfo
, const CStringManager::TCondition
&cond
) const
166 // Test unknown entity
167 if ((cond
.ReferenceInt
== 0) && (cond
.Property
.empty()))
169 if (cond
.Operator
== CStringManager::equal
)
170 return EId
.isUnknownId();
171 else if (cond
.Operator
== CStringManager::notEqual
)
172 return !EId
.isUnknownId();
176 const NLMISC::CSheetId
&sheetId
= SM
->getSheetId(EId
);
177 if (sheetId
== NLMISC::CSheetId::Unknown
)
179 nlwarning("The sheet id for entity entity %s is unknown !", EId
.toString().c_str());
182 const CStringManager::TSheetInfo
&si
= SM
->getSheetInfo(sheetId
);
185 if (cond
.Property
== "race")
189 else if (cond
.Property
== "gender")
191 CCharacterInfos
*playerInfo
= IOS
->getCharInfos(EId
);
194 op1
= GSGENDER::toString(playerInfo
->getGender());
199 return CParameterTraits::eval(lang
, charInfo
, cond
);
203 LOG("SM : (entity) eval condition for property %s [%s] %s [%s]", cond
.Property
.c_str(), op1
.c_str(), OperatorNames
[cond
.Operator
], cond
.ReferenceStr
.c_str());
205 switch(cond
.Operator
)
207 case CStringManager::equal
:
208 return op1
== cond
.ReferenceStr
;
209 case CStringManager::notEqual
:
210 return op1
!= cond
.ReferenceStr
;
211 case CStringManager::less
:
212 return op1
< cond
.ReferenceStr
;
213 case CStringManager::lessEqual
:
214 return op1
<= cond
.ReferenceStr
;
215 case CStringManager::greater
:
216 return op1
> cond
.ReferenceStr
;
217 case CStringManager::greaterEqual
:
218 return op1
>= cond
.ReferenceStr
;
220 nlwarning("Operator %s not applicable to creature property %s", OperatorNames
[cond
.Operator
], cond
.Property
.c_str());
223 nlerror("This point of code can never be reach !");
224 return CParameterTraits::eval(lang
, charInfo
, cond
);
227 void fillBitMemStream( const CCharacterInfos
*charInfo
,CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
229 if ( EId
== CEntityId::Unknown
&& _AIAlias
!= 0)
231 CAIAliasManager
& aiAliasMgr
= IOS
->getAIAliasManager();
232 if (aiAliasMgr
.is(_AIAlias
))
235 static const string
NAME("name");
236 CSString format
= rep
.Format
;
237 if (format
.left(4) != NAME
)
239 // can't replace this parameter, write a del char
240 const static string
s("\010");
241 uint32 index
= SM
->storeString(s
);
248 index
= aiAliasMgr
.getShortNameIndex(_AIAlias
);
254 index
= aiAliasMgr
.getTitleIndex(_AIAlias
, language
);
261 // No translated title or translated phrase found send ''
262 // ucstring temp(EId.toString());
263 const ucstring
NoName("''");
264 uint32 index
= SM
->storeString(NoName
);
270 if (EId
.getType() == RYZOMID::player
|| EId
.getType() == RYZOMID::npc
)
272 CCharacterInfos
*playerInfo
= IOS
->getCharInfos(EId
);
275 static const string
NAME("name");
276 CSString format
= rep
.Format
;
277 if (format
.left(4) != NAME
)
279 // can't replace this parameter, write a del char
280 const static string
s("\010");
281 uint32 index
= SM
->storeString(s
);
287 if (!playerInfo
->ShortName
.empty())
289 uint32 index
= playerInfo
->ShortNameIndex
;
293 if (!playerInfo
->Title
.empty())
295 uint32 index
= SM
->translateTitle(playerInfo
->Title
, language
);
296 // we must match this index against the function table
304 // special case fauna entity or unnamed npc (i.e. npc not registered with a character name, like fauna in npc state machine)
305 if (EId
.getType() == RYZOMID::creature
|| EId
.getType() == RYZOMID::npc
)
308 STRING_MANAGER::TParamType realType
= ParamId
.Type
;
309 ParamId
.Type
= STRING_MANAGER::creature
;
310 CParameterTraits::fillBitMemStream(charInfo
, language
, rep
, bms
);
312 // restore normal type
313 ParamId
.Type
= realType
;
317 // no info on the name, just send the EID as string.
318 // ucstring temp(EId.toString());
319 const ucstring
NoName("''");
320 uint32 index
= SM
->storeString(NoName
);
324 void setDefaultValue()
326 EId
= NLMISC::CEntityId::Unknown
;
331 class CParameterTraitsEnum
: public CStringManager::CParameterTraits
334 CParameterTraitsEnum(STRING_MANAGER::TParamType type
, const std::string
&typeName
)
335 : CParameterTraits(type
, typeName
)
337 bool extractFromMessage(NLNET::CMessage
&message
, bool debug
)
340 if (param
.serialParam(debug
, message
, ParamId
.Type
))
353 class CParameterTraitsIdentifier
: public CStringManager::CParameterTraits
356 CParameterTraitsIdentifier(STRING_MANAGER::TParamType type
, const std::string
&typeName
)
357 : CParameterTraits(type
, typeName
)
359 bool extractFromMessage(NLNET::CMessage
&message
, bool debug
)
362 if (param
.serialParam(debug
, message
, ParamId
.Type
))
364 Identifier
= param
.Identifier
;
374 const std::string
&getParameterId() const
379 void setDefaultValue()
385 class CParameterTraitsSheet
: public CStringManager::CParameterTraits
388 CParameterTraitsSheet(STRING_MANAGER::TParamType type
, const std::string
&typeName
)
389 : CParameterTraits(type
, typeName
)
391 bool extractFromMessage(NLNET::CMessage
&message
, bool debug
)
394 if (param
.serialParam(debug
, message
, ParamId
.Type
))
396 SheetId
= param
.SheetId
;
404 // message.serial(SheetId);
407 const std::string
&getParameterId() const
409 // const CStringManager::TSheetInfo &si = SM->getSheetInfo(SheetId);
411 static string sheetName
;
412 sheetName
= SheetId
.toString();
413 sheetName
= CFile::getFilenameWithoutExtension(sheetName
);
418 void setDefaultValue()
420 SheetId
= NLMISC::CSheetId::Unknown
;
426 class CParameterTraitsItem
: public CParameterTraitsSheet
429 CParameterTraitsItem() : CParameterTraitsSheet(STRING_MANAGER::item
, "item")
432 CStringManager::CParameterTraits
*clone()
434 return new CParameterTraitsItem();
437 /// fill overloaded to deals with ring user defined item with custom names
438 void fillBitMemStream( const CCharacterInfos
*charInfo
, CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
440 // check if SheetId if in the table or user item
441 const CStringManager::TRingUserItemInfos
&itemInfos
= SM
->getUserItems();
442 CStringManager::TRingUserItemInfos::const_iterator
it(itemInfos
.find(SheetId
));
443 if (it
!= itemInfos
.end() && !it
->second
.empty())
445 // this item has some user name, check the aiInstance
446 const vector
<CStringManager::TRingUserItemInfo
> &userItemInfos
= it
->second
;
447 for (uint i
=0; i
<userItemInfos
.size(); ++i
)
449 if (userItemInfos
[i
].AIInstance
== charInfo
->AIInstance
)
451 // ok, this item is renamed !
453 // use the user name for a list a predefined column :
454 // name, named, nameda, p, pd
455 if ( rep
.Format
== "name"
456 || rep
.Format
== "named"
457 || rep
.Format
== "nameda"
459 || rep
.Format
== "pd")
461 nlWrite(bms
, serial
, userItemInfos
[i
].ItemNameId
);
465 // not a valid replacement, return a 'backspace' character
466 static uint32 noString
= SM
->storeString(ucstring()+ucchar(8));
467 bms
.serial(noString
);
470 /// return here ---------------------
476 // normal item name, use the base function instead
477 CParameterTraitsSheet::fillBitMemStream( charInfo
, language
, rep
, bms
);
482 class CParameterTraitsSPhrase
: public CParameterTraitsSheet
485 CParameterTraitsSPhrase() : CParameterTraitsSheet(STRING_MANAGER::sphrase
, "sphrase")
488 CStringManager::CParameterTraits
*clone()
490 return new CParameterTraitsSPhrase();
494 class CParameterTraitsBotName
: public CParameterTraitsIdentifier
497 CParameterTraitsBotName() : CParameterTraitsIdentifier(STRING_MANAGER::bot_name
, "bot_name")
500 CStringManager::CParameterTraits
*clone()
502 return new CParameterTraitsBotName();
505 void fillBitMemStream( const CCharacterInfos
*charInfo
, CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
508 uint32 nameId1
= SM
->storeString(Identifier
);
509 uint32 nameId2
= SM
->translateShortName(nameId1
);
510 const ucstring
&name
= SM
->getString(nameId2
);
511 if (!name
.empty() && name
[0] == '$')
513 // this name is a generic name, translate the title
514 ucstring title
= name
.substr(1, name
.size()-2);
515 nameId2
= SM
->translateTitle(title
.toString(), language
);
517 // serial the string ID
524 class CParameterTraitsPlace
: public CParameterTraitsIdentifier
527 CParameterTraitsPlace() : CParameterTraitsIdentifier(STRING_MANAGER::place
, "place")
530 CStringManager::CParameterTraits
*clone()
532 return new CParameterTraitsPlace();
537 class CParameterTraitsCreature
: public CParameterTraitsEntity
540 CStringManager::CParameterTraits
*clone()
542 return new CParameterTraitsCreature();
545 CParameterTraitsCreature() : CParameterTraitsEntity(STRING_MANAGER::creature
, "creature")
547 const std::string
&getParameterId() const
549 const NLMISC::CSheetId
&sheetId
= SM
->getSheetId(EId
);
550 if (sheetId
== NLMISC::CSheetId::Unknown
)
552 nlwarning("The sheet id for creature entity %s is unknown !", EId
.toString().c_str());
553 static std::string empty
;
558 const CStringManager::TSheetInfo
&si
= SM
->getSheetInfo(sheetId
);
564 bool eval(CStringManager::TLanguages lang
, const CCharacterInfos
*charInfo
, const CStringManager::TCondition
&cond
) const
566 // Test unknown entity
567 if ((cond
.ReferenceInt
== 0) && (cond
.Property
.empty()))
569 if (cond
.Operator
== CStringManager::equal
)
570 return EId
.isUnknownId();
571 else if (cond
.Operator
== CStringManager::notEqual
)
572 return !EId
.isUnknownId();
575 // creature can test model name, model gender
577 // 1st, I need to retreive the sheetId from the mirror
578 const NLMISC::CSheetId
&sheetId
= SM
->getSheetId(EId
);
579 if (sheetId
== NLMISC::CSheetId::Unknown
)
581 nlwarning("The sheet id for creature entity %s is unknown !", EId
.toString().c_str());
585 const CStringManager::TSheetInfo
&si
= SM
->getSheetInfo(sheetId
);
587 if (cond
.Property
== "name")
589 op1
= NLMISC::toLowerAscii(si
.SheetName
);
591 else if (cond
.Property
== "gender")
593 op1
= NLMISC::toLowerAscii(GSGENDER::toString(si
.Gender
));
597 return CParameterTraitsEntity::eval(lang
,charInfo
, cond
);
600 LOG("SM : (creature) eval condition for property %s [%s] %s [%s]", cond
.Property
.c_str(), op1
.c_str(), OperatorNames
[cond
.Operator
], cond
.ReferenceStr
.c_str());
602 switch(cond
.Operator
)
604 case CStringManager::equal
:
605 return op1
== cond
.ReferenceStr
;
606 case CStringManager::notEqual
:
607 return op1
!= cond
.ReferenceStr
;
608 case CStringManager::less
:
609 return op1
< cond
.ReferenceStr
;
610 case CStringManager::lessEqual
:
611 return op1
<= cond
.ReferenceStr
;
612 case CStringManager::greater
:
613 return op1
> cond
.ReferenceStr
;
614 case CStringManager::greaterEqual
:
615 return op1
>= cond
.ReferenceStr
;
617 nlwarning("Operator %s not applicable to creature property %s", OperatorNames
[cond
.Operator
], cond
.Property
.c_str());
620 nlerror("This point of code can never be reach !");
622 /* void fillBitMemStream(CStringManager::TLanguages language, const CStringManager::TReplacement &rep, NLMISC::CBitMemStream &bms)
624 // need to evaluate the name of the creature : name from the sheet id
626 NLMISC::CSheetId sid = SM->getSheetId(EId);
627 if (sid != NLMISC::CSheetId::Unknown)
629 const CStringManager::TSheetInfo &si = SM->getSheetInfo(sid);
631 temp = si.DisplayName;
634 uint32 index = SM->storeString(temp);
639 // hum, no name available
640 CParameterTraitsEntity::fillBitMemStream(charInfo, rep, bms);
644 class CParameterTraitsSkill
: public CParameterTraitsEnum
647 CStringManager::CParameterTraits
*clone()
649 return new CParameterTraitsSkill();
651 CParameterTraitsSkill() : CParameterTraitsEnum(STRING_MANAGER::skill
, "skill")
653 const std::string
&getParameterId() const
655 return SKILLS::toString(SKILLS::ESkills(Enum
));
657 void setDefaultValue()
659 Enum
= SKILLS::unknown
;
663 class CParameterTraitsBodyPart
: public CParameterTraitsEnum
666 CStringManager::CParameterTraits
*clone()
668 return new CParameterTraitsBodyPart();
670 CParameterTraitsBodyPart() : CParameterTraitsEnum(STRING_MANAGER::body_part
, "bodypart")
672 const std::string
&getParameterId() const
674 return BODY::toString(BODY::TBodyPart(Enum
));
676 void setDefaultValue()
678 Enum
= BODY::UnknownBodyPart
;
682 class CParameterTraitsScore
: public CParameterTraitsEnum
685 CStringManager::CParameterTraits
*clone()
687 return new CParameterTraitsScore();
689 CParameterTraitsScore() : CParameterTraitsEnum(STRING_MANAGER::score
, "score")
691 const std::string
&getParameterId() const
693 return SCORES::toString(SCORES::TScores(Enum
));
695 void setDefaultValue()
697 Enum
= SCORES::unknown
;
701 class CParameterTraitsCharacteristic
: public CParameterTraitsEnum
704 CStringManager::CParameterTraits
*clone()
706 return new CParameterTraitsCharacteristic();
708 CParameterTraitsCharacteristic() : CParameterTraitsEnum(STRING_MANAGER::characteristic
, "characteristic")
710 const std::string
&getParameterId() const
712 return CHARACTERISTICS::toString(CHARACTERISTICS::TCharacteristics(Enum
));
714 void setDefaultValue()
716 Enum
= CHARACTERISTICS::Unknown
;
720 class CParameterTraitsDamageType
: public CParameterTraitsEnum
723 CStringManager::CParameterTraits
*clone()
725 return new CParameterTraitsDamageType();
727 CParameterTraitsDamageType() : CParameterTraitsEnum(STRING_MANAGER::damage_type
, "damagetype")
729 const std::string
&getParameterId() const
731 return DMGTYPE::toString(DMGTYPE::EDamageType(Enum
));
733 void setDefaultValue()
735 Enum
= DMGTYPE::UNDEFINED
;
739 class CParameterTraitsClassificationType
: public CParameterTraitsEnum
742 CStringManager::CParameterTraits
*clone()
744 return new CParameterTraitsClassificationType ();
746 CParameterTraitsClassificationType () : CParameterTraitsEnum(STRING_MANAGER::classification_type
, "classificationtype")
748 const std::string
&getParameterId() const
750 return DMGTYPE::toString(DMGTYPE::EDamageType(Enum
));
752 void setDefaultValue()
754 Enum
= EGSPD::CClassificationType::Unknown
;
759 class CParameterTraitsPowerType
: public CParameterTraitsEnum
762 CStringManager::CParameterTraits
*clone()
764 return new CParameterTraitsPowerType();
766 CParameterTraitsPowerType() : CParameterTraitsEnum(STRING_MANAGER::power_type
, "powertype")
768 const std::string
&getParameterId() const
770 return POWERS::toString(POWERS::TPowerType(Enum
));
772 void setDefaultValue()
774 Enum
= POWERS::UnknownType
;
778 class CParameterTraitsRole
: public CParameterTraitsEnum
781 CStringManager::CParameterTraits
*clone()
783 return new CParameterTraitsRole();
785 CParameterTraitsRole() : CParameterTraitsEnum(STRING_MANAGER::role
, "role")
787 const std::string
&getParameterId() const
789 return ROLES::toString(ROLES::ERole(Enum
));
791 void setDefaultValue()
793 // TODO : set a default value
794 Enum
= ROLES::role_unknown
;
799 class CParameterTraitsCareer : public CParameterTraitsEnum
802 CStringManager::CParameterTraits *clone()
804 return new CParameterTraitsCareer();
806 CParameterTraitsCareer() : CParameterTraitsEnum(STRING_MANAGER::career, "career")
808 const std::string &getParameterId() const
810 // TODO : use the career enum when it exist !
811 return ROLES::toString(ROLES::ERole(Enum));
813 void setDefaultValue()
815 Enum = ROLES::role_unknown;
820 class CParameterTraitsJob : public CParameterTraitsEnum
823 CStringManager::CParameterTraits *clone()
825 return new CParameterTraitsJob();
827 CParameterTraitsJob() : CParameterTraitsEnum(STRING_MANAGER::job, "job")
829 const std::string &getParameterId() const
831 return JOBS::toString(JOBS::TJob(Enum));
833 void setDefaultValue()
835 Enum = JOBS::Unknown;
839 class CParameterTraitsEcosystem
: public CParameterTraitsEnum
842 CStringManager::CParameterTraits
*clone()
844 return new CParameterTraitsEcosystem();
846 CParameterTraitsEcosystem() : CParameterTraitsEnum(STRING_MANAGER::ecosystem
, "ecosystem")
848 const std::string
&getParameterId() const
850 return ECOSYSTEM::toString(ECOSYSTEM::EECosystem(Enum
));
852 void setDefaultValue()
854 Enum
= ECOSYSTEM::unknown
;
857 class CParameterTraitsRace
: public CParameterTraitsEnum
860 CStringManager::CParameterTraits
*clone()
862 return new CParameterTraitsRace();
864 CParameterTraitsRace() : CParameterTraitsEnum(STRING_MANAGER::race
, "race")
866 const std::string
&getParameterId() const
868 return EGSPD::CPeople::toString(EGSPD::CPeople::TPeople(Enum
));
870 void setDefaultValue()
872 Enum
= EGSPD::CPeople::EndPeople
;
876 class CParameterTraitsBrick
: public CParameterTraitsSheet
879 CParameterTraitsBrick() : CParameterTraitsSheet(STRING_MANAGER::sbrick
, "sbrick")
882 CStringManager::CParameterTraits
*clone()
884 return new CParameterTraitsBrick();
888 class CParameterTraitsOutpostWord
: public CParameterTraitsSheet
891 CParameterTraitsOutpostWord() : CParameterTraitsSheet(STRING_MANAGER::outpost
, "outpost")
894 CStringManager::CParameterTraits
*clone()
896 return new CParameterTraitsOutpostWord();
898 const std::string
&getParameterId() const
900 static string sheetName
;
901 sheetName
= SheetId
.toString();
907 class CParameterTraitsBrick : public CParameterTraitsEnum
910 CStringManager::CParameterTraits *clone()
912 return new CParameterTraitsBrick();
914 CParameterTraitsBrick() : CParameterTraitsEnum(STRING_MANAGER::sbrick, "sbrick")
916 const std::string &getParameterId() const
918 // return BRICK_FAMILIES::toString(BRICK_FAMILIES::TBrickFamily(Enum));
919 return SheetId.toString();
921 void setDefaultValue()
923 Enum = BRICK_FAMILIES::Unknown;
927 class CParameterTraitsFaction
: public CParameterTraitsEnum
930 CStringManager::CParameterTraits
*clone()
932 return new CParameterTraitsFaction();
934 CParameterTraitsFaction() : CParameterTraitsEnum(STRING_MANAGER::faction
, "faction")
936 const std::string
&getParameterId() const
938 return CStaticFames::getInstance().getFactionName(Enum
);
940 void setDefaultValue()
942 // TODO : set a default value
946 class CParameterTraitsGuild
: public CParameterTraitsEntity
949 CStringManager::CParameterTraits
*clone()
951 return new CParameterTraitsGuild();
953 CParameterTraitsGuild() : CParameterTraitsEntity(STRING_MANAGER::guild
, "guild")
957 class CParameterTraitsPlayer
: public CParameterTraitsEntity
960 CStringManager::CParameterTraits
*clone()
962 return new CParameterTraitsPlayer();
964 CParameterTraitsPlayer() : CParameterTraitsEntity(STRING_MANAGER::player
, "player")
967 bool eval(CStringManager::TLanguages lang
, const CCharacterInfos
*charInfo
, const CStringManager::TCondition
&cond
) const
969 // Test unknown entity
970 if ((cond
.ReferenceInt
== 0) && (cond
.Property
.empty()))
972 if (cond
.Operator
== CStringManager::equal
)
973 return EId
.isUnknownId();
974 else if (cond
.Operator
== CStringManager::notEqual
)
975 return !EId
.isUnknownId();
978 // player can test model name, entity name, entity gender
979 // 1st, I need to retrieve the sheetId from the mirror
981 if (cond
.Property
== "name")
983 const NLMISC::CSheetId
&sheetId
= SM
->getSheetId(EId
);
984 if (sheetId
== NLMISC::CSheetId::Unknown
)
986 nlwarning("The sheet id for creature entity %s is unknown !", EId
.toString().c_str());
989 const CStringManager::TSheetInfo
&si
= SM
->getSheetInfo(sheetId
);
990 op1
= NLMISC::toLowerAscii(si
.SheetName
);
992 else if (cond
.Property
== "gender")
994 CCharacterInfos
*charInfo
= IOS
->getCharInfos(EId
);
995 if (charInfo
== NULL
)
997 nlwarning("Could not find character info for EId %s to check property %s", EId
.toString().c_str(), cond
.Property
.c_str());
1000 op1
= NLMISC::toLowerAscii(GSGENDER::toString(charInfo
->getGender()));
1004 return CParameterTraitsEntity::eval(lang
,charInfo
, cond
);
1007 LOG("SM : (player) eval condition for property %s [%s] %s [%s]", cond
.Property
.c_str(), op1
.c_str(), OperatorNames
[cond
.Operator
], cond
.ReferenceStr
.c_str());
1009 switch(cond
.Operator
)
1011 case CStringManager::equal
:
1012 return op1
== cond
.ReferenceStr
;
1013 case CStringManager::notEqual
:
1014 return op1
!= cond
.ReferenceStr
;
1015 case CStringManager::less
:
1016 return op1
< cond
.ReferenceStr
;
1017 case CStringManager::lessEqual
:
1018 return op1
<= cond
.ReferenceStr
;
1019 case CStringManager::greater
:
1020 return op1
> cond
.ReferenceStr
;
1021 case CStringManager::greaterEqual
:
1022 return op1
>= cond
.ReferenceStr
;
1024 nlwarning("Operator %s not applicable to player property %s", OperatorNames
[cond
.Operator
], cond
.Property
.c_str());
1027 nlerror("This point of code can never be reach !");
1029 void fillBitMemStream( const CCharacterInfos
*charInfo
,CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
1033 CCharacterInfos
*playerInfo
= IOS
->getCharInfos(EId
);
1034 if (playerInfo
!= 0)
1036 if (!playerInfo
->ShortName
.empty())
1038 uint32 index
= playerInfo
->ShortNameIndex
;
1043 // hum, no name available
1044 CParameterTraitsEntity::fillBitMemStream(charInfo
,language
, rep
, bms
);
1047 class CParameterTraitsBot
: public CParameterTraitsEntity
1050 CStringManager::CParameterTraits
*clone()
1052 return new CParameterTraitsBot();
1054 CParameterTraitsBot() : CParameterTraitsEntity(STRING_MANAGER::bot
, "bot")
1056 bool eval(CStringManager::TLanguages lang
, const CCharacterInfos
*charInfo
, const CStringManager::TCondition
&cond
) const
1058 // Test unknown entity
1059 if ((cond
.ReferenceInt
== 0) && (cond
.Property
.empty()))
1061 if (cond
.Operator
== CStringManager::equal
)
1062 return EId
.isUnknownId();
1063 else if (cond
.Operator
== CStringManager::notEqual
)
1064 return !EId
.isUnknownId();
1067 // bot can test career and role
1068 // 1st, I need to retrieve the sheetId from the mirror
1069 // TODO : reuse sheet server when AI fill in correctly !
1070 const NLMISC::CSheetId
&sheetId
= SM
->getSheetServerId(EId
);
1071 if (sheetId
== NLMISC::CSheetId::Unknown
)
1073 nlwarning("The sheet id for creature bot %s is unknown !", EId
.toString().c_str());
1077 LOG("Bot %s use server sheet %s", EId
.toString().c_str(), sheetId
.toString().c_str());
1078 const CStringManager::TSheetInfo
&si
= SM
->getSheetInfo(sheetId
);
1080 if (cond
.Property
== "career")
1084 else if (cond
.Property
== "role")
1086 op1
= NLMISC::toLowerAscii(si
.ChatProfile
);
1088 else if (cond
.Property
== "title")
1090 // we need to retrieve the charInfo
1091 CCharacterInfos
*ci
= IOS
->getCharInfos(EId
);
1093 op1
= NLMISC::toLowerAscii(ci
->Title
);
1096 nlwarning("No character info for bot %s, can't test property 'title' !", EId
.toString().c_str());
1102 return CParameterTraitsEntity::eval(lang
, charInfo
, cond
);
1105 LOG("SM : (bot) eval condition for property %s [%s] %s [%s]", cond
.Property
.c_str(), op1
.c_str(), OperatorNames
[cond
.Operator
], cond
.ReferenceStr
.c_str());
1107 switch(cond
.Operator
)
1109 case CStringManager::equal
:
1110 return op1
== cond
.ReferenceStr
;
1111 case CStringManager::notEqual
:
1112 return op1
!= cond
.ReferenceStr
;
1113 case CStringManager::less
:
1114 return op1
< cond
.ReferenceStr
;
1115 case CStringManager::lessEqual
:
1116 return op1
<= cond
.ReferenceStr
;
1117 case CStringManager::greater
:
1118 return op1
> cond
.ReferenceStr
;
1119 case CStringManager::greaterEqual
:
1120 return op1
>= cond
.ReferenceStr
;
1122 nlwarning("Operator %s not applicable to player property %s", OperatorNames
[cond
.Operator
], cond
.Property
.c_str());
1125 nlerror("This point of code can never be reach !");
1128 void fillBitMemStream( const CCharacterInfos
*charInfo
,CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
1130 // need to evaluate the name of the bot : should be in the charinfo
1133 CCharacterInfos
*botInfo
= IOS
->getCharInfos(EId
);
1136 if (!botInfo
->ShortName
.empty())
1138 uint32 index
= botInfo
->ShortNameIndex
;
1142 if (!botInfo
->Title
.empty())
1144 uint32 index
= SM
->translateTitle(botInfo
->Title
, language
);
1149 // hum, no name available
1150 CParameterTraitsEntity::fillBitMemStream(charInfo
, language
, rep
, bms
);
1153 class CParameterTraitsInteger
: public CStringManager::CParameterTraits
1156 CStringManager::CParameterTraits
*clone()
1158 return new CParameterTraitsInteger();
1160 CParameterTraitsInteger() : CParameterTraits(STRING_MANAGER::integer
, "integer")
1162 bool extractFromMessage(NLNET::CMessage
&message
, bool debug
)
1165 if (param
.serialParam(debug
, message
, ParamId
.Type
))
1175 // message.serial(Int);
1178 void fillBitMemStream( const CCharacterInfos
*charInfo
,CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
1183 const std::string
&getParameterId() const
1185 nlstopex(("Never call this !"));
1186 static std::string temp
= "";
1190 bool eval(CStringManager::TLanguages lang
, const CCharacterInfos
*charInfo
, const CStringManager::TCondition
&cond
) const
1192 switch(cond
.Operator
)
1194 case CStringManager::equal
:
1195 return Int
== cond
.ReferenceInt
;
1196 case CStringManager::notEqual
:
1197 return Int
!= cond
.ReferenceInt
;
1198 case CStringManager::greater
:
1199 return Int
> cond
.ReferenceInt
;
1200 case CStringManager::greaterEqual
:
1201 return Int
>= cond
.ReferenceInt
;
1202 case CStringManager::less
:
1203 return Int
< cond
.ReferenceInt
;
1204 case CStringManager::lessEqual
:
1205 return Int
<= cond
.ReferenceInt
;
1207 nlwarning("Operator not valid (%d)", cond
.Operator
);
1211 void setDefaultValue()
1216 class CParameterTraitsTime
: public CStringManager::CParameterTraits
1219 CStringManager::CParameterTraits
*clone()
1221 return new CParameterTraitsTime();
1223 CParameterTraitsTime() : CParameterTraits(STRING_MANAGER::time
, "time")
1225 bool extractFromMessage(NLNET::CMessage
&message
, bool debug
)
1228 if (param
.serialParam(debug
, message
, ParamId
.Type
))
1238 // message.serial(Time);
1240 void fillBitMemStream( const CCharacterInfos
*charInfo
,CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
1244 const std::string
&getParameterId() const
1246 nlstopex(("Never call this !"));
1247 static std::string temp
= "";
1250 bool eval(CStringManager::TLanguages lang
, const CCharacterInfos
*charInfo
, const CStringManager::TCondition
&cond
) const
1252 nlwarning("Time parameter can't be conditional");
1255 void setDefaultValue()
1260 class CParameterTraitsMoney
: public CStringManager::CParameterTraits
1263 CStringManager::CParameterTraits
*clone()
1265 return new CParameterTraitsMoney();
1267 CParameterTraitsMoney() : CParameterTraits(STRING_MANAGER::money
, "money")
1269 bool extractFromMessage(NLNET::CMessage
&message
, bool debug
)
1272 if (param
.serialParam(debug
, message
, ParamId
.Type
))
1274 Money
= param
.Money
;
1282 // message.serial(Money);
1284 void fillBitMemStream( const CCharacterInfos
*charInfo
,CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
1286 // TODO : serial only 48 bits
1289 const std::string
&getParameterId() const
1291 nlstopex(("Never call this !"));
1292 static std::string temp
= "";
1295 bool eval(CStringManager::TLanguages lang
, const CCharacterInfos
*charInfo
, const CStringManager::TCondition
&cond
) const
1297 nlwarning("Money parameter can't be conditional");
1300 void setDefaultValue()
1305 class CParameterTraitsCompass
: public CParameterTraitsEnum
1308 CStringManager::CParameterTraits
*clone()
1310 return new CParameterTraitsCompass();
1312 CParameterTraitsCompass() : CParameterTraitsEnum(STRING_MANAGER::compass
, "compass")
1314 const std::string
&getParameterId() const
1316 // TODO : add an enum for compass dir in game_share
1317 static std::string temp
= "";
1320 void setDefaultValue()
1322 // TODO : set a default value
1326 class CParameterTraitsStringId
: public CStringManager::CParameterTraits
1329 CStringManager::CParameterTraits
*clone()
1331 return new CParameterTraitsStringId();
1333 CParameterTraitsStringId() : CParameterTraits(STRING_MANAGER::string_id
, "string_id")
1335 bool extractFromMessage(NLNET::CMessage
&message
, bool debug
)
1338 if (param
.serialParam(debug
, message
, ParamId
.Type
))
1340 StringId
= param
.StringId
;
1348 // message.serial(StringId);
1350 void fillBitMemStream( const CCharacterInfos
*charInfo
,CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
1352 bms
.serial(StringId
);
1354 const std::string
&getParameterId() const
1357 static std::string temp
= "";
1360 bool eval(CStringManager::TLanguages lang
, const CCharacterInfos
*charInfo
, const CStringManager::TCondition
&cond
) const
1362 switch(cond
.Operator
)
1364 case CStringManager::equal
:
1365 return StringId
== uint32(cond
.ReferenceInt
);
1366 case CStringManager::notEqual
:
1367 return StringId
!= uint32(cond
.ReferenceInt
);
1369 nlwarning("Operator %s not applicable to self property %s", OperatorNames
[cond
.Operator
], cond
.Property
.c_str());
1373 void setDefaultValue()
1378 class CParameterTraitsdyn_string_id
: public CStringManager::CParameterTraits
1381 CStringManager::CParameterTraits
*clone()
1383 return new CParameterTraitsdyn_string_id();
1385 CParameterTraitsdyn_string_id() : CParameterTraits(STRING_MANAGER::dyn_string_id
, "dyn_string_id")
1387 bool extractFromMessage(NLNET::CMessage
&message
, bool debug
)
1390 if (param
.serialParam(debug
, message
, ParamId
.Type
))
1392 StringId
= param
.StringId
;
1400 // message.serial(StringId);
1402 void fillBitMemStream( const CCharacterInfos
*charInfo
,CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
1404 bms
.serial(StringId
);
1406 const std::string
&getParameterId() const
1409 static std::string temp
= "";
1412 bool eval(CStringManager::TLanguages lang
, const CCharacterInfos
*charInfo
, const CStringManager::TCondition
&cond
) const
1414 switch(cond
.Operator
)
1416 case CStringManager::equal
:
1417 return StringId
== uint32(cond
.ReferenceInt
);
1418 case CStringManager::notEqual
:
1419 return StringId
!= uint32(cond
.ReferenceInt
);
1421 nlwarning("Operator %s not applicable to self property %s", OperatorNames
[cond
.Operator
], cond
.Property
.c_str());
1425 void setDefaultValue()
1430 class CParameterTraitsSelf
: public CParameterTraitsEntity
1433 CStringManager::CParameterTraits
*clone()
1435 return new CParameterTraitsSelf();
1437 CParameterTraitsSelf() : CParameterTraitsEntity(STRING_MANAGER::self
, "self")
1439 bool extractFromMessage(NLNET::CMessage
&message
, bool debug
)
1441 nlwarning("CParameterTraitsSelf can't be received !");
1444 const std::string
&getParameterId() const
1446 // TODO : retreive the entity name...
1447 static std::string temp
= "";
1450 bool eval(CStringManager::TLanguages lang
, const CCharacterInfos
*charInfo
, const CStringManager::TCondition
&cond
) const
1456 // check if checked property is gender or name
1457 if (cond
.Property
== "gender")
1459 value
= NLMISC::toLowerAscii(GSGENDER::toString(charInfo
->getGender()));
1461 else if (cond
.Property
== "name")
1463 value
= NLMISC::toLowerAscii(charInfo
->ShortName
.toString());
1467 return CParameterTraitsEntity::eval(lang
,charInfo
, cond
);
1470 LOG("SM : (self) eval condition for property %s [%s] %s [%s]", cond
.Property
.c_str(), value
.c_str(), OperatorNames
[cond
.Operator
], cond
.ReferenceStr
.c_str());
1472 switch(cond
.Operator
)
1474 case CStringManager::equal
:
1475 return value
== cond
.ReferenceStr
;
1476 case CStringManager::notEqual
:
1477 return value
!= cond
.ReferenceStr
;
1478 case CStringManager::less
:
1479 return value
< cond
.ReferenceStr
;
1480 case CStringManager::lessEqual
:
1481 return value
<= cond
.ReferenceStr
;
1482 case CStringManager::greater
:
1483 return value
> cond
.ReferenceStr
;
1484 case CStringManager::greaterEqual
:
1485 return value
>= cond
.ReferenceStr
;
1487 nlwarning("Operator %s not applicable to self property %s", OperatorNames
[cond
.Operator
], cond
.Property
.c_str());
1491 void fillBitMemStream( const CCharacterInfos
*charInfo
,CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
1493 // need to evaluate the name of the bot : should be in the charinfo
1498 if (!charInfo
->Name
.empty())
1500 uint32 index
= charInfo
->ShortNameIndex
;
1505 // hum, no name available
1506 CParameterTraitsEntity::fillBitMemStream(charInfo
, language
, rep
, bms
);
1510 class CParameterTraitsCreatureModel
: public CParameterTraitsSheet
1513 CParameterTraitsCreatureModel() : CParameterTraitsSheet(STRING_MANAGER::creature_model
, "creature")
1516 CStringManager::CParameterTraits
*clone()
1518 return new CParameterTraitsItem();
1522 class CParameterTraitsLiteral
: public CStringManager::CParameterTraits
1525 CParameterTraitsLiteral() : CParameterTraits(STRING_MANAGER::literal
, "literal")
1528 CStringManager::CParameterTraits
*clone()
1530 return new CParameterTraitsLiteral();
1533 /// Return parameter id, ie, the name that is use to identity the data row in the csv file.
1534 virtual const std::string
&getParameterId() const
1537 static const string s
;
1540 /// Extract the parameter value from a message.
1541 virtual bool extractFromMessage(NLNET::CMessage
&message
, bool debug
)
1544 if (param
.serialParam(debug
, message
, ParamId
.Type
))
1546 Literal
= param
.Literal
;
1555 /// Fill a bitmem strean with the parameter value.
1556 virtual void fillBitMemStream( const CCharacterInfos
*charInfo
, CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
1558 uint32 id
= SM
->storeString(Literal
);
1561 /// Eval a condition with this parameter.
1562 // virtual bool eval(TLanguages lang, const CCharacterInfos *charInfo, const TCondition &cond) const;
1563 /// set a default value
1564 virtual void setDefaultValue()
1566 Literal
= ucstring();
1571 class CParameterTraitsTitle
: public CParameterTraitsIdentifier
1574 CParameterTraitsTitle() : CParameterTraitsIdentifier(STRING_MANAGER::title
, "title")
1577 CStringManager::CParameterTraits
*clone()
1579 return new CParameterTraitsTitle();
1584 class CParameterTraitsEventFaction
: public CParameterTraitsIdentifier
1587 CParameterTraitsEventFaction() : CParameterTraitsIdentifier(STRING_MANAGER::event_faction
, "event_faction")
1590 CStringManager::CParameterTraits
*clone()
1592 return new CParameterTraitsEventFaction();
1595 void fillBitMemStream( const CCharacterInfos
*charInfo
, CStringManager::TLanguages language
, const CStringManager::TReplacement
&rep
, NLMISC::CBitMemStream
&bms
)
1597 uint32 eventFactionId
= SM
->translateEventFaction(Identifier
);
1599 // serial the string ID
1600 bms
.serial(eventFactionId
);
1606 * WARNING: the order in this array is very important, and MUST match exactly
1607 * the order in the TParamType enum declared in string_manager_sender.h
1609 std::vector
<CStringManager::CParameterTraits
*> CStringManager::CParameterTraits::_Models
;
1611 void CStringManager::CParameterTraits::init()
1613 _Models
.push_back(new CParameterTraitsItem());
1614 _Models
.push_back(new CParameterTraitsPlace());
1615 _Models
.push_back(new CParameterTraitsCreature());
1616 _Models
.push_back(new CParameterTraitsSkill());
1617 _Models
.push_back(new CParameterTraitsRole());
1618 _Models
.push_back(new CParameterTraitsEcosystem());
1619 _Models
.push_back(new CParameterTraitsRace());
1620 _Models
.push_back(new CParameterTraitsBrick());
1621 _Models
.push_back(new CParameterTraitsFaction());
1622 _Models
.push_back(new CParameterTraitsGuild());
1623 _Models
.push_back(new CParameterTraitsPlayer());
1624 _Models
.push_back(new CParameterTraitsBot());
1625 _Models
.push_back(new CParameterTraitsInteger());
1626 _Models
.push_back(new CParameterTraitsTime());
1627 _Models
.push_back(new CParameterTraitsMoney());
1628 _Models
.push_back(new CParameterTraitsCompass());
1629 _Models
.push_back(new CParameterTraitsStringId());
1630 _Models
.push_back(new CParameterTraitsdyn_string_id());
1631 _Models
.push_back(new CParameterTraitsSelf());
1632 _Models
.push_back(new CParameterTraitsCreatureModel());
1633 _Models
.push_back(new CParameterTraitsEntity(STRING_MANAGER::entity
, "entity"));
1634 _Models
.push_back(new CParameterTraitsBodyPart());
1635 _Models
.push_back(new CParameterTraitsScore());
1636 _Models
.push_back(new CParameterTraitsSPhrase());
1637 _Models
.push_back(new CParameterTraitsCharacteristic());
1638 _Models
.push_back(new CParameterTraitsDamageType());
1639 _Models
.push_back(new CParameterTraitsBotName());
1640 _Models
.push_back(new CParameterTraitsPowerType());
1641 _Models
.push_back(new CParameterTraitsLiteral());
1642 _Models
.push_back(new CParameterTraitsTitle());
1643 _Models
.push_back(new CParameterTraitsEventFaction());
1644 _Models
.push_back(new CParameterTraitsClassificationType());
1645 _Models
.push_back(new CParameterTraitsOutpostWord());
1648 CStringManager::CParameterTraits
*CStringManager::CParameterTraits::createParameterTraits(STRING_MANAGER::TParamType type
)
1650 for (uint i
=0; i
<_Models
.size(); ++i
)
1652 if (_Models
[i
]->ParamId
.Type
== type
)
1653 return _Models
[i
]->clone();
1660 std::vector
<std::pair
<STRING_MANAGER::TParamType
, std::string
> > CStringManager::CParameterTraits::getParameterTraitsNames()
1662 std::vector
<std::pair
<STRING_MANAGER::TParamType
, std::string
> > ret
;
1663 for (uint i
=0; i
<_Models
.size(); ++i
)
1665 ret
.push_back(std::make_pair(_Models
[i
]->ParamId
.Type
, _Models
[i
]->TypeName
));