Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / tools / leveldesign / mission_compiler_lib / step_content.cpp
blob073f6ddea26b1e12144992919c612f2508d9dfdd
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2011 Fabien HENON
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "mission_compiler.h"
22 #include "step.h"
24 #include "nel/ligo/primitive_utils.h"
26 using namespace std;
27 using namespace NLMISC;
28 using namespace NLLIGO;
31 // ************
32 // IStepContent
33 // ************
35 IStepContent *IStepContent::createStepContent(CMissionData &md, NLLIGO::IPrimitive *prim)
37 string className;
38 prim->getPropertyByName("class", className);
40 IStepContentFactory *factory = CFactoryIndirect<IStepContentFactory, string>::instance().getFactory(className);
41 if (factory == NULL)
43 string err = toString("Can't find factory for class '%s'", className.c_str());
44 throw EParseException(prim, err.c_str());
47 IStepContent *content = factory->createStepContent(md, prim);
48 return content;
51 void IStepContent::init(CMissionData &md, NLLIGO::IPrimitive *prim)
53 prim->getPropertyByName("name", _ContentName);
55 // parse the post actions
56 for (uint i=0; i<prim->getNumChildren(); ++i)
58 IPrimitive *child;
59 prim->getChild(child, i);
60 if (child)
62 // ok, we got one
63 IStepContent *sc = IStepContent::createStepContent(md, child);
64 if (sc)
65 _PostActions.push_back(sc);
70 std::string IStepContent::genStepContentCode(CMissionData &md)
72 string ret;
73 // call the derived class code generation
74 ret += genCode(md);
76 // generate the code for the post action
77 for (uint i=0; i<_PostActions.size(); ++i)
79 ret += _PostActions[i]->genCode(md);
82 return ret;
85 std::string IStepContent::genStepContentPhrase()
87 string ret;
89 // call ther derived class phrase generation
90 ret += genPhrase();
92 // generate the phrase for the post action
93 for (uint i=0; i<_PostActions.size(); ++i)
95 ret += _PostActions[i]->genPhrase();
98 return ret;
101 void IStepContent::fillJump(CMissionData &md, std::set<TJumpInfo> &jumpPoints)
103 for (uint i=0; i<_PostActions.size(); ++i)
105 _PostActions[i]->fillJump(md, jumpPoints);
110 ////////////////////// Actions and objectives /////////////////////
112 class CActionJumpTo : public IStepContent
114 string _JumpTo;
116 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
118 numEntry = 0;
120 public:
121 void init(CMissionData &md, IPrimitive *prim)
123 IStepContent::init(md, prim);
124 _JumpTo = md.getProperty(prim, "target", true, false);
127 string genCode(CMissionData &md)
129 if (!_JumpTo.empty())
130 return "jump : "+_JumpTo+NL;
131 else
132 return string();
135 void fillJump(CMissionData &md, std::set<TJumpInfo> &jumpPoints)
137 IStepContent::fillJump(md, jumpPoints);
138 jumpPoints.insert(TJumpInfo(_JumpTo, "", false));
142 REGISTER_STEP_CONTENT(CActionJumpTo, "jump_to");
145 // ---------------------------------------------------------------------------
146 class CActionRecvMoney : public IStepContent
148 string _Amount;
149 bool _Guild;
151 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
153 numEntry = 0;
155 public:
156 void init(CMissionData &md, IPrimitive *prim)
158 IStepContent::init(md, prim);
159 _Amount = md.getProperty(prim, "amount", true, false);
161 _Guild = md.getProperty(prim, "guild", false, true) == "true";
162 // Check: if _Guild is true then check if we are in a guild mission
163 if (_Guild && !md.isGuildMission())
165 string err = toString("primitive(%s): 'guild' option true 1 for non guild mission.", prim->getName().c_str());
166 throw EParseException(prim, err.c_str());
170 string genCode(CMissionData &md)
172 if (!_Amount.empty())
174 string ret;
175 ret = "recv_money : "+_Amount;
176 if (_Guild)
177 ret += ": guild";
178 ret += NL;
179 return ret;
181 else
182 return string();
186 REGISTER_STEP_CONTENT(CActionRecvMoney, "recv_money");
189 // ---------------------------------------------------------------------------
190 class CActionRecvChargePoint : public IStepContent
192 string _Amount;
194 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
196 numEntry = 0;
198 public:
199 void init(CMissionData &md, IPrimitive *prim)
201 IStepContent::init(md, prim);
202 _Amount = md.getProperty(prim, "charge_points", true, false);
205 string genCode(CMissionData &md)
207 if (!_Amount.empty())
209 string ret;
210 ret = "recv_charge_point : "+_Amount;
211 ret += NL;
212 return ret;
214 else
215 return string();
219 REGISTER_STEP_CONTENT(CActionRecvChargePoint, "recv_charge_point");
222 // ---------------------------------------------------------------------------
223 class CActionGiveOutpostControl : public IStepContent
225 string _OutpostName;
227 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
229 numEntry = 0;
231 public:
232 void init(CMissionData &md, IPrimitive *prim)
234 IStepContent::init(md, prim);
235 _OutpostName = md.getProperty(prim, "outpost_name", true, false);
238 string genCode(CMissionData &md)
240 if (!_OutpostName.empty())
242 string ret;
243 ret = "give_control : "+_OutpostName;
244 ret += NL;
245 return ret;
247 else
248 return string();
252 REGISTER_STEP_CONTENT(CActionGiveOutpostControl, "give_control");
255 // ---------------------------------------------------------------------------
256 class CActionSpawnMission : public IStepContent
258 protected:
259 string _MissionName;
260 string _GiverName;
261 bool _Guild;
262 private:
263 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
265 numEntry = 0;
267 public:
268 void init(CMissionData &md, IPrimitive *prim)
270 IStepContent::init(md, prim);
271 _MissionName = md.getProperty(prim, "mission_name", true, false);
272 _GiverName = md.getProperty(prim, "giver_name", true, false);
273 if (_GiverName.empty())
275 throw EParseException(prim, "giver_name is empty !");
278 _Guild = md.getProperty(prim, "guild", false, true) == "true";
279 // Check: if _Guild is true then check if we are in a guild mission
280 if (_Guild && !md.isGuildMission())
282 string err = toString("primitive(%s): 'guild' option true 1 for non guild mission.", prim->getName().c_str());
283 throw EParseException(prim, err.c_str());
287 string genCode(CMissionData &md)
289 string ret;
290 if (!_MissionName.empty())
292 ret = "spawn_mission : " + _MissionName + " : " + _GiverName;
293 if (_Guild)
294 ret += " : guild";
295 ret += NL;
297 return ret;
300 REGISTER_STEP_CONTENT(CActionSpawnMission, "spawn_mission");
303 // ---------------------------------------------------------------------------
304 class CActionChainMission : public CActionSpawnMission
306 public:
308 string genCode(CMissionData &md)
311 if (!_MissionName.empty())
315 return "chain_mission : " + _MissionName + " : " + _GiverName + NL;
317 else
318 return string();
322 REGISTER_STEP_CONTENT(CActionChainMission, "chain_mission");
325 // ---------------------------------------------------------------------------
326 class CActionEncycloUnlock : public IStepContent
328 string _AlbumThema;
330 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
332 numEntry = 0;
334 public:
335 void init(CMissionData &md, IPrimitive *prim)
337 IStepContent::init(md, prim);
338 _AlbumThema = md.getProperty(prim, "album_thema", true, false);
341 string genCode(CMissionData &md)
343 if (!_AlbumThema.empty())
344 return "encyclo_unlock : " + _AlbumThema + NL;
345 else
346 return string();
350 REGISTER_STEP_CONTENT(CActionEncycloUnlock, "encyclo_unlock");
353 // ---------------------------------------------------------------------------
354 class CActionHandleCreate : public IStepContent
356 protected:
357 string _Group;
358 string _DespawnTimer;
359 private:
360 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
362 numEntry = 0;
364 public:
365 void init(CMissionData &md, IPrimitive *prim)
367 IStepContent::init(md, prim);
368 _Group = md.getProperty(prim, "group", true, false);
369 _DespawnTimer = md.getProperty(prim, "despawn_timer", true, false);
372 string genCode(CMissionData &md)
374 if (!_Group.empty())
376 if (!_DespawnTimer.empty())
377 return "handle_create : " + _Group + " : " + _DespawnTimer + NL;
378 else
379 return "handle_create : " + _Group + NL;
381 else
382 return string();
386 REGISTER_STEP_CONTENT(CActionHandleCreate, "handle_create");
389 // ---------------------------------------------------------------------------
390 class CActionHandleRelease : public IStepContent
392 protected:
393 string _Group;
395 private:
396 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
398 numEntry = 0;
400 public:
401 void init(CMissionData &md, IPrimitive *prim)
403 IStepContent::init(md, prim);
404 _Group = md.getProperty(prim, "group", true, false);
407 string genCode(CMissionData &md)
409 if (!_Group.empty())
410 return "handle_release : " + _Group + NL;
411 else
412 return string();
416 REGISTER_STEP_CONTENT(CActionHandleRelease, "handle_release");
419 // ---------------------------------------------------------------------------
420 class CActionSetEventFaction : public IStepContent
422 string _EventFaction;
424 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
426 numEntry = 0;
428 public:
429 void init(CMissionData &md, IPrimitive *prim)
431 IStepContent::init(md, prim);
432 _EventFaction = md.getProperty(prim, "event_faction", true, false);
435 string genCode(CMissionData &md)
437 if (!_EventFaction.empty())
438 return "set_event_faction : " + _EventFaction + NL;
439 else
440 return string();
444 REGISTER_STEP_CONTENT(CActionSetEventFaction, "set_event_faction");
447 // ---------------------------------------------------------------------------
448 class CActionSetRespawnPoints : public IStepContent
450 string _Continent;
451 vector<string> _RespawnPoints;
452 bool _HideOthers;
454 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
456 numEntry = 0;
458 public:
459 void init(CMissionData &md, IPrimitive *prim)
461 IStepContent::init(md, prim);
462 _Continent = md.getProperty(prim, "continent", true, false);
464 vector<string> vs;
465 vs = md.getPropertyArray(prim, "respawn_points", true, false);
467 for (uint i=0; i<vs.size(); ++i)
469 if (!vs[i].empty())
470 _RespawnPoints.push_back(vs[i]);
473 string s;
474 s = md.getProperty(prim, "hide_others", true, false);
475 _HideOthers = NLMISC::toBool(s);
478 string genCode(CMissionData &md)
480 string ret;
482 if (_Continent.empty() || _RespawnPoints.empty())
483 return ret;
485 ret = "set_respawn_points : " + _Continent + " : ";
487 for (uint i = 0; i < _RespawnPoints.size(); i++)
489 ret += _RespawnPoints[i];
490 if (i < _RespawnPoints.size() - 1)
491 ret += "; ";
494 ret += string(" : ") + (_HideOthers?"true":"false");
495 ret += NL;
497 return ret;
501 REGISTER_STEP_CONTENT(CActionSetRespawnPoints, "set_respawn_points");
504 // ---------------------------------------------------------------------------
505 class CActionRecvFactionPoint : public IStepContent
507 string _Faction;
508 string _Point;
510 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
512 numEntry = 0;
514 public:
515 void init(CMissionData &md, IPrimitive *prim)
517 IStepContent::init(md, prim);
519 _Faction = md.getProperty(prim, "faction", true, false);
520 _Point = md.getProperty(prim, "point", true, false);
523 string genCode(CMissionData &md)
525 if (!_Faction.empty() && !_Point.empty())
526 return string("recv_faction_point : ")+_Faction+" "+_Point+NL;
527 else
528 return string();
531 REGISTER_STEP_CONTENT(CActionRecvFactionPoint, "recv_faction_point");
534 // ---------------------------------------------------------------------------
535 class CActionSDBSet : public IStepContent
537 string _SDBPath;
538 string _SDBValue;
540 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
542 numEntry = 0;
544 public:
545 void init(CMissionData &md, IPrimitive *prim)
547 IStepContent::init(md, prim);
548 _SDBPath = md.getProperty(prim, "sdb_path", true, false);
549 _SDBValue = md.getProperty(prim, "sdb_value", true, false);
552 string genCode(CMissionData &md)
554 string ret;
556 if (_SDBPath.empty() || _SDBValue.empty())
557 return ret;
559 ret = "sdb_set : " + _SDBPath + " : " + _SDBValue + NL;
560 return ret;
564 REGISTER_STEP_CONTENT(CActionSDBSet, "sdb_set");
567 // ---------------------------------------------------------------------------
568 class CActionSDBAdd : public IStepContent
570 string _SDBPath;
571 string _SDBValue;
573 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
575 numEntry = 0;
577 public:
578 void init(CMissionData &md, IPrimitive *prim)
580 IStepContent::init(md, prim);
581 _SDBPath = md.getProperty(prim, "sdb_path", true, false);
582 _SDBValue = md.getProperty(prim, "sdb_value", true, false);
585 string genCode(CMissionData &md)
587 string ret;
589 if (_SDBPath.empty() || _SDBValue.empty())
590 return ret;
592 ret = "sdb_add : " + _SDBPath + " : " + _SDBValue + NL;
593 return ret;
597 REGISTER_STEP_CONTENT(CActionSDBAdd, "sdb_add");
600 // ---------------------------------------------------------------------------
601 class CActionSDBPlayerAdd : public IStepContent
603 string _SDBPath;
604 string _SDBValue;
606 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
608 numEntry = 0;
610 public:
611 void init(CMissionData &md, IPrimitive *prim)
613 IStepContent::init(md, prim);
614 _SDBPath = md.getProperty(prim, "sdb_path", true, false);
615 _SDBValue = md.getProperty(prim, "sdb_value", true, false);
618 string genCode(CMissionData &md)
620 string ret;
622 if (_SDBPath.empty() || _SDBValue.empty())
623 return ret;
625 ret = "sdb_player_add : " + _SDBPath + " : " + _SDBValue + NL;
626 return ret;
630 REGISTER_STEP_CONTENT(CActionSDBPlayerAdd, "sdb_player_add");
633 // ---------------------------------------------------------------------------
634 class CActionSDBSetPvPPath : public IStepContent
636 string _SDBPath;
638 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
640 numEntry = 0;
642 public:
643 void init(CMissionData &md, IPrimitive *prim)
645 IStepContent::init(md, prim);
646 _SDBPath = md.getProperty(prim, "sdb_path", true, false);
649 string genCode(CMissionData &md)
651 string ret;
653 if (_SDBPath.empty())
654 return ret;
656 ret = "sdb_set_pvp_path : " + _SDBPath + NL;
657 return ret;
661 REGISTER_STEP_CONTENT(CActionSDBSetPvPPath, "sdb_set_pvp_path");
664 // ---------------------------------------------------------------------------
665 class CActionSDBClearPvPPath : public IStepContent
667 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
669 numEntry = 0;
671 public:
672 void init(CMissionData &md, IPrimitive *prim)
674 IStepContent::init(md, prim);
677 string genCode(CMissionData &md)
679 string ret = "sdb_clear_pvp_path" + NL;
680 return ret;
684 REGISTER_STEP_CONTENT(CActionSDBClearPvPPath, "sdb_clear_pvp_path");
687 // ---------------------------------------------------------------------------
688 class CActionRecvFame : public IStepContent
690 string _Faction;
691 string _Fame;
692 bool _Guild;
694 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
696 numEntry = 0;
698 public:
699 void init(CMissionData &md, IPrimitive *prim)
701 IStepContent::init(md, prim);
703 _Faction = md.getProperty(prim, "faction", true, false);
704 _Fame = md.getProperty(prim, "value", true, false);
706 _Guild = md.getProperty(prim, "guild", false, true) == "true";
707 // Check: if _Guild is true then check if we are in a guild mission
708 if (_Guild && !md.isGuildMission())
710 string err = toString("primitive(%s): 'guild' option true 1 for non guild mission.", prim->getName().c_str());
711 throw EParseException(prim, err.c_str());
715 string genCode(CMissionData &md)
717 if (!_Faction.empty() && !_Fame.empty())
719 string ret;
720 ret = "recv_fame : "+_Faction+" "+_Fame;
721 if (_Guild)
722 ret += ": guild";
723 ret += NL;
724 return ret;
726 else
727 return string();
730 REGISTER_STEP_CONTENT(CActionRecvFame, "recv_fame");
732 // ---------------------------------------------------------------------------
733 struct TItemDesc
735 string ItemName;
736 string ItemQuant;
737 string ItemQual;
740 class CActionRecvItem : public IStepContent
742 string _BotGiver;
743 vector<TItemDesc> _Items;
744 bool _QualSpec;
745 bool _Group;
746 bool _Guild;
748 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
750 numEntry = 0;
752 public:
753 void init(CMissionData &md, IPrimitive *prim)
755 _BotGiver =md.getProperty(prim, "npc_name", true, false);
756 vector<string> vs;
757 vs = md.getPropertyArray(prim, "item/quantity/quality", true, false);
758 for (uint i=0; i<vs.size(); ++i)
760 vector<string> args;
761 if (!vs[i].empty())
763 explode(vs[i], string(" "), args, false);
764 if (args.size() != 3 && args.size() != 2)
766 string err = toString("can't find 2 or 3 part (<item> <quant> [<qual>]) in item line '%s', found %u instead", vs[i].c_str(), args.size());
767 throw EParseException(prim, err.c_str());
770 if (i == 0)
772 _QualSpec = (args.size() == 3);
774 else if (args.size() == 3 && !_QualSpec)
776 string err = toString("can't mix item with quality and item without quality in item line '%s'", vs[i].c_str());
777 throw EParseException(prim, err.c_str());
780 TItemDesc item;
781 item.ItemName = args[0];
782 item.ItemQuant = args[1];
783 if (_QualSpec)
784 item.ItemQual = args[2];
786 _Items.push_back(item);
790 string s;
791 s = md.getProperty(prim, "group", true, false);
792 _Group = NLMISC::toBool(s);
794 _Guild = md.getProperty(prim, "guild", false, true) == "true";
795 // Check: if _Guild is true then check if we are in a guild mission
796 if (_Guild && !md.isGuildMission())
798 string err = toString("primitive(%s): 'guild' option true 1 for non guild mission.", prim->getName().c_str());
799 throw EParseException(prim, err.c_str());
802 IStepContent::init(md, prim);
805 string genCode(CMissionData &md)
807 string ret;
808 for (uint i=0; i<_Items.size(); ++i)
810 TItemDesc &item = _Items[i];
812 ret += "recv_item : "+item.ItemName+" "+item.ItemQuant;
813 if (_QualSpec)
814 ret +=" "+item.ItemQual;
815 if (!_BotGiver.empty())
816 ret += " : "+_BotGiver;
817 if (_Group)
818 ret += " : group";
819 if (_Guild)
820 ret += ": guild";
821 ret += NL;
824 return ret;
828 REGISTER_STEP_CONTENT(CActionRecvItem, "recv_item");
830 // ---------------------------------------------------------------------------
831 class CActionRecvNamedItem : public IStepContent
833 vector<TItemDesc> _Items;
834 bool _Group;
835 bool _Guild;
837 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
839 numEntry = 0;
841 public:
842 void init(CMissionData &md, IPrimitive *prim)
844 vector<string> vs;
845 vs = md.getPropertyArray(prim, "item/quantity", true, false);
846 for (uint i=0; i<vs.size(); ++i)
848 vector<string> args;
849 if (!vs[i].empty())
851 explode(vs[i], string(" "), args, false);
852 if (args.size() != 1 && args.size() != 2)
854 string err = toString("can't find 1 or 2 part (<item> [<quant>]) in item line '%s', found %u instead", vs[i].c_str(), args.size());
855 throw EParseException(prim, err.c_str());
858 TItemDesc item;
859 item.ItemName = args[0];
860 item.ItemQuant = "1";
861 if(args.size()>=2 && atoi(args[1].c_str())>0)
862 item.ItemQuant = args[1];
864 _Items.push_back(item);
868 string s;
869 s = md.getProperty(prim, "group", true, false);
870 _Group = NLMISC::toBool(s);
872 _Guild = md.getProperty(prim, "guild", false, true) == "true";
873 // Check: if _Guild is true then check if we are in a guild mission
874 if (_Guild && !md.isGuildMission())
876 string err = toString("primitive(%s): 'guild' option true 1 for non guild mission.", prim->getName().c_str());
877 throw EParseException(prim, err.c_str());
880 IStepContent::init(md, prim);
883 string genCode(CMissionData &md)
885 string ret;
886 for (uint i=0; i<_Items.size(); ++i)
888 TItemDesc &item = _Items[i];
890 ret += "recv_named_item : "+item.ItemName+" "+item.ItemQuant;
891 if (_Group)
892 ret += " : group";
893 if (_Guild)
894 ret += ": guild";
895 ret += NL;
898 return ret;
902 REGISTER_STEP_CONTENT(CActionRecvNamedItem, "recv_named_item");
904 // ---------------------------------------------------------------------------
905 class CActionDestroyItem : public IStepContent
907 struct CItemDesc
909 TItemDesc Desc;
910 bool QuantSpec;
911 bool QualSpec;
914 string _BotDestroyer;
915 vector<CItemDesc> _Items;
916 bool _Guild;
918 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
920 numEntry = 0;
922 public:
923 void init(CMissionData &md, IPrimitive *prim)
925 // get the bot who destroys the item
926 _BotDestroyer =md.getProperty(prim, "npc_name", true, false);
928 // read list of items to destroy
929 vector<string> vs;
930 vs = md.getPropertyArray(prim, "item/quantity/quality", true, false);
931 for (uint i=0; i<vs.size(); ++i)
933 vector<string> args;
934 if (!vs[i].empty())
936 // parse
937 explode(vs[i], string(" "), args, false);
938 if (args.size()<1 || args.size()>3)
940 string err = toString("can't find 1, 2 or 3 part (<item> [<quant>] [<qual>]) in item line '%s', found %u instead", vs[i].c_str(), args.size());
941 throw EParseException(prim, err.c_str());
944 // add the item in desc
945 CItemDesc item;
946 item.Desc.ItemName = args[0];
947 if(args.size()>=2)
949 item.QuantSpec= true;
950 item.Desc.ItemQuant = args[1];
952 if(args.size()>=3)
954 item.QualSpec= true;
955 item.Desc.ItemQual = args[2];
958 _Items.push_back(item);
962 _Guild = md.getProperty(prim, "guild", false, true) == "true";
963 // Check: if _Guild is true then check if we are in a guild mission
964 if (_Guild && !md.isGuildMission())
966 string err = toString("primitive(%s): 'guild' option true 1 for non guild mission.", prim->getName().c_str());
967 throw EParseException(prim, err.c_str());
970 IStepContent::init(md, prim);
973 string genCode(CMissionData &md)
975 string ret;
976 for (uint i=0; i<_Items.size(); ++i)
978 CItemDesc &item = _Items[i];
980 ret += "destroy_item : "+item.Desc.ItemName;
981 if (item.QuantSpec)
982 ret +=" "+item.Desc.ItemQuant;
983 if (item.QualSpec)
984 ret +=" "+item.Desc.ItemQual;
985 if (!_BotDestroyer.empty())
986 ret += " : "+_BotDestroyer;
987 if (_Guild)
988 ret += ": guild";
989 ret += NL;
992 return ret;
996 REGISTER_STEP_CONTENT(CActionDestroyItem, "destroy_item");
998 // ---------------------------------------------------------------------------
999 class CActionRecvXp : public IStepContent
1001 string _Skill;
1002 sint32 _Value;
1004 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1006 numEntry = 0;
1008 public:
1010 void init(CMissionData &md, IPrimitive *prim)
1012 IStepContent::init(md, prim);
1013 _Skill = md.getProperty(prim, "skill", true, false);
1014 _Value = atoi(md.getProperty(prim, "value", true, false).c_str());
1015 if(_Skill.empty() || tolower(_Skill[0])!='s' || _Value<=0)
1017 string err = toString("Bad skill name or value: '%s' '%d' ", _Skill.c_str(), _Value);
1018 throw EParseException(prim, err.c_str());
1022 string genCode(CMissionData &md)
1024 if (!_Skill.empty())
1025 return toString("recv_xp : %s %d", _Skill.c_str(), _Value) + NL;
1026 else
1027 return string();
1030 REGISTER_STEP_CONTENT(CActionRecvXp, "recv_xp");
1032 // ---------------------------------------------------------------------------
1033 class CActionLearnAction : public IStepContent
1035 string _BotGiver;
1036 vector<string> _Actions;
1037 bool _Group;
1039 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1041 numEntry = 0;
1043 public:
1044 void init(CMissionData &md, IPrimitive *prim)
1046 _BotGiver = md.getProperty(prim, "npc_name", true, false);
1047 vector<string> vs;
1048 vs = md.getPropertyArray(prim, "actions", true, false);
1050 for (uint i=0; i<vs.size(); ++i)
1052 if (!vs[i].empty())
1053 _Actions.push_back(vs[i]);
1056 string s;
1057 s = md.getProperty(prim, "group", true, false);
1058 _Group = NLMISC::toBool(s);
1060 IStepContent::init(md, prim);
1063 string genCode(CMissionData &md)
1065 string ret;
1067 if (_Actions.empty())
1068 return ret;
1070 ret = "learn_action : ";
1071 for (uint i=0; i<_Actions.size(); ++i)
1073 ret += _Actions[i];
1074 if (i < _Actions.size()-1)
1075 ret += "; ";
1078 if (!_BotGiver.empty())
1079 ret += " : "+_BotGiver;
1080 if (_Group)
1081 ret += " : group";
1082 ret += NL;
1084 return ret;
1087 REGISTER_STEP_CONTENT(CActionLearnAction, "learn_action");
1089 // ---------------------------------------------------------------------------
1090 class CActionLearnBrick : public IStepContent
1092 string _BotGiver;
1093 vector<string> _Bricks;
1094 bool _Group;
1096 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1098 numEntry = 0;
1100 public:
1101 void init(CMissionData &md, IPrimitive *prim)
1103 _BotGiver = md.getProperty(prim, "npc_name", true, false);
1104 vector<string> vs;
1105 vs = md.getPropertyArray(prim, "bricks", true, false);
1107 for (uint i=0; i<vs.size(); ++i)
1109 if (!vs[i].empty())
1110 _Bricks.push_back(vs[i]);
1113 string s;
1114 s = md.getProperty(prim, "group", true, false);
1115 _Group = NLMISC::toBool(s);
1117 IStepContent::init(md, prim);
1120 string genCode(CMissionData &md)
1122 string ret;
1124 // if (_Bricks.empty())
1125 // return ret;
1127 ret = "learn_brick : ";
1128 for (uint i=0; i<_Bricks.size(); ++i)
1130 ret += _Bricks[i];
1131 if (i < _Bricks.size()-1)
1132 ret += "; ";
1135 if (!_BotGiver.empty())
1136 ret += " : "+_BotGiver;
1137 if (_Group)
1138 ret += " : group";
1139 ret += NL;
1141 return ret;
1144 REGISTER_STEP_CONTENT(CActionLearnBrick, "learn_brick");
1147 // ---------------------------------------------------------------------------
1148 class CActionUnlearnBrick : public IStepContent
1150 string _BotGiver;
1151 vector<string> _Bricks;
1152 bool _Group;
1154 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1156 numEntry = 0;
1158 public:
1159 void init(CMissionData &md, IPrimitive *prim)
1161 _BotGiver = md.getProperty(prim, "npc_name", true, false);
1162 vector<string> vs;
1163 vs = md.getPropertyArray(prim, "bricks", true, false);
1165 for (uint i=0; i<vs.size(); ++i)
1167 if (!vs[i].empty())
1168 _Bricks.push_back(vs[i]);
1171 string s;
1172 s = md.getProperty(prim, "group", true, false);
1173 _Group = NLMISC::toBool(s);
1175 IStepContent::init(md, prim);
1178 string genCode(CMissionData &md)
1180 string ret;
1182 // if (_Bricks.empty())
1183 // return ret;
1185 ret = "unlearn_brick : ";
1186 for (uint i=0; i<_Bricks.size(); ++i)
1188 ret += _Bricks[i];
1189 if (i < _Bricks.size()-1)
1190 ret += "; ";
1193 if (!_BotGiver.empty())
1194 ret += " : "+_BotGiver;
1195 if (_Group)
1196 ret += " : group";
1197 ret += NL;
1199 return ret;
1202 REGISTER_STEP_CONTENT(CActionUnlearnBrick, "unlearn_brick");
1206 // ---------------------------------------------------------------------------
1207 class CActionBotChat : public IStepContent
1209 protected:
1210 string _BotName;
1211 CPhrase _Phrase;
1212 string _ChatMode;
1214 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1216 numEntry = 0;
1218 public:
1219 void init(CMissionData &md, IPrimitive *prim)
1221 IStepContent::init(md, prim);
1223 _BotName = md.getProperty(prim, "npc_name", true, false);
1224 if (_BotName.empty())
1225 throw EParseException(prim, "npc_name is empty !");
1226 vector<string> vs;
1227 vs = md.getPropertyArray(prim, "phrase", false, false);
1228 _Phrase.initPhrase(md, prim, vs);
1230 _ChatMode = md.getProperty(prim, "chat_type", true, false);
1233 string genCode(CMissionData &md)
1235 string ret;
1237 ret = "bot_chat : "+_ChatMode+" : "+_BotName+" : "+_Phrase.genScript(md)+NL;
1238 return ret;
1241 string genPhrase()
1243 return _Phrase.genPhrase();
1246 REGISTER_STEP_CONTENT(CActionBotChat, "bot_chat");
1248 // ---------------------------------------------------------------------------
1249 class CActionBotEmote : public IStepContent
1251 string _BotName;
1252 string _Emote;
1254 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1256 numEntry = 0;
1258 public:
1259 void init(CMissionData &md, IPrimitive *prim)
1261 IStepContent::init(md, prim);
1263 _BotName = md.getProperty(prim, "npc_name", true, false);
1264 _Emote = md.getProperty(prim, "emote", true, false);
1267 string genCode(CMissionData &md)
1269 string ret;
1271 ret = "bot_emot : "+_BotName+" "+_Emote+NL;
1272 return ret;
1275 REGISTER_STEP_CONTENT(CActionBotEmote, "bot_emote");
1277 // ---------------------------------------------------------------------------
1278 class CActionAIEvent : public IStepContent
1280 string _GroupName;
1281 string _EventNumber;
1283 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1285 numEntry = 0;
1287 public:
1288 void init(CMissionData &md, IPrimitive *prim)
1290 IStepContent::init(md, prim);
1292 _GroupName = md.getProperty(prim, "group_name", true, false);
1293 _EventNumber = md.getProperty(prim, "event_number", true, false);
1296 string genCode(CMissionData &md)
1298 string ret;
1300 ret = "ai_event : "+_GroupName+"; "+_EventNumber+NL;
1301 return ret;
1304 REGISTER_STEP_CONTENT(CActionAIEvent, "ai_event");
1306 // ---------------------------------------------------------------------------
1307 class CActionSetTeleport : public CActionBotChat
1309 string _WorldPosition;
1310 bool _Once;
1312 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1314 numEntry = 0;
1316 public:
1317 void init(CMissionData &md, IPrimitive *prim)
1319 CActionBotChat::init(md, prim);
1321 _WorldPosition = md.getProperty(prim, "world_position", true, false);
1322 string s;
1323 prim->getPropertyByName("once", s);
1324 _Once = NLMISC::toBool(s);
1327 string genCode(CMissionData &md)
1329 string ret;
1331 ret = "set_teleport : "+_BotName+" : "+_WorldPosition+" : ";
1333 if (_Once)
1334 ret += "once : ";
1335 ret += _Phrase.genScript(md) + NL;
1336 return ret;
1339 REGISTER_STEP_CONTENT(CActionSetTeleport, "set_teleport");
1341 // ---------------------------------------------------------------------------
1342 class CActionTeleport : public IStepContent
1344 string _WorldPosition;
1346 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1348 numEntry = 0;
1350 public:
1351 void init(CMissionData &md, IPrimitive *prim)
1353 IStepContent::init(md, prim);
1355 _WorldPosition = md.getProperty(prim, "world_position", true, false);
1358 string genCode(CMissionData &md)
1360 string ret;
1362 ret = "teleport : "+_WorldPosition+NL;
1364 return ret;
1367 REGISTER_STEP_CONTENT(CActionTeleport, "teleport");
1369 // ---------------------------------------------------------------------------
1370 class CActionSetCult : public IStepContent
1372 string _Cult;
1374 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1376 numEntry = 0;
1378 public:
1379 void init(CMissionData &md, IPrimitive *prim)
1381 IStepContent::init(md, prim);
1383 _Cult = md.getProperty(prim, "cult", true, false);
1386 string genCode(CMissionData &md)
1388 string ret;
1390 ret = "set_cult : " + _Cult + NL;
1392 return ret;
1395 REGISTER_STEP_CONTENT(CActionSetCult, "set_cult");
1397 // ---------------------------------------------------------------------------
1398 class CActionSetCiv : public IStepContent
1400 string _Civ;
1402 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1404 numEntry = 0;
1406 public:
1407 void init(CMissionData &md, IPrimitive *prim)
1409 IStepContent::init(md, prim);
1411 _Civ = md.getProperty(prim, "civ", true, false);
1414 string genCode(CMissionData &md)
1416 string ret;
1418 ret = "set_civ : " + _Civ + NL;
1420 return ret;
1423 REGISTER_STEP_CONTENT(CActionSetCiv, "set_civ");
1425 // ---------------------------------------------------------------------------
1426 class CActionSetGuildCult : public IStepContent
1428 string _Cult;
1430 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1432 numEntry = 0;
1434 public:
1435 void init(CMissionData &md, IPrimitive *prim)
1437 IStepContent::init(md, prim);
1439 _Cult = md.getProperty(prim, "cult", true, false);
1442 string genCode(CMissionData &md)
1444 string ret;
1446 ret = "set_guild_cult : " + _Cult + NL;
1448 return ret;
1451 REGISTER_STEP_CONTENT(CActionSetGuildCult, "set_guild_cult");
1453 // ---------------------------------------------------------------------------
1454 class CActionSetGuildCiv : public IStepContent
1456 string _Civ;
1458 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1460 numEntry = 0;
1462 public:
1463 void init(CMissionData &md, IPrimitive *prim)
1465 IStepContent::init(md, prim);
1467 _Civ = md.getProperty(prim, "civ", true, false);
1470 string genCode(CMissionData &md)
1472 string ret;
1474 ret = "set_guild_civ : " + _Civ + NL;
1476 return ret;
1479 REGISTER_STEP_CONTENT(CActionSetGuildCiv, "set_guild_civ");
1481 // ---------------------------------------------------------------------------
1482 class CActionAddCompass : public IStepContent
1484 string _NpcName;
1485 string _PlaceName;
1487 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1489 numEntry = 0;
1491 public:
1492 void init(CMissionData &md, IPrimitive *prim)
1494 IStepContent::init(md, prim);
1496 _NpcName = md.getProperty(prim, "npc_to_add", true, false);
1497 _PlaceName = md.getProperty(prim, "place_to_add", true, false);
1500 string genCode(CMissionData &md)
1502 string ret;
1504 if (!_NpcName.empty())
1505 ret = "add_compass_npc : "+_NpcName+NL;
1506 if (!_PlaceName.empty())
1507 ret += "add_compass_place : "+_PlaceName+NL;
1508 return ret;
1511 REGISTER_STEP_CONTENT(CActionAddCompass, "add_compass");
1513 // ---------------------------------------------------------------------------
1514 class CActionRemoveCompass : public IStepContent
1516 string _NpcName;
1517 string _PlaceName;
1519 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1521 numEntry = 0;
1523 public:
1524 void init(CMissionData &md, IPrimitive *prim)
1526 IStepContent::init(md, prim);
1528 _NpcName = md.getProperty(prim, "npc_to_remove", true, false);
1529 _PlaceName = md.getProperty(prim, "place_to_remove", true, false);
1532 string genCode(CMissionData &md)
1534 string ret;
1536 if (!_NpcName.empty())
1537 ret = "remove_compass_npc : "+_NpcName+NL;
1538 if (!_PlaceName.empty())
1539 ret += "remove_compass_place : "+_PlaceName+NL;
1540 return ret;
1543 REGISTER_STEP_CONTENT(CActionRemoveCompass, "remove_compass");
1545 // ---------------------------------------------------------------------------
1546 class CActionFail : public IStepContent
1549 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1551 numEntry = 0;
1553 public:
1554 void init(CMissionData &md, IPrimitive *prim)
1556 IStepContent::init(md, prim);
1559 string genCode(CMissionData &md)
1561 return string("fail")+NL;
1564 REGISTER_STEP_CONTENT(CActionFail, "fail");
1566 // ---------------------------------------------------------------------------
1567 class CActionFailIfSDB : public IStepContent
1570 string _Condition;
1572 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1574 numEntry = 0;
1576 public:
1577 void init(CMissionData &md, IPrimitive *prim)
1579 IStepContent::init(md, prim);
1580 _Condition = md.getProperty(prim, "condition", true, false);
1583 string genCode(CMissionData &md)
1585 return string("fail_if_sdb : ")+_Condition+NL;
1588 REGISTER_STEP_CONTENT(CActionFailIfSDB, "fail_if_sdb");
1590 // ---------------------------------------------------------------------------
1591 class CActionFailMissionCat : public IStepContent
1594 string _MissionCategory;
1596 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1598 numEntry = 0;
1600 public:
1601 void init(CMissionData &md, IPrimitive *prim)
1603 IStepContent::init(md, prim);
1604 _MissionCategory = md.getProperty(prim, "category", true, false);
1607 string genCode(CMissionData &md)
1609 return string("fail_mission_cat : ")+_MissionCategory+NL;
1612 REGISTER_STEP_CONTENT(CActionFailMissionCat, "fail_mission_cat");
1614 // ---------------------------------------------------------------------------
1615 class CActionSystemMsg : public IStepContent
1617 CPhrase _Message;
1619 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1621 numEntry = 0;
1623 public:
1624 void init(CMissionData &md, IPrimitive *prim)
1626 IStepContent::init(md, prim);
1628 vector<string> vs = md.getPropertyArray(prim, "msg_to_display", false, false);
1630 _Message.initPhrase(md, prim, vs);
1633 string genCode(CMissionData &md)
1635 string ret;
1637 ret = "system_msg : "+_Message.genScript(md)+NL;
1638 return ret;
1641 string genPhrase()
1643 return _Message.genPhrase();
1646 REGISTER_STEP_CONTENT(CActionSystemMsg, "system_msg");
1648 // ---------------------------------------------------------------------------
1649 class CActionPopupMsg : public IStepContent
1651 CPhrase _Title;
1652 CPhrase _Message;
1654 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1656 numEntry = 0;
1658 public:
1659 void init(CMissionData &md, IPrimitive *prim)
1661 IStepContent::init(md, prim);
1663 vector<string> vst = md.getPropertyArray(prim, "title_to_display", false, false);
1664 vector<string> vsm = md.getPropertyArray(prim, "msg_to_display", false, false);
1666 _Title.initPhrase(md, prim, vst);
1667 _Message.initPhrase(md, prim, vsm);
1670 string genCode(CMissionData &md)
1672 string ret;
1674 ret = "popup_msg : " + _Title.genScript(md) + " : " + _Message.genScript(md) + NL;
1675 return ret;
1678 string genPhrase()
1680 return _Title.genPhrase() + _Message.genPhrase();
1683 REGISTER_STEP_CONTENT(CActionPopupMsg, "popup_msg");
1685 // ---------------------------------------------------------------------------
1686 class CActionDeclareWar : public IStepContent
1689 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1691 numEntry = 0;
1693 public:
1694 void init(CMissionData &md, IPrimitive *prim)
1696 IStepContent::init(md, prim);
1699 string genCode(CMissionData &md)
1701 return string("declare_war")+NL;
1704 REGISTER_STEP_CONTENT(CActionDeclareWar, "declare_war");
1706 // ---------------------------------------------------------------------------
1707 class CActionSetConstrains : public IStepContent
1709 string _Timer;
1710 string _TimePeriod;
1711 string _InsidePlace;
1712 string _InsidePlaceDelay;
1713 string _OutsidePlace;
1714 string _OutsidePlaceDelay;
1715 vector<string> _Wears;
1717 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1719 numEntry = 0;
1721 public:
1722 void init(CMissionData &md, IPrimitive *prim)
1724 IStepContent::init(md, prim);
1726 _Timer = md.getProperty(prim, "timer", true, false);
1727 _TimePeriod = md.getProperty(prim, "time_period", true, false);
1728 _InsidePlace = md.getProperty(prim, "inside_place", true, false);
1729 _InsidePlaceDelay = md.getProperty(prim, "inside_place_delay", true, false);
1730 _OutsidePlace = md.getProperty(prim, "outside_place", true, false);
1731 _OutsidePlaceDelay = md.getProperty(prim, "outside_place_delay", true, false);
1732 _Wears = md.getPropertyArray(prim, "wear", true, false);
1735 string genCode(CMissionData &md)
1737 string ret;
1739 if (!_Timer.empty())
1740 ret += "timer : "+_Timer+NL;
1741 if (!_TimePeriod.empty())
1743 if ( _TimePeriod == "winter"
1744 || _TimePeriod == "spring"
1745 || _TimePeriod == "summer"
1746 || _TimePeriod == "autumn"
1747 || _TimePeriod == "none")
1749 ret += "season : "+_TimePeriod+NL;
1751 else
1752 ret += "day_period : "+_TimePeriod+NL;
1754 if (!_InsidePlace.empty())
1756 if (_InsidePlace != "none")
1758 ret += "inside : "+_InsidePlace;
1759 if (!_InsidePlaceDelay.empty())
1760 ret += " : "+_InsidePlaceDelay;
1762 else
1763 ret += "inside";
1764 ret += NL;
1766 if (!_OutsidePlace.empty())
1768 if (_OutsidePlace != "none")
1770 ret += "outside : "+_OutsidePlace;
1771 if (!_OutsidePlaceDelay.empty())
1772 ret += " : "+_OutsidePlaceDelay;
1774 else
1775 ret += "outside";
1776 ret += NL;
1778 if (!_Wears.empty())
1779 nlwarning("wear constraint not implemented yet");
1780 return ret;
1783 REGISTER_STEP_CONTENT(CActionSetConstrains, "set_constrains");
1785 // ---------------------------------------------------------------------------
1786 class CActionSetDesc : public IStepContent
1788 CPhrase _Description;
1790 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1792 numEntry = 0;
1794 public:
1795 void init(CMissionData &md, IPrimitive *prim)
1797 IStepContent::init(md, prim);
1799 std::vector<string> vs = md.getPropertyArray(prim, "mission_description", false, false);
1801 _Description.initPhrase(md, prim, vs);
1804 string genCode(CMissionData &md)
1806 string ret;
1808 ret = "set_desc : "+_Description.genScript(md)+NL;
1809 return ret;
1812 string genPhrase()
1814 return _Description.genPhrase();
1818 REGISTER_STEP_CONTENT(CActionSetDesc, "set_desc");
1820 // *****************
1821 // CContentObjective
1822 // *****************
1823 // base class for step content objectives
1824 // ---------------------------------------------------------------------------
1825 void CContentObjective::init(CMissionData &md, IPrimitive *prim)
1827 IStepContent::init(md, prim);
1829 _HideObj = md.getProperty(prim, "hide_obj", true, false) == "true";
1830 _OverloadObj = md.getPropertyArray(prim, "overload_objective", false, false);
1831 _RoleplayObj = md.getPropertyArray(prim, "roleplay_objective", false, false);
1832 uint32 numEntry;
1833 CPhrase::TPredefParams params;
1834 // ask derived class for predefined params
1835 getPredefParam(numEntry, params);
1836 // init the overload phrase
1837 _OverloadPhrase.initPhrase(md, prim, _OverloadObj, numEntry, params);
1838 // init the roleplay phrase
1839 _RoleplayPhrase.initPhrase(md, prim, _RoleplayObj, numEntry, params);
1841 // check for the 'nb_guild_members_needed' option and see if it's correct for this mission
1842 /*string nbGuildMembersNeeded = md.getProperty(prim, "nb_guild_members_needed", false, true);
1843 if (nbGuildMembersNeeded.empty())
1844 nbGuildMembersNeeded = "1";
1845 if (!fromString(nbGuildMembersNeeded.c_str(), _NbGuildMembersNeeded))
1846 _NbGuildMembersNeeded = 1;
1848 // Check:
1849 if (!md.isGuildMission() && _NbGuildMembersNeeded != 1)
1851 string err = toString("primitive(%s): nb_guild_members_needed != 1 for non guild mission.", prim->getName().c_str());
1852 throw EParseException(prim, err.c_str());
1856 // ---------------------------------------------------------------------------
1857 string CContentObjective::genCode(CMissionData &md)
1859 string ret;
1860 if (_HideObj)
1861 ret = "hide_obj"+NL;
1862 if (!_OverloadObj.empty())
1864 ret += "set_obj : " + _OverloadPhrase.genScript(md)+NL;
1866 if (!_RoleplayObj.empty())
1868 ret += "set_obj_rp : " + _RoleplayPhrase.genScript(md)+NL;
1870 return ret;
1873 // ---------------------------------------------------------------------------
1874 /*std::string CContentObjective::genNbGuildMembersNeededOption(CMissionData &md)
1876 string ret;
1877 // If we are in a guild mission we add the 'nb_guild_members_needed' option to the script
1878 if (md.isGuildMission())
1880 ret = ": nb_guild_members_needed ";
1881 ret += toString(_NbGuildMembersNeeded);
1884 return ret;
1887 // ---------------------------------------------------------------------------
1888 string CContentObjective::genPhrase()
1890 if (!_OverloadObj.empty())
1891 return _OverloadPhrase.genPhrase();
1892 else
1893 return _RoleplayPhrase.genPhrase();
1896 // ---------------------------------------------------------------------------
1897 // ---------------------------------------------------------------------------
1899 struct TKillFaunaInfo
1901 TCompilerVarName SheetName;
1902 TCompilerVarName Quantity;
1905 struct TKillRaceInfo
1907 TCompilerVarName RaceName;
1908 TCompilerVarName Quantity;
1911 struct TKillPlayerInfo
1913 TCompilerVarName ClanName;
1914 TCompilerVarName MinLevel;
1915 TCompilerVarName MaxLevel;
1916 TCompilerVarName Quantity;
1919 class CContentKill : public CContentObjective
1921 vector<TKillFaunaInfo> _KillFaunas;
1922 vector<TKillRaceInfo> _KillRaces;
1923 TCompilerVarName _KillGroup;
1924 vector<TCompilerVarName> _KillNpcs;
1925 TCompilerVarName _KillNpcByNames;
1926 TCompilerVarName _KillNpcByNamesQuantity;
1927 TCompilerVarName _KillFactionName;
1928 TCompilerVarName _KillFactionQuantity;
1929 vector<string> _PredefVarName;
1930 vector<TKillPlayerInfo> _KillPlayers;
1931 TCompilerVarName _Place;
1934 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
1936 if (!_KillFaunas.empty())
1938 numEntry = (uint32)_KillFaunas.size();
1939 predef.resize(numEntry);
1940 for (uint i=0; i<_KillFaunas.size(); ++i)
1942 predef[i].resize(2*(i+1));
1943 for (uint j=0; j<i+1; ++j)
1945 predef[i][2*j] = _KillFaunas[j].SheetName;
1946 predef[i][2*j+1] = _KillFaunas[j].Quantity;
1950 else if (!_KillRaces.empty())
1952 numEntry = (uint32)_KillRaces.size();
1953 predef.resize(numEntry);
1954 for (uint i=0; i<_KillRaces.size(); ++i)
1956 predef[i].resize(2*(i+1));
1957 for (uint j=0; j<i+1; ++j)
1959 predef[i][2*j] = _KillRaces[j].RaceName;
1960 predef[i][2*j+1] = _KillRaces[j].Quantity;
1964 else if (!_KillGroup.empty())
1966 numEntry = 0;
1967 predef.resize(1);
1968 predef[0].resize(1);
1969 predef[0][0] = _KillGroup;
1971 else if (!_KillNpcs.empty())
1973 numEntry = (uint32)_KillNpcs.size();
1974 predef.resize(numEntry);
1975 for (uint i=0; i<_KillNpcs.size(); ++i)
1977 predef[i].resize(i+1);
1978 for (uint j=0; j<i+1; ++j)
1980 predef[i][j] = _KillNpcs[j];
1984 else if (!_KillNpcByNames._VarValue.empty())
1986 numEntry = 0;
1987 predef.resize(1);
1988 predef[0].resize(2);
1989 predef[0][0] = _KillNpcByNames;
1990 predef[0][1] =_KillNpcByNamesQuantity;
1992 else if (!_KillFactionName._VarValue.empty())
1994 numEntry = 0;
1995 predef.resize(1);
1996 predef[0].resize(2);
1997 predef[0][0] = _KillFactionName;
1998 predef[0][1] = _KillFactionQuantity;
2000 else if(!_KillPlayers.empty())
2002 numEntry = _KillPlayers.size();
2003 predef.resize(numEntry);
2004 for (uint i=0; i<numEntry; ++i)
2006 predef[i].resize(4*(i+1));
2007 for (uint j=0; j<i+1; ++j)
2009 predef[i][j*4] = _KillPlayers[j].ClanName;
2010 predef[i][j*4+1] = _KillPlayers[j].MinLevel;
2011 predef[i][j*4+2] = _KillPlayers[j].MaxLevel;
2012 predef[i][j*4+3] = _KillPlayers[j].Quantity;
2017 // add optional place
2018 if (!_Place._VarValue.empty())
2020 for (uint i=0; i<predef.size(); ++i)
2022 predef[i].push_back(_Place);
2027 public:
2028 void init(CMissionData &md, IPrimitive *prim)
2030 vector<string> vs;
2031 vs = md.getPropertyArray(prim, "fauna/quantity", false, false);
2032 for (uint i=0; i<vs.size(); ++i)
2034 vector<string> args;
2035 explode(vs[i], string(" "), args, true);
2036 if (args.size() != 2)
2038 string err = toString("Syntax error in kill fauna : '%s', need <fauna_sheet_name> <quantity>", vs[i].c_str());
2039 throw EParseException (prim, err.c_str());
2041 TKillFaunaInfo kfi;
2042 kfi.SheetName.initWithText(toString("c%u", i+1), STRING_MANAGER::creature_model, md, prim, args[0]);
2043 kfi.Quantity.initWithText(toString("q%u", i+1), STRING_MANAGER::integer, md, prim, args[1]);
2044 _KillFaunas.push_back(kfi);
2047 vs = md.getPropertyArray(prim, "race/quantity", false, false);
2048 for (uint i=0; i<vs.size(); ++i)
2050 vector<string> args;
2051 explode(vs[i], string(" "), args, true);
2052 if (args.size() != 2)
2054 string err = toString("Syntax error in kill race : '%s', need <race_name> <quantity>", vs[i].c_str());
2055 throw EParseException (prim, err.c_str());
2057 TKillRaceInfo kri;
2058 kri.RaceName.initWithText(toString("r%u", i+1), STRING_MANAGER::creature_model, md, prim, args[0]);
2059 kri.Quantity.initWithText(toString("q%u", i+1), STRING_MANAGER::integer, md, prim, args[1]);
2060 _KillRaces.push_back(kri);
2062 string s;
2063 //s = md.getProperty(prim, "group", false, true);
2064 vs = md.getPropertyArray(prim, "group", false, false);
2065 if (!vs.empty())
2067 if (vs.size() != 1)
2069 string err = "Syntax error in kill group";
2070 throw EParseException (prim, err.c_str());
2073 _KillGroup.initWithText("group_name", STRING_MANAGER::bot_name, md, prim, vs[0] );
2078 vs = md.getPropertyArray(prim, "npc", false, false);
2079 for (uint i=0; i<vs.size(); ++i)
2081 TCompilerVarName npcname;
2082 npcname.initWithText(toString("npc%u", i+1), STRING_MANAGER::bot, md, prim, vs[i]);
2083 _KillNpcs.push_back(npcname);
2085 vs = md.getPropertyArray(prim, "clan_name/min_level/max_level/quantity", true, false);
2086 for (uint i=0; i<vs.size(); ++i)
2088 vector<string> args;
2089 explode(vs[i], string(" "), args, true);
2090 if (args.size() != 4)
2092 string err = toString("Invalid player clan infos in '%s', need <clan_name> <min_level> <max_level> <quantity>", vs[i].c_str());
2093 throw EParseException(prim, err.c_str());
2095 if (atoi(args[1].c_str()) >= atoi(args[2].c_str()))
2097 string err = toString("Invalid player clan infos in '%s', need <min_level> lower than <max_level>", vs[i].c_str());
2098 throw EParseException(prim, err.c_str());
2100 if (atoi(args[3].c_str()) <= 0)
2102 string err = toString("Invalid player clan infos in '%s', need <quantity> upper than 0", vs[i].c_str());
2103 throw EParseException(prim, err.c_str());
2105 TKillPlayerInfo kp;
2106 kp.ClanName.initWithText(toString("clan%u", i+1), STRING_MANAGER::clan, md, prim, args[0]);
2107 kp.MinLevel.initWithText(toString("minlvl%u", i+1), STRING_MANAGER::integer, md, prim, args[1]);
2108 kp.MaxLevel.initWithText(toString("maxlvl%u", i+1), STRING_MANAGER::integer, md, prim, args[2]);
2109 kp.Quantity.initWithText(toString("quantity%u", i+1), STRING_MANAGER::integer, md, prim, args[3]);
2110 _KillPlayers.push_back(kp);
2113 s = md.getProperty(prim, "npc_by_name/quantity", false, false);
2114 if (!s.empty())
2116 vector<string> args;
2117 explode(s, string(" "), args, true);
2118 if (args.size() != 2)
2120 string err = toString("Syntax error in kill npc by name : '%s', need <npc_name> <quantity>", s.c_str());
2121 throw EParseException(prim, err.c_str());
2123 _KillNpcByNames.initWithText("npc", STRING_MANAGER::bot_name, md, prim, args[0]);
2124 _KillNpcByNamesQuantity.initWithText("qt", STRING_MANAGER::integer, md, prim, args[1]);
2127 s = md.getProperty(prim, "faction/quantity", false, false);
2128 if (!s.empty())
2130 vector<string> args;
2131 explode(s, string(" "), args, true);
2132 if (args.size() != 2)
2134 string err = toString("Syntax error in kill faction : '%s', need <faction_name> <quantity>", s.c_str());
2135 throw EParseException (prim, err.c_str());
2137 _KillFactionName.initWithText("faction", STRING_MANAGER::faction, md, prim, args[0]);
2138 _KillFactionQuantity.initWithText("qt", STRING_MANAGER::integer, md, prim, args[1]);
2141 bool check = false;
2142 if (!_KillFaunas.empty())
2143 check = true;
2144 if (!_KillRaces.empty())
2146 if (check)
2147 throw EParseException(prim, "Merging of multiple kill mode is forbidden !");
2148 check = true;
2150 if (!_KillGroup.empty())
2152 if (check)
2153 throw EParseException(prim, "Merging of multiple kill mode is forbidden !");
2155 check = true;
2157 if (!_KillNpcs.empty())
2159 if (check)
2160 throw EParseException(prim, "Merging of multiple kill mode is forbidden !");
2161 check = true;
2163 if (!_KillNpcByNames._VarValue.empty())
2165 if (check)
2166 throw EParseException(prim, "Merging of multiple kill mode is forbidden !");
2167 check = true;
2169 if (!_KillFactionName.empty())
2171 if (check)
2172 throw EParseException(prim, "Merging of multiple kill mode is forbidden !");
2173 check = true;
2175 if (!_KillPlayers.empty())
2177 if (check)
2178 throw EParseException(prim, "Merging of multiple kill mode is forbidden !");
2179 check = true;
2182 _Place.init("p", STRING_MANAGER::place, md, prim, "place");
2184 if (!_Place.empty() && !_KillGroup.empty())
2186 throw EParseException(prim, "Using location with kill group instruction is forbidden!");
2188 // init base class
2189 CContentObjective::init(md, prim);
2193 string genCode(CMissionData &md)
2195 string ret;
2196 ret = CContentObjective::genCode(md);
2198 if (!_KillFaunas.empty())
2200 ret += "kill_fauna : ";
2201 for (uint i=0; i<_KillFaunas.size(); ++i)
2203 ret += _KillFaunas[i].SheetName+" "+_KillFaunas[i].Quantity;
2204 if (i < _KillFaunas.size()-1)
2205 ret += "; ";
2208 else if (!_KillRaces.empty())
2210 ret += "kill_race : ";
2211 for (uint i=0; i<_KillRaces.size(); ++i)
2213 ret += _KillRaces[i].RaceName+" "+_KillRaces[i].Quantity;
2214 if (i < _KillRaces.size()-1)
2215 ret += "; ";
2218 else if (!_KillGroup.empty())
2220 ret += "kill_group : " + _KillGroup;
2222 else if (!_KillNpcs.empty())
2224 ret += "kill_npc : ";
2225 for (uint i=0; i<_KillNpcs.size(); ++i)
2227 ret += _KillNpcs[i];
2228 if (i < _KillNpcs.size()-1)
2229 ret += "; ";
2232 else if (!_KillNpcByNames.empty())
2234 ret += "kill_npc_by_name : "+_KillNpcByNames+" "+_KillNpcByNamesQuantity;
2236 else if (!_KillFactionName.empty())
2238 ret += "kill_faction : "+_KillFactionName+" "+_KillFactionQuantity;
2240 else if (!_KillPlayers.empty())
2242 ret += "kill_player : ";
2243 for (uint i=0; i<_KillPlayers.size(); ++i)
2245 ret += _KillPlayers[i].ClanName+" "+_KillPlayers[i].MinLevel+" "+_KillPlayers[i].MaxLevel+" "+_KillPlayers[i].Quantity;
2246 if (i < _KillPlayers.size()-1)
2247 {ret += "; ";}
2251 if (!_Place.empty())
2252 ret += " : "+_Place;
2254 // Add the 'nb_guild_members_needed' parameter if needed
2255 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
2256 ret += NL;
2258 return ret;
2261 REGISTER_STEP_CONTENT(CContentKill, "kill");
2265 class CContentKillFamedPlayer : public CContentObjective
2267 vector<TKillFamedPlayerInfo> _Clans;
2269 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
2271 numEntry = _Clans.size();
2272 predef.resize(numEntry);
2273 for (uint i=0; i<numEntry; ++i)
2275 predef[i].resize(4*(i+1));
2276 for (uint j=0; j<i+1; ++j)
2278 predef[i][j*4] = _Clans[j].ClanName;
2279 predef[i][j*4+1] = _Clans[j].MinLevel;
2280 predef[i][j*4+2] = _Clans[j].MaxLevel;
2281 predef[i][j*4+3] = _Clans[j].Quantity;
2287 class CContentTalkTo : public CContentObjective
2289 TCompilerVarName _BotName;
2290 CPhrase _Phrase;
2292 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
2294 numEntry = 0;
2295 predef.resize(1);
2296 predef[0].resize(1);
2297 predef[0][0] = _BotName;
2299 public:
2300 void init(CMissionData &md, IPrimitive *prim)
2304 _BotName.init("npc", STRING_MANAGER::bot, md, prim, "npc_name" );
2306 CPhrase::TPredefParams pp(1);
2307 pp[0].push_back(_BotName.getParamInfo());
2309 vector<string> vs;
2310 vs = md.getPropertyArray(prim, "phrase", false, false);
2311 _Phrase.initPhrase(md, prim, vs, 0, pp);
2313 // _Phrase.initPhrase(md, prim, vs);
2315 // if (_Phrase.asAdditionnalParams())
2316 // {
2317 // // we need to remove the default 'npc' parameter if add params are found
2318 // CPhrase temp;
2319 // temp.initPhrase(md, prim, vs);
2321 // _Phrase = temp;
2322 // }
2323 CContentObjective::init(md, prim);
2326 string genCode(CMissionData &md)
2328 string ret;
2329 ret = CContentObjective::genCode(md);
2331 ret += "talk_to : "+_BotName;
2333 if (!_Phrase.isEmpty())
2334 ret += " : "+_Phrase.genScript(md);
2335 // Add the 'nb_guild_members_needed' parameter if needed
2336 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
2337 ret += NL;
2339 return ret;
2342 string genPhrase()
2344 string ret;
2345 ret = CContentObjective::genPhrase();
2346 ret += _Phrase.genPhrase();
2348 return ret;
2351 REGISTER_STEP_CONTENT(CContentTalkTo, "talk_to");
2353 class CContentCast : public CContentObjective
2355 vector<TCompilerVarName> _Actions;
2356 TCompilerVarName _Place;
2358 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
2361 numEntry = (uint32)_Actions.size();
2362 predef.resize(numEntry);
2363 for (uint i=0; i<numEntry; ++i)
2365 predef[i].resize(i+1);
2367 for (uint j=0; j<i+1; ++j)
2369 predef[i][j] = _Actions[j];
2374 if (!_Place.empty())
2376 for (uint i=0; i<_Actions.size(); ++i)
2378 predef[i].push_back(_Place);
2382 public:
2383 void init(CMissionData &md, IPrimitive *prim)
2385 _Actions=TCompilerVarName::getPropertyArrayWithTextStaticDefaultName("action", STRING_MANAGER::sphrase, md, prim, "action");
2386 _Place.init("p", STRING_MANAGER::place, md, prim, "place");
2390 CContentObjective::init(md, prim);
2393 string genCode(CMissionData &md)
2395 string ret;
2396 ret = CContentObjective::genCode(md);
2398 ret += "cast : ";
2400 for (uint i=0; i<_Actions.size(); ++i)
2402 ret += _Actions[i];
2403 if (i < _Actions.size()-1)
2404 ret += "; ";
2407 if (!_Place.empty())
2409 ret += ": "+_Place;
2411 // Add the 'nb_guild_members_needed' parameter if needed
2412 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
2413 ret += NL;
2415 return ret;
2418 REGISTER_STEP_CONTENT(CContentCast, "cast");
2420 struct TForageInfo
2422 TCompilerVarName Item;
2423 TCompilerVarName Qt;
2424 TCompilerVarName Ql;
2427 class CContentForage : public CContentObjective
2429 vector<TForageInfo> _Mps;
2431 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
2433 numEntry = (uint32)_Mps.size();
2434 predef.resize(numEntry);
2435 for (uint i=0; i<numEntry; ++i)
2437 predef[i].resize(3*(i+1));
2438 for (uint j=0; j<i+1; ++j)
2440 predef[i][j*3] = _Mps[j].Item;
2441 predef[i][j*3+1] = _Mps[j].Qt;
2442 predef[i][j*3+2] = _Mps[j].Ql;
2446 public:
2447 void init(CMissionData &md, IPrimitive *prim)
2449 vector<string> vs;
2450 vs = md.getPropertyArray(prim, "item/quantity/quality", true, false);
2452 for (uint i=0; i<vs.size(); ++i)
2454 vector<string> args;
2455 explode(vs[i], string(" "), args, true);
2456 if (args.size() != 3)
2458 string err = toString("Invalid forage item in '%s', need <item> <quantity> <quality>", vs[i].c_str());
2459 throw EParseException(prim, err.c_str());
2462 TForageInfo fi;
2463 fi.Item.initWithText(toString("i%u", i+1), STRING_MANAGER::item, md, prim, args[0]);
2464 fi.Qt.initWithText(toString("qt%u", i+1), STRING_MANAGER::integer, md, prim, args[1]);
2465 fi.Ql.initWithText(toString("qual%u", i+1), STRING_MANAGER::integer, md, prim, args[2]);
2467 _Mps.push_back(fi);
2470 CContentObjective::init(md, prim);
2473 string genCode(CMissionData &md)
2475 string ret;
2476 ret = CContentObjective::genCode(md);
2478 ret += "forage : ";
2480 for (uint i=0; i<_Mps.size(); ++i)
2482 ret += _Mps[i].Item+" "+_Mps[i].Qt+" "+_Mps[i].Ql;
2483 if (i < _Mps.size()-1)
2484 ret += "; ";
2486 // Add the 'nb_guild_members_needed' parameter if needed
2487 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
2488 ret += NL;
2490 return ret;
2493 REGISTER_STEP_CONTENT(CContentForage, "forage");
2495 struct TLootInfo
2497 TCompilerVarName Item;
2498 TCompilerVarName Qt;
2499 TCompilerVarName Ql;
2502 class CContentLoot : public CContentObjective
2504 enum TLootMode
2506 lm_unknown,
2507 lm_item,
2508 lm_mp
2511 TLootMode _Mode;
2512 vector<TLootInfo> _Items;
2514 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
2516 if (_Mode == lm_item)
2518 numEntry = (uint32)_Items.size();
2519 predef.resize(numEntry);
2520 for (uint i=0; i<numEntry; ++i)
2522 predef[i].resize(i+1);
2523 for (uint j=0; j<i+1; ++j)
2525 predef[i][j] = _Items[j].Item;
2529 else if (_Mode == lm_mp)
2531 numEntry = (uint32)_Items.size();
2532 predef.resize(numEntry);
2533 for (uint i=0; i<numEntry; ++i)
2535 predef[i].resize(3*(i+1));
2536 for (uint j=0; j<i+1; ++j)
2538 predef[i][j*3] = _Items[j].Item;
2539 predef[i][j*3+1] = _Items[j].Qt;
2540 predef[i][j*3+2] = _Items[j].Ql;
2544 else
2545 numEntry = 0;
2549 public:
2550 void init(CMissionData &md, IPrimitive *prim)
2552 _Mode = lm_unknown;
2553 vector<string> vs;
2554 vs = md.getPropertyArray(prim, "item/quantity/quality", true, false);
2556 for (uint i=0; i<vs.size(); ++i)
2558 vector<string> args;
2559 explode(vs[i], string(" "), args, true);
2560 if (args.size() != 1 && args.size() != 3)
2562 string err = toString("Invalid loot item in '%s', need <item> or <item> <quantity> <quality>", vs[i].c_str());
2563 throw EParseException(prim, err.c_str());
2566 if (args.size() == 1)
2568 if (_Mode == lm_mp)
2569 throw EParseException(prim, "Can't mix item and mps loot");
2570 _Mode = lm_item;
2572 else if (args.size() == 3)
2574 if (_Mode == lm_item)
2575 throw EParseException(prim, "Can't mix item and mps loot");
2576 _Mode = lm_mp;
2579 TLootInfo li;
2580 li.Item.initWithText(toString("i%u", i+1), STRING_MANAGER::item, md, prim, args[0]);
2582 if (args.size() > 1)
2584 li.Qt.initWithText(toString("qt%u", i+1), STRING_MANAGER::integer, md, prim, args[1]);
2586 li.Ql.initWithText(toString("qual%u", i+1), STRING_MANAGER::integer, md, prim, args[2]);
2589 _Items.push_back(li);
2592 CContentObjective::init(md, prim);
2595 string genCode(CMissionData &md)
2597 string ret;
2598 ret = CContentObjective::genCode(md);
2600 if (_Mode == lm_item)
2601 ret += "loot_item : ";
2602 else
2603 ret += "loot_mp : ";
2605 for (uint i=0; i<_Items.size(); ++i)
2607 ret += _Items[i].Item;
2608 if (_Mode == lm_mp)
2609 ret += " "+_Items[i].Qt+" "+_Items[i].Ql;
2610 if (i < _Items.size()-1)
2611 ret += "; ";
2613 // Add the 'nb_guild_members_needed' parameter if needed
2614 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
2615 ret += NL;
2617 return ret;
2620 REGISTER_STEP_CONTENT(CContentLoot, "loot");
2622 struct TCraftInfo
2624 TCompilerVarName Item;
2625 TCompilerVarName Qt;
2626 TCompilerVarName Ql;
2629 class CContentCraft : public CContentObjective
2631 vector<TCraftInfo> _Items;
2634 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
2636 numEntry = (uint32)_Items.size();
2637 predef.resize(numEntry);
2638 for (uint i=0; i<numEntry; ++i)
2640 predef[i].resize(3*(i+1));
2641 for (uint j=0; j<i+1; ++j)
2643 predef[i][j*3] = _Items[j].Item;
2644 predef[i][j*3+1] = _Items[j].Qt;
2645 predef[i][j*3+2] = _Items[j].Ql;
2649 public:
2650 void init(CMissionData &md, IPrimitive *prim)
2652 vector<string> vs;
2653 vs = md.getPropertyArray(prim, "item/quantity/quality", true, false);
2655 for (uint i=0; i<vs.size(); ++i)
2657 vector<string> args;
2658 explode(vs[i], string(" "), args, true);
2659 if (args.size() != 3)
2661 string err = toString("Invalid craft item in '%s', need <item> <quantity> <quality>", vs[i].c_str());
2662 throw EParseException(prim, err.c_str());
2665 TCraftInfo ci;
2666 ci.Item.initWithText(toString("i%u", i+1), STRING_MANAGER::item, md, prim, args[0]);
2667 ci.Qt.initWithText(toString("qt%u", i+1), STRING_MANAGER::integer, md, prim, args[1]);
2668 ci.Ql.initWithText(toString("qual%u", i+1), STRING_MANAGER::integer, md, prim, args[2]);
2669 _Items.push_back(ci);
2672 CContentObjective::init(md, prim);
2675 string genCode(CMissionData &md)
2677 string ret;
2678 ret = CContentObjective::genCode(md);
2680 ret += "craft : ";
2682 for (uint i=0; i<_Items.size(); ++i)
2684 ret += _Items[i].Item+" "+_Items[i].Qt+" "+_Items[i].Ql;
2685 if (i < _Items.size()-1)
2686 ret += "; ";
2688 // Add the 'nb_guild_members_needed' parameter if needed
2689 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
2690 ret += NL;
2692 return ret;
2695 REGISTER_STEP_CONTENT(CContentCraft, "craft");
2697 class CContentTarget : public CContentObjective
2700 vector<TCompilerVarName> _Npcs;
2701 vector<TCompilerVarName> _Faunas;
2702 vector<TCompilerVarName> _Races;
2703 TCompilerVarName _Place;
2704 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
2706 // phrase 0 - 1 parameter
2707 // phrase 1 - 2 parameters
2708 // etc ... as many (bots,faunas,race) as specified
2711 if (!_Npcs.empty())
2713 numEntry = (uint32)_Npcs.size();
2714 predef.resize(numEntry);
2715 for (uint i=0; i<numEntry; ++i)
2717 predef[i].resize(1*(i+1));
2718 for (uint j=0; j<i+1; ++j)
2720 predef[i][j] = _Npcs[j];
2724 else if (!_Faunas.empty())
2726 numEntry = (uint32)_Faunas.size();
2727 predef.resize(numEntry);
2728 for (uint i=0; i<numEntry; ++i)
2730 predef[i].resize(1*(i+1));
2731 for (uint j=0; j<i+1; ++j)
2733 predef[i][j] = _Faunas[j];
2737 else if (!_Races.empty())
2739 numEntry = (uint32)_Races.size();
2740 predef.resize(numEntry);
2741 for (uint i=0; i<numEntry; ++i)
2743 predef[i].resize(1*(i+1));
2744 for (uint j=0; j<i+1; ++j)
2746 predef[i][j] = _Races[j];
2751 // If there is a place add the param for text to all phrases (predef[x] is a phrase)
2752 if (!_Place.empty())
2754 for (uint i= 0; i < predef.size(); ++i)
2756 predef[i].push_back( _Place );
2761 public:
2762 void init(CMissionData &md, IPrimitive *prim)
2764 _Npcs = TCompilerVarName::getPropertyArrayWithText("npc", STRING_MANAGER::bot, md, prim, "npcs_to_target");
2765 _Faunas = TCompilerVarName::getPropertyArrayWithText("fauna", STRING_MANAGER::creature_model, md, prim, "faunas_to_target" );
2766 _Races = TCompilerVarName::getPropertyArrayWithText("race", STRING_MANAGER::race, md, prim, "races_to_target" );
2767 _Place.init("place", STRING_MANAGER::place, md, prim, "place" );
2770 if (!_Npcs.empty() && !_Faunas.empty())
2771 throw EParseException(prim, "Can't mix npc and fauna target");
2773 if (!_Npcs.empty() && !_Races.empty())
2774 throw EParseException(prim, "Can't mix npc and race target");
2776 if (!_Faunas.empty() && !_Races.empty())
2777 throw EParseException(prim, "Can't mix fauna and race target");
2779 CContentObjective::init(md, prim);
2782 string genCode(CMissionData &md)
2784 string ret;
2785 ret = CContentObjective::genCode(md);
2787 if (!_Npcs.empty())
2789 ret += "target_npc : ";
2790 for (uint i=0; i<_Npcs.size(); ++i)
2792 ret += _Npcs[i];
2793 if (i < _Npcs.size()-1)
2794 ret += "; ";
2797 else if (!_Faunas.empty())
2799 ret += "target_fauna : ";
2800 for (uint i=0; i<_Faunas.size(); ++i)
2802 ret += _Faunas[i];
2803 if (i < _Faunas.size()-1)
2804 ret += "; ";
2807 else if (!_Races.empty())
2809 ret += "target_race : ";
2810 for (uint i=0; i<_Races.size(); ++i)
2812 ret += _Races[i];
2813 if (i < _Races.size()-1)
2814 ret += "; ";
2818 if (!_Place.empty())
2819 ret += " : " + _Place;
2820 // Add the 'nb_guild_members_needed' parameter if needed
2821 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
2822 ret += NL;
2824 return ret;
2827 REGISTER_STEP_CONTENT(CContentTarget, "target");
2829 struct TSellInfo
2831 TCompilerVarName Item;
2832 TCompilerVarName Qt;
2833 TCompilerVarName Ql;
2836 class CContentSell : public CContentObjective
2838 vector<TSellInfo> _Items;
2839 TCompilerVarName _Npc;
2841 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
2843 numEntry = (uint32)_Items.size();
2844 predef.resize(numEntry);
2845 for (uint i=0; i<numEntry; ++i)
2847 predef[i].resize(3*(i+1));
2848 for (uint j=0; j<i+1; ++j)
2850 predef[i][j*3] = _Items[j].Item;
2851 predef[i][j*3+1] = _Items[j].Qt;
2852 predef[i][j*3+2] = _Items[j].Ql;
2855 if (!_Npc.empty())
2857 predef[i].push_back(_Npc);
2861 public:
2862 void init(CMissionData &md, IPrimitive *prim)
2864 vector<string> vs;
2865 vs = md.getPropertyArray(prim, "item/quantity/quality", true, false);
2867 for (uint i=0; i<vs.size(); ++i)
2869 vector<string> args;
2870 explode(vs[i], string(" "), args, true);
2871 if (args.size() != 3)
2873 string err = toString("Invalid sell item in '%s', need <item> <quantity> <quality>", vs[i].c_str());
2874 throw EParseException(prim, err.c_str());
2877 TSellInfo si;
2878 si.Item.initWithText(toString("i%u", i+1), STRING_MANAGER::item, md, prim, args[0]);
2879 si.Qt.initWithText(toString("qt%u", i+1), STRING_MANAGER::integer, md, prim, args[1]);
2880 si.Ql.initWithText(toString("qual%u", i+1), STRING_MANAGER::integer, md, prim, args[2]);
2881 _Items.push_back(si);
2884 _Npc.init("npc", STRING_MANAGER::bot, md, prim, "npc_name");
2886 CContentObjective::init(md, prim);
2889 string genCode(CMissionData &md)
2891 string ret;
2892 ret = CContentObjective::genCode(md);
2894 ret += "sell : ";
2896 for (uint i=0; i<_Items.size(); ++i)
2898 ret += _Items[i].Item+" "+_Items[i].Qt+" "+_Items[i].Ql;
2899 if (i < _Items.size()-1)
2900 ret += "; ";
2902 if (!_Npc.empty())
2904 ret += " : "+_Npc;
2906 // Add the 'nb_guild_members_needed' parameter if needed
2907 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
2908 ret += NL;
2910 return ret;
2913 REGISTER_STEP_CONTENT(CContentSell, "sell");
2915 struct TBuyInfo
2917 TCompilerVarName Item;
2918 TCompilerVarName Qt;
2919 TCompilerVarName Ql;
2922 class CContentBuy : public CContentObjective
2924 vector<TBuyInfo> _Items;
2925 TCompilerVarName _Npc;
2928 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
2930 numEntry = (uint32)_Items.size();
2931 predef.resize(numEntry);
2932 for (uint i=0; i<numEntry; ++i)
2934 predef[i].resize(3*(i+1));
2935 for (uint j=0; j<i+1; ++j)
2937 predef[i][j*3] = _Items[j].Item;
2938 predef[i][j*3+1] = _Items[j].Qt;
2939 predef[i][j*3+2] = _Items[j].Ql;
2941 predef[i].push_back(_Npc);
2944 public:
2945 void init(CMissionData &md, IPrimitive *prim)
2947 vector<string> vs;
2948 vs = md.getPropertyArray(prim, "item/quantity/quality", true, false);
2950 for (uint i=0; i<vs.size(); ++i)
2952 vector<string> args;
2953 explode(vs[i], string(" "), args, true);
2954 if (args.size() != 3)
2956 string err = toString("Invalid buy item in '%s', need <item> <quantity> <quality>", vs[i].c_str());
2957 throw EParseException(prim, err.c_str());
2960 TBuyInfo bi;
2961 bi.Item.initWithText(toString("i%u", i+1), STRING_MANAGER::item, md, prim, args[0]);
2962 bi.Qt.initWithText(toString("qt%u", i+1), STRING_MANAGER::integer, md, prim, args[1]);
2963 bi.Ql.initWithText(toString("qual%u", i+1), STRING_MANAGER::integer, md, prim, args[2]);
2964 _Items.push_back(bi);
2967 _Npc.init("npc", STRING_MANAGER::bot, md, prim, "npc_name");
2969 CContentObjective::init(md, prim);
2972 string genCode(CMissionData &md)
2974 string ret;
2975 ret = CContentObjective::genCode(md);
2977 ret += "buy : ";
2979 for (uint i=0; i<_Items.size(); ++i)
2981 ret += _Items[i].Item+" "+_Items[i].Qt+" "+_Items[i].Ql;
2982 if (i < _Items.size()-1)
2983 ret += "; ";
2985 if (!_Npc.empty())
2987 ret += " : "+_Npc;
2989 // Add the 'nb_guild_members_needed' parameter if needed
2990 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
2991 ret += NL;
2993 return ret;
2997 REGISTER_STEP_CONTENT(CContentBuy, "buy");
2999 struct TGiveInfo
3001 TCompilerVarName Item;
3002 TCompilerVarName Qt;
3003 TCompilerVarName Ql;
3006 class CContentGive : public CContentObjective
3008 vector<TGiveInfo> _Items;
3009 TCompilerVarName _Npc;
3010 bool _QualSpec;
3012 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
3014 numEntry = (uint32)_Items.size();
3015 predef.resize(numEntry);
3016 for (uint i=0; i<numEntry; ++i)
3018 if (_QualSpec)
3020 predef[i].resize(3*(i+1));
3021 for (uint j=0; j<i+1; ++j)
3023 predef[i][j*3] = _Items[j].Item;
3024 predef[i][j*3+1] = _Items[j].Qt;
3025 predef[i][j*3+2] = _Items[j].Ql;
3028 else
3030 predef[i].resize(2*(i+1));
3031 for (uint j=0; j<i+1; ++j)
3033 predef[i][j*2] = _Items[j].Item;
3034 predef[i][j*2+1] = _Items[j].Qt;
3038 predef[i].push_back(_Npc);
3042 public:
3043 void init(CMissionData &md, IPrimitive *prim)
3045 vector<string> vs;
3046 vs = md.getPropertyArray(prim, "item/quantity/quality", true, false);
3048 for (uint i=0; i<vs.size(); ++i)
3050 vector<string> args;
3051 explode(vs[i], string(" "), args, true);
3052 if (args.size() != 3 && args.size() != 2)
3054 string err = toString("Invalid give item in '%s', need <item> <quantity> [<quality>]", vs[i].c_str());
3055 throw EParseException(prim, err.c_str());
3058 if (i == 0)
3060 _QualSpec = args.size() == 3;
3062 else
3064 if (_QualSpec && args.size() == 2)
3066 string err = toString("Invalid give item in '%s', mixing of item with quality and item without quality is not supported", vs[i].c_str());
3067 throw EParseException(prim, err.c_str());
3071 TGiveInfo gi;
3072 gi.Item.initWithText(toString("i%u", i+1), STRING_MANAGER::item, md, prim, args[0]);
3073 gi.Qt.initWithText(toString("qt%u", i+1), STRING_MANAGER::integer, md, prim, args[1]);
3075 if (_QualSpec)
3076 gi.Ql.initWithText(toString("qual%u", i+1), STRING_MANAGER::integer, md, prim, args[2]);
3078 _Items.push_back(gi);
3081 _Npc.init("npc", STRING_MANAGER::bot, md, prim, "npc_name");
3083 CContentObjective::init(md, prim);
3086 string genCode(CMissionData &md)
3088 string ret;
3089 ret = CContentObjective::genCode(md);
3091 ret += "give_item : ";
3093 for (uint i=0; i<_Items.size(); ++i)
3095 ret += _Items[i].Item+" "+_Items[i].Qt;
3096 if (_QualSpec)
3097 ret += " "+_Items[i].Ql;
3098 if (i < _Items.size()-1)
3099 ret += "; ";
3101 ret += " : "+_Npc;
3102 // Add the 'nb_guild_members_needed' parameter if needed
3103 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
3104 ret += NL;
3106 return ret;
3109 REGISTER_STEP_CONTENT(CContentGive, "give_item");
3111 class CContentGiveMoney : public CContentObjective
3113 TCompilerVarName _Amount;
3114 TCompilerVarName _Npc;
3116 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
3118 numEntry = 0;
3119 predef.resize(1);
3120 predef[0].resize(2);
3122 predef[0][0] = _Amount;
3123 predef[0][1] = _Npc;
3126 public:
3127 void init(CMissionData &md, IPrimitive *prim)
3129 _Amount.init("amount", STRING_MANAGER::integer, md, prim, "amount");
3130 _Npc.init("npc", STRING_MANAGER::bot, md, prim, "npc_name");
3131 CContentObjective::init(md, prim);
3134 string genCode(CMissionData &md)
3136 string ret;
3137 ret = CContentObjective::genCode(md);
3139 ret += "give_money : "+_Amount+" : "+_Npc;
3140 // Add the 'nb_guild_members_needed' parameter if needed
3141 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
3142 ret += NL;
3144 return ret;
3147 REGISTER_STEP_CONTENT(CContentGiveMoney, "give_money");
3149 class CContentVisit : public CContentObjective
3151 TCompilerVarName _Place;
3152 TCompilerVarName _PlaceVar;
3153 vector<TCompilerVarName> _Items;
3155 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
3157 numEntry = 0;
3158 predef.resize(1);
3159 predef[0].resize(1+_Items.size());
3160 predef[0][0] = _Place;
3162 for (uint i=0; i<_Items.size(); ++i)
3163 predef[0][i+1] = _Items[i];
3166 public:
3167 void init(CMissionData &md, IPrimitive *prim)
3170 _Place.init("place", STRING_MANAGER::place, md, prim, "place");
3171 _Items = TCompilerVarName::getPropertyArrayWithText("i", STRING_MANAGER::item, md, prim, "items_worn" );
3173 CContentObjective::init(md, prim);
3176 string genCode(CMissionData &md)
3178 string ret;
3179 ret = CContentObjective::genCode(md);
3181 ret += "visit : "+_Place;
3183 if (!_Items.empty())
3185 ret += " : ";
3186 for (uint i=0; i<_Items.size(); ++i)
3188 ret += _Items[i];
3189 if (i < _Items.size()-1)
3190 ret += "; ";
3193 // Add the 'nb_guild_members_needed' parameter if needed
3194 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
3195 ret += NL;
3197 return ret;
3200 REGISTER_STEP_CONTENT(CContentVisit, "visit");
3202 class CContentEscort : public CContentObjective
3204 string _GroupName;
3205 bool _SaveAll;
3207 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
3209 numEntry = 0;
3211 public:
3212 void init (CMissionData &md, IPrimitive *prim)
3214 _GroupName = md.getProperty(prim, "group_to_escort", true, false);
3215 string s = md.getProperty(prim, "save_all", true, false);
3216 _SaveAll = NLMISC::toBool(s);
3218 CContentObjective::init(md, prim);
3221 string genCode(CMissionData &md)
3223 string ret;
3224 ret = CContentObjective::genCode(md);
3226 ret += "escort : "+_GroupName;
3228 if (_SaveAll)
3229 ret += " : save_all";
3230 // Add the 'nb_guild_members_needed' parameter if needed
3231 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
3232 ret += NL;
3234 return ret;
3237 REGISTER_STEP_CONTENT(CContentEscort, "escort");
3239 struct TSkillInfo
3241 TCompilerVarName _SkillName;
3242 TCompilerVarName _Level;
3245 class CContentSkill: public CContentObjective
3247 vector<TSkillInfo> _Skills;
3249 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
3251 numEntry = (uint32)_Skills.size();
3252 predef.resize(numEntry);
3254 for (uint i=0; i<numEntry; ++i)
3256 predef[i].resize(2*(i+1));
3257 for (uint j=0; j<i+1; ++j)
3259 predef[i][j*2] = _Skills[j]._SkillName;
3260 predef[i][j*2+1] = _Skills[j]._Level;
3265 public:
3266 void init(CMissionData &md, IPrimitive *prim)
3268 vector<string> vs;
3269 vs = md.getPropertyArray(prim, "skill_name/level", true, false);
3271 for (uint i=0; i<vs.size(); ++i)
3273 vector<string> args;
3274 explode(vs[i], string(" "), args, true);
3276 if (args.size() != 2)
3278 string err = toString("Invalid skill in '%s', need <skill_name> <skill_level>", vs[i].c_str());
3279 throw EParseException(prim, err.c_str());
3282 TSkillInfo si;
3283 si._SkillName.initWithText(toString("s%u", i+1), STRING_MANAGER::skill, md, prim, args[0]);
3284 si._Level.initWithText(toString("level%u", i+1), STRING_MANAGER::integer, md, prim, args[1]);
3285 _Skills.push_back(si);
3288 CContentObjective::init(md, prim);
3291 string genCode(CMissionData &md)
3293 string ret;
3294 ret = CContentObjective::genCode(md);
3296 ret += "skill : ";
3298 for (uint i=0; i<_Skills.size(); ++i)
3300 ret += _Skills[i]._SkillName+" "+_Skills[i]._Level;
3301 if (i < _Skills.size()-1)
3302 ret += "; ";
3304 // Add the 'nb_guild_members_needed' parameter if needed
3305 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
3306 ret += NL;
3308 return ret;
3311 REGISTER_STEP_CONTENT(CContentSkill, "skill");
3313 class CContentMission: public CContentObjective
3315 vector<string> _Missions;
3317 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
3319 numEntry = 0;
3322 public:
3323 CContentMission(): _Prim(0) {}
3325 void init(CMissionData &md, IPrimitive *prim)
3327 _Missions = md.getPropertyArray(prim, "mission_names", true, false);
3328 _Prim = prim;
3330 CContentObjective::init(md, prim);
3333 string genCode(CMissionData &md)
3335 string ret;
3336 ret = CContentObjective::genCode(md);
3338 ret += "mission : ";
3340 for (uint i=0; i<_Missions.size(); ++i)
3342 ret += _Missions[i];
3343 if (i < _Missions.size()-1)
3344 ret += "; ";
3346 // We check to see if we specified a number after the mission name. If so, we check if it's a guild mission
3347 std::size_t pos = _Missions[i].find_first_of(" \t");
3348 if (pos != std::string::npos && !md.isGuildMission())
3350 string err = toString("primitive(%s): CContentMission: Number of members needed to complete the mission specified but the mission is not a guild mission.", _Prim->getName().c_str());
3351 throw EParseException(_Prim, err.c_str());
3354 // Add the 'nb_guild_members_needed' parameter if needed
3355 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
3356 ret += NL;
3358 return ret;
3361 IPrimitive *_Prim;
3363 REGISTER_STEP_CONTENT(CContentMission, "do_mission");
3365 class CContentWaitAIMsg : public CContentObjective
3367 vector<string> _MsgContent;
3369 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
3371 numEntry = 0;
3374 public:
3375 void init(CMissionData &md, IPrimitive *prim)
3377 _MsgContent = md.getPropertyArray(prim, "msg_content", true, false);
3379 CContentObjective::init(md, prim);
3382 string genCode(CMissionData &md)
3384 string ret;
3385 ret = CContentObjective::genCode(md);
3387 ret += "wait_msg : ";
3389 for (uint i=0; i<_MsgContent.size(); ++i)
3391 ret += _MsgContent[i];
3392 if (i < _MsgContent.size()-1)
3393 ret += " ";
3395 // Add the 'nb_guild_members_needed' parameter if needed
3396 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
3397 ret += NL;
3399 return ret;
3402 REGISTER_STEP_CONTENT(CContentWaitAIMsg, "wait_ai_msg");
3404 // ***********
3405 // queue_start
3406 // ***********
3408 class CContentQueueStart : public CContentObjective
3410 string _StepName;
3411 string _QueueName;
3412 string _Timer;
3413 vector<string> _AIInstances;
3414 vector<string> _GroupsToSpawn;
3416 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
3418 numEntry = 0;
3421 public:
3422 void init(CMissionData &md, IPrimitive *prim)
3424 _StepName = md.getProperty(prim, "step_name", true, true);
3425 _QueueName = md.getProperty(prim, "queue_name", true, false);
3426 if (_StepName.empty())
3427 _StepName = "queue_start_" + _QueueName;
3429 _Timer = md.getProperty(prim, "timer", true, false);
3430 _GroupsToSpawn = md.getPropertyArray(prim, "groups_to_spawn", true, true);
3431 if (_GroupsToSpawn.empty())
3432 _AIInstances = md.getPropertyArray(prim, "ai_instances", true, true);
3433 else
3434 _AIInstances = md.getPropertyArray(prim, "ai_instances", true, false);
3436 CContentObjective::init(md, prim);
3439 string genCode(CMissionData &md)
3441 uint32 i;
3442 string ret;
3443 ret = CContentObjective::genCode(md);
3445 ret += "jump_point : " + _StepName + NL;
3446 ret += "queue_start : " + _QueueName + " : " + _Timer + NL;
3447 ret += NL;
3449 if (!_GroupsToSpawn.empty())
3451 // crash : ai_instance_1 : ai_instance_2 : ...
3452 ret += "crash";
3453 nlassert(!_AIInstances.empty());
3454 for (i = 0; i < _AIInstances.size(); ++i)
3455 ret += " : " + _AIInstances[i];
3456 ret += NL;
3458 for (i = 0; i < _GroupsToSpawn.size(); ++i)
3459 ret += "handle_release : " + _GroupsToSpawn[i] + NL;
3461 ret += "/crash" + NL;
3462 ret += NL;
3464 ret += "failure" + NL;
3465 for (i = 0; i < _GroupsToSpawn.size(); ++i)
3466 ret += "handle_release : " + _GroupsToSpawn[i] + NL;
3467 ret += "/failure" + NL;
3468 ret += NL;
3471 ret += "player_reconnect" + NL;
3472 for (i = 0; i < _GroupsToSpawn.size(); ++i)
3473 ret += "handle_release : " + _GroupsToSpawn[i] + NL;
3474 ret += "jump : " + _StepName + NL;
3475 ret += "/player_reconnect" + NL;
3476 ret += NL;
3478 for (i = 0; i < _GroupsToSpawn.size(); ++i)
3479 ret += "handle_create : " + _GroupsToSpawn[i] + NL;
3481 return ret;
3484 REGISTER_STEP_CONTENT(CContentQueueStart, "queue_start");
3486 // *********
3487 // queue_end
3488 // *********
3490 class CActionQueueEnd : public IStepContent
3492 string _ActionName;
3493 string _QueueName;
3494 // Find the following info in the queue_start node
3495 vector<string> _AIInstances;
3496 vector<string> _GroupsToSpawn;
3498 void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
3500 numEntry = 0;
3502 public:
3503 void init(CMissionData &md, IPrimitive *prim)
3505 IStepContent::init(md, prim);
3506 _ActionName = md.getProperty(prim, "action_name", true, true);
3507 _QueueName = md.getProperty(prim, "queue_name", true, false);
3508 if (_ActionName.empty())
3509 _ActionName = "queue_end_" + _QueueName;
3511 // Search in the queue_start node
3512 IPrimitive *primParent = prim;
3513 while (primParent->getParent() != NULL)
3515 string className;
3516 if (primParent->getPropertyByName("class", className))
3517 if (className == "mission_tree")
3518 break;
3519 primParent = primParent->getParent();
3521 TPrimitiveClassPredicate condClass("queue_start");
3522 CPrimitiveSet<TPrimitiveClassPredicate> s;
3523 TPrimitiveSet ps;
3524 s.buildSet(primParent, condClass, ps);
3526 TPrimitivePropertyPredicate condProp("queue_name", _QueueName);
3527 CPrimitiveSetFilter<TPrimitivePropertyPredicate> filter;
3528 TPrimitiveSet psFinal;
3529 filter.filterSet(ps, condProp, psFinal);
3531 if (psFinal.size() == 0)
3533 string err = toString("Can't find queue_start for queue_end : '%s'", _QueueName.c_str());
3534 throw EParseException(prim, err.c_str());
3536 if (psFinal.size() > 1)
3538 string err = toString("More than 1 queue_start for queue_end : '%s'", _QueueName.c_str());
3539 throw EParseException(prim, err.c_str());
3542 _GroupsToSpawn = md.getPropertyArray(psFinal[0], "groups_to_spawn", true, true);
3543 if (_GroupsToSpawn.empty())
3544 _AIInstances = md.getPropertyArray(psFinal[0], "ai_instances", true, true);
3545 else
3546 _AIInstances = md.getPropertyArray(psFinal[0], "ai_instances", true, false);
3550 string genCode(CMissionData &md)
3552 uint32 i;
3553 string ret;
3555 if (!_GroupsToSpawn.empty())
3557 for (i = 0; i < _GroupsToSpawn.size(); ++i)
3558 ret += "handle_release : " + _GroupsToSpawn[i] + NL;
3559 ret += NL;
3562 if (!_AIInstances.empty())
3564 ret += "crash";
3565 for (i = 0; i < _AIInstances.size(); ++i)
3566 ret += " : " + _AIInstances[i];
3567 ret += NL;
3568 ret += "/crash" + NL;
3569 ret += NL;
3572 ret += "failure" + NL;
3573 ret += "/failure" + NL;
3574 ret += NL;
3576 ret += "player_reconnect" + NL;
3577 ret += "/player_reconnect" + NL;
3578 ret += NL;
3579 ret += "queue_end : " +_QueueName + NL;
3581 return ret;
3585 REGISTER_STEP_CONTENT(CActionQueueEnd, "queue_end");
3588 class CContentRingScenario: public CContentObjective
3590 string _ScenarioTag;
3592 virtual void getPredefParam(uint32 &numEntry, CPhrase::TPredefParams &predef)
3594 numEntry = 0;
3597 public:
3598 void init(CMissionData &md, IPrimitive *prim)
3600 _ScenarioTag = md.getProperty(prim, "scenario_tag", true, false);
3602 CContentObjective::init(md, prim);
3605 string genCode(CMissionData &md)
3607 string ret;
3608 ret = CContentObjective::genCode(md);
3610 ret += "ring_scenario : ";
3611 ret += _ScenarioTag;
3612 // Add the 'nb_guild_members_needed' parameter if needed
3613 //ret += CContentObjective::genNbGuildMembersNeededOption(md);
3614 ret += NL;
3616 return ret;
3619 REGISTER_STEP_CONTENT(CContentRingScenario, "ring_scenario");