1 // Copyright (C) 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
2 // Copyright (C) 2003 Michael Bartl
3 // Copyright (C) 2007, 2008 Ben Asselstine
4 // Copyright (C) 2008 Ole Laursen
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Library General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <sigc++/functors/mem_fun.h>
33 #include "QKillHero.h"
34 #include "QEnemyArmies.h"
35 #include "QEnemyArmytype.h"
36 #include "QCitySack.h"
37 #include "QCityRaze.h"
38 #include "QCityOccupy.h"
39 #include "QPillageGold.h"
40 #include "armysetlist.h"
41 #include "playerlist.h"
43 #include "armyprodbase.h"
44 #include "heroproto.h"
47 std::string Action::d_tag = "action";
50 #define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<< x << endl<<flush;}
53 Action::Action(Type type)
58 Action::Action(const Action &action)
59 :d_type(action.d_type)
63 Action::Action(XML_Helper *helper)
66 helper->getData(type_str, "type");
67 d_type = actionTypeFromString(type_str);
74 bool Action::save(XML_Helper* helper) const
78 retval &= helper->openTag(Action::d_tag);
79 retval &= saveContents(helper);
80 retval &= helper->closeTag();
85 bool Action::saveContents(XML_Helper* helper) const
89 std::string type_str = actionTypeToString(Action::Type(d_type));
90 retval &= helper->saveData("type", type_str);
91 retval &= doSave(helper);
96 Action* Action::handle_load(XML_Helper* helper)
100 helper->getData(type_str, "type");
101 Action::Type t = actionTypeFromString(type_str);
106 return (new Action_Move(helper));
108 return (new Action_Split(helper));
110 return (new Action_Fight(helper));
112 return(new Action_Join(helper));
114 return (new Action_Ruin(helper));
116 return (new Action_Temple(helper));
118 return (new Action_Occupy(helper));
120 return (new Action_Pillage(helper));
122 return (new Action_Sack(helper));
124 return (new Action_Raze(helper));
126 return (new Action_Upgrade(helper));
128 return (new Action_Buy(helper));
130 return (new Action_Production(helper));
132 return (new Action_Reward(helper));
134 return (new Action_Quest(helper));
136 return (new Action_Equip(helper));
138 return (new Action_Level(helper));
140 return (new Action_Disband(helper));
141 case MODIFY_SIGNPOST:
142 return (new Action_ModifySignpost(helper));
144 return (new Action_RenameCity(helper));
146 return (new Action_Vector(helper));
148 return (new Action_FightOrder(helper));
150 return (new Action_Resign(helper));
152 return (new Action_Plant(helper));
154 return (new Action_Produce(helper));
155 case PRODUCE_VECTORED_UNIT:
156 return (new Action_ProduceVectored(helper));
157 case DIPLOMATIC_STATE:
158 return (new Action_DiplomacyState(helper));
159 case DIPLOMATIC_PROPOSAL:
160 return (new Action_DiplomacyProposal(helper));
161 case DIPLOMATIC_SCORE:
162 return (new Action_DiplomacyScore(helper));
164 return (new Action_EndTurn(helper));
166 return (new Action_ConquerCity(helper));
168 return (new Action_RecruitHero(helper));
170 return (new Action_RenamePlayer(helper));
172 return (new Action_CityTooPoorToProduce(helper));
174 return (new Action_InitTurn(helper));
176 return (new Action_Loot(helper));
183 Action* Action::copy(const Action* a)
188 return (new Action_Move(*dynamic_cast<const Action_Move*>(a)));
190 return (new Action_Split(*dynamic_cast<const Action_Split*>(a)));
192 return (new Action_Fight(*dynamic_cast<const Action_Fight*>(a)));
194 return(new Action_Join(*dynamic_cast<const Action_Join*>(a)));
196 return (new Action_Ruin(*dynamic_cast<const Action_Ruin*>(a)));
198 return (new Action_Temple(*dynamic_cast<const Action_Temple*>(a)));
200 return (new Action_Occupy(*dynamic_cast<const Action_Occupy*>(a)));
202 return (new Action_Pillage(*dynamic_cast<const Action_Pillage*>(a)));
204 return (new Action_Sack(*dynamic_cast<const Action_Sack*>(a)));
206 return (new Action_Raze(*dynamic_cast<const Action_Raze*>(a)));
208 return (new Action_Upgrade(*dynamic_cast<const Action_Upgrade*>(a)));
210 return (new Action_Buy(*dynamic_cast<const Action_Buy*>(a)));
212 return (new Action_Production(*dynamic_cast<const Action_Production*>(a)));
214 return (new Action_Reward(*dynamic_cast<const Action_Reward*>(a)));
216 return (new Action_Quest(*dynamic_cast<const Action_Quest*>(a)));
218 return (new Action_Equip(*dynamic_cast<const Action_Equip*>(a)));
220 return (new Action_Level(*dynamic_cast<const Action_Level*>(a)));
222 return (new Action_Disband(*dynamic_cast<const Action_Disband*>(a)));
223 case MODIFY_SIGNPOST:
224 return (new Action_ModifySignpost(*dynamic_cast<const Action_ModifySignpost*>(a)));
226 return (new Action_RenameCity(*dynamic_cast<const Action_RenameCity*>(a)));
228 return (new Action_Vector(*dynamic_cast<const Action_Vector*>(a)));
230 return (new Action_FightOrder(*dynamic_cast<const Action_FightOrder*>(a)));
232 return (new Action_Resign(*dynamic_cast<const Action_Resign*>(a)));
234 return (new Action_Plant(*dynamic_cast<const Action_Plant*>(a)));
236 return (new Action_Produce(*dynamic_cast<const Action_Produce*>(a)));
237 case PRODUCE_VECTORED_UNIT:
239 (new Action_ProduceVectored
240 (*dynamic_cast<const Action_ProduceVectored*>(a)));
241 case DIPLOMATIC_STATE:
243 (new Action_DiplomacyState
244 (*dynamic_cast<const Action_DiplomacyState*>(a)));
245 case DIPLOMATIC_PROPOSAL:
247 (new Action_DiplomacyProposal
248 (*dynamic_cast<const Action_DiplomacyProposal*>(a)));
249 case DIPLOMATIC_SCORE:
251 (new Action_DiplomacyScore
252 (*dynamic_cast<const Action_DiplomacyScore*>(a)));
256 (*dynamic_cast<const Action_EndTurn*>(a)));
259 (new Action_ConquerCity
260 (*dynamic_cast<const Action_ConquerCity*>(a)));
263 (new Action_RecruitHero
264 (*dynamic_cast<const Action_RecruitHero*>(a)));
267 (new Action_RenamePlayer
268 (*dynamic_cast<const Action_RenamePlayer*>(a)));
271 (new Action_CityTooPoorToProduce
272 (*dynamic_cast<const Action_CityTooPoorToProduce*>(a)));
276 (*dynamic_cast<const Action_InitTurn*>(a)));
280 (*dynamic_cast<const Action_Loot*>(a)));
286 //-----------------------------------------------------------------------------
289 Action_Move::Action_Move()
290 :Action(Action::STACK_MOVE), d_stack(0)
292 d_dest.x = d_dest.y = 0;
293 d_delta.x = d_delta.y = 0;
296 Action_Move::Action_Move (const Action_Move &action)
297 :Action(action), d_stack(action.d_stack), d_dest(action.d_dest),
298 d_delta(action.d_delta)
302 Action_Move::Action_Move(XML_Helper* helper)
305 helper->getData(d_stack, "stack");
308 helper->getData(i, "x");
310 helper->getData(i, "y");
312 helper->getData(i, "delta_x");
314 helper->getData(i, "delta_y");
318 Action_Move::~Action_Move()
322 std::string Action_Move::dump() const
326 s <<"Stack " <<d_stack <<" moved to (";
327 s <<d_dest.x <<"," <<d_dest.y <<")\n";
332 bool Action_Move::doSave(XML_Helper* helper) const
336 retval &= helper->saveData("stack", d_stack);
337 retval &= helper->saveData("x", d_dest.x);
338 retval &= helper->saveData("y", d_dest.y);
339 retval &= helper->saveData("delta_x", d_delta.x);
340 retval &= helper->saveData("delta_y", d_delta.y);
345 bool Action_Move::fillData(Stack* s, Vector<int> dest)
347 d_stack = s->getId();
349 d_delta = dest - s->getPos();
353 //-----------------------------------------------------------------------------
356 Action_Split::Action_Split()
357 :Action(Action::STACK_SPLIT), d_orig(0), d_added(0)
359 for (unsigned int i = 0; i < MAX_STACK_SIZE; i++)
360 d_armies_moved[i] = 0;
363 Action_Split::Action_Split(const Action_Split &action)
364 : Action(action), d_orig(action.d_orig),
365 d_added(action.d_added)
367 for (unsigned int i = 0; i < MAX_STACK_SIZE; i++)
368 d_armies_moved[i] = action.d_armies_moved[i];
371 Action_Split::Action_Split(XML_Helper* helper)
374 helper->getData(d_orig, "orig_stack");
375 helper->getData(d_added, "new_stack");
378 std::istringstream si;
380 helper->getData(s, "moved");
382 for (unsigned int i = 0; i < MAX_STACK_SIZE; i++)
383 si >>d_armies_moved[i];
386 Action_Split::~Action_Split()
390 std::string Action_Split::dump() const
394 s <<"Stack " <<d_orig<<" splitted with new stack ";
397 s <<"moved armies: ";
398 for (unsigned int i = 0; i < MAX_STACK_SIZE; i++)
399 s <<d_armies_moved[i] <<" ";
405 bool Action_Split::doSave(XML_Helper* helper) const
410 for (unsigned int i = 0; i < MAX_STACK_SIZE - 1; i++)
411 s <<d_armies_moved[i] <<" ";
412 s <<d_armies_moved[MAX_STACK_SIZE - 1];
414 retval &= helper->saveData("orig_stack", d_orig);
415 retval &= helper->saveData("new_stack", d_added);
416 retval &= helper->saveData("moved", s.str());
421 bool Action_Split::fillData(Stack* orig, Stack* added)
423 if (orig->validate() == false || added->validate() == false)
425 std::cerr <<"Action_Split::fillData(): stacks don't validate\n";
426 std::cerr <<"Action_Split:: orig has " << orig->size() <<
427 " and added has " <<added->size();
431 debug("Action_Split::fillData()")
433 d_orig = orig->getId();
434 d_added = added->getId();
436 Stack::iterator it = added->begin();
437 for (int i = 0; it != added->end(); it++, i++)
438 d_armies_moved[i] = (*it)->getId();
444 //-----------------------------------------------------------------------------
447 Action_Fight::Action_Fight()
448 :Action(Action::STACK_FIGHT)
452 Action_Fight::Action_Fight(const Action_Fight &action)
453 : Action(action), d_history(action.d_history), d_attackers(action.d_attackers),
454 d_defenders(action.d_defenders)
458 Action_Fight::Action_Fight(XML_Helper* helper)
462 std::istringstream si;
465 helper->registerTag(Item::d_tag, sigc::mem_fun(this, &Action_Fight::loadItem));
467 // get attacking and defending stacks
468 helper->getData(s, "attackers");
471 d_attackers.push_back(ui);
474 helper->getData(s, "defenders");
477 d_defenders.push_back(ui);
480 Action_Fight::~Action_Fight()
484 std::string Action_Fight::dump() const
487 std::list<guint32>::const_iterator uit;
489 s << "Battle fought.\n Attacking stacks: ";
490 for (uit = d_attackers.begin(); uit != d_attackers.end(); uit++)
493 s << "\n Defending stacks: ";
494 for (uit = d_defenders.begin(); uit != d_defenders.end(); uit++)
500 bool Action_Fight::doSave(XML_Helper* helper) const
502 std::stringstream si;
503 std::list<guint32>::const_iterator uit;
507 // save the stack's ids
508 for (uit = d_attackers.begin(); uit != d_attackers.end(); uit++)
510 retval &= helper->saveData("attackers", si.str());
512 for (uit = d_defenders.begin(), si.str(""); uit != d_defenders.end(); uit++)
514 retval &= helper->saveData("defenders", si.str());
516 // save what happened
517 for (std::list<FightItem>::const_iterator fit = d_history.begin();
518 fit != d_history.end(); fit++)
520 retval &= helper->openTag(Item::d_tag);
521 retval &= helper->saveData("turn", (*fit).turn);
522 retval &= helper->saveData("id", (*fit).id);
523 retval &= helper->saveData("damage", (*fit).damage);
524 retval &= helper->closeTag();
530 bool Action_Fight::fillData(const Fight* f)
532 std::list<Stack*> list = f->getAttackers();
533 std::list<Stack*>::const_iterator it;
535 for (it = list.begin(); it != list.end(); it++)
536 d_attackers.push_back((*it)->getId());
538 list = f->getDefenders();
540 for (it = list.begin(); it != list.end(); it++)
541 d_defenders.push_back((*it)->getId());
543 d_history = f->getCourseOfEvents();
548 bool Action_Fight::loadItem(std::string tag, XML_Helper* helper)
552 helper->getData(item.turn, "turn");
553 helper->getData(item.id, "id");
554 helper->getData(item.damage, "damage");
556 d_history.push_back(item);
561 //-----------------------------------------------------------------------------
564 Action_Join::Action_Join()
565 :Action(Action::STACK_JOIN), d_orig_id(0), d_joining_id(0)
569 Action_Join::Action_Join(const Action_Join &action)
570 : Action(action), d_orig_id(action.d_orig_id), d_joining_id(action.d_joining_id)
574 Action_Join::Action_Join(XML_Helper* helper)
577 helper->getData(d_orig_id, "receiver");
578 helper->getData(d_joining_id, "joining");
581 Action_Join::~Action_Join()
585 std::string Action_Join::dump() const
589 s <<"Stack " <<d_joining_id <<" joined stack " <<d_orig_id <<"\n";
594 bool Action_Join::doSave(XML_Helper* helper) const
598 retval &= helper->saveData("receiver", d_orig_id);
599 retval &= helper->saveData("joining", d_joining_id);
604 bool Action_Join::fillData(Stack* orig, Stack* joining)
606 if ((orig->empty()) || (joining->empty())
607 || (orig->size() + joining->size() > MAX_STACK_SIZE))
609 std::cerr <<"Action_Join::fillData(): wrong stack size\n";
610 std::cerr <<"Action_Join:: orig has " << orig->size() <<
611 " and joining has " <<joining->size() <<"\n";
615 debug("Action_Join::fillData")
617 d_orig_id = orig->getId();
618 d_joining_id = joining->getId();
622 //-----------------------------------------------------------------------------
625 Action_Ruin::Action_Ruin()
626 :Action(Action::RUIN_SEARCH), d_ruin(0), d_stack(0), d_searched(false)
630 Action_Ruin::Action_Ruin(const Action_Ruin&action)
631 : Action(action), d_ruin(action.d_ruin), d_stack(action.d_stack),
632 d_searched(action.d_searched)
636 Action_Ruin::Action_Ruin(XML_Helper* helper)
639 helper->getData(d_ruin, "ruin");
640 helper->getData(d_stack, "seeker");
641 helper->getData(d_searched, "searched");
644 Action_Ruin::~Action_Ruin()
648 std::string Action_Ruin::dump() const
652 s <<"Ruin " <<d_ruin <<" searched by stack " <<d_stack <<". ";
653 s <<"Ruin has" <<(d_searched? " ":" not ") <<"been searched.\n";
658 bool Action_Ruin::doSave(XML_Helper* helper) const
662 retval &= helper->saveData("ruin", d_ruin);
663 retval &= helper->saveData("seeker", d_stack);
664 retval &= helper->saveData("searched", d_searched);
669 bool Action_Ruin::fillData(Ruin* r, Stack* explorers)
674 d_stack = explorers->getId();
679 //-----------------------------------------------------------------------------
682 Action_Temple::Action_Temple()
683 :Action(Action::TEMPLE_SEARCH), d_temple(0), d_stack(0)
687 Action_Temple::Action_Temple(const Action_Temple &action)
688 : Action(action), d_temple(action.d_temple), d_stack(action.d_stack)
692 Action_Temple::Action_Temple(XML_Helper* helper)
695 helper->getData(d_temple, "temple");
696 helper->getData(d_stack, "stack");
699 Action_Temple::~Action_Temple()
703 std::string Action_Temple::dump() const
707 s <<"Stack " <<d_stack <<" visited temple " <<d_temple <<".\n";
712 bool Action_Temple::doSave(XML_Helper* helper) const
716 retval &= helper->saveData("temple", d_temple);
717 retval &= helper->saveData("stack", d_stack);
722 bool Action_Temple::fillData(Temple* t, Stack* s)
724 d_temple = t->getId();
725 d_stack = s->getId();
731 //-----------------------------------------------------------------------------
734 Action_Occupy::Action_Occupy()
735 :Action(Action::CITY_OCCUPY), d_city(0)
739 Action_Occupy::Action_Occupy(const Action_Occupy &action)
740 : Action(action), d_city(action.d_city)
744 Action_Occupy::Action_Occupy(XML_Helper* helper)
747 helper->getData(d_city, "city");
750 Action_Occupy::~Action_Occupy()
754 std::string Action_Occupy::dump() const
758 s <<"City " <<d_city <<" occupied\n";
763 bool Action_Occupy::doSave(XML_Helper* helper) const
767 retval &= helper->saveData("city", d_city);
772 bool Action_Occupy::fillData(City* c)
778 //-----------------------------------------------------------------------------
781 Action_Pillage::Action_Pillage()
782 :Action(Action::CITY_PILLAGE), d_city(0)
786 Action_Pillage::Action_Pillage(const Action_Pillage &action)
787 : Action(action), d_city(action.d_city)
791 Action_Pillage::Action_Pillage(XML_Helper* helper)
794 helper->getData(d_city, "city");
797 Action_Pillage::~Action_Pillage()
801 std::string Action_Pillage::dump() const
804 s <<"city " <<d_city <<"pillaged.\n";
808 bool Action_Pillage::doSave(XML_Helper* helper) const
812 retval &= helper->saveData("city", d_city);
817 bool Action_Pillage::fillData(City* c)
823 //-----------------------------------------------------------------------------
826 Action_Sack::Action_Sack()
827 :Action(Action::CITY_SACK), d_city(0)
831 Action_Sack::Action_Sack(const Action_Sack &action)
832 : Action(action), d_city(action.d_city)
836 Action_Sack::Action_Sack(XML_Helper* helper)
839 helper->getData(d_city, "city");
842 Action_Sack::~Action_Sack()
846 std::string Action_Sack::dump() const
849 s <<"city " <<d_city <<"sacked.\n";
853 bool Action_Sack::doSave(XML_Helper* helper) const
857 retval &= helper->saveData("city", d_city);
862 bool Action_Sack::fillData(City* c)
868 //-----------------------------------------------------------------------------
871 Action_Raze::Action_Raze()
872 :Action(Action::CITY_RAZE), d_city(0)
876 Action_Raze::Action_Raze(const Action_Raze &action)
877 : Action(action), d_city(action.d_city)
881 Action_Raze::Action_Raze(XML_Helper* helper)
884 helper->getData(d_city, "city");
887 Action_Raze::~Action_Raze()
891 std::string Action_Raze::dump() const
895 s <<"City " <<d_city <<" razed.\n";
900 bool Action_Raze::doSave(XML_Helper* helper) const
904 retval &= helper->saveData("city", d_city);
909 bool Action_Raze::fillData(City* c)
915 //-----------------------------------------------------------------------------
918 Action_Upgrade::Action_Upgrade()
919 :Action(Action::CITY_UPGRADE), d_city(0)
923 Action_Upgrade::Action_Upgrade(const Action_Upgrade &action)
924 : Action(action), d_city(action.d_city)
928 Action_Upgrade::Action_Upgrade(XML_Helper* helper)
931 helper->getData(d_city, "city");
934 Action_Upgrade::~Action_Upgrade()
938 std::string Action_Upgrade::dump() const
942 s <<"Defense of city " <<d_city <<" upgraded.\n";
947 bool Action_Upgrade::doSave(XML_Helper* helper) const
951 retval &= helper->saveData("city", d_city);
956 bool Action_Upgrade::fillData(City* c)
962 //-----------------------------------------------------------------------------
965 Action_Buy::Action_Buy()
966 :Action(Action::CITY_BUY), d_city(0), d_slot(-1), d_prod(-1)
970 Action_Buy::Action_Buy(const Action_Buy &action)
971 : Action(action), d_city(action.d_city), d_slot(action.d_slot),
972 d_prod(action.d_prod)
976 Action_Buy::Action_Buy(XML_Helper* helper)
979 helper->getData(d_city, "city");
980 helper->getData(d_slot, "slot");
981 helper->getData(d_prod, "production");
984 Action_Buy::~Action_Buy()
988 std::string Action_Buy::dump() const
992 s <<"Production " <<d_prod <<" bought in city " <<d_city;
993 s <<" slot: " <<d_slot << "\n";
998 bool Action_Buy::doSave(XML_Helper* helper) const
1002 retval &= helper->saveData("city", d_city);
1003 retval &= helper->saveData("slot", d_slot);
1004 retval &= helper->saveData("production", d_prod);
1009 bool Action_Buy::fillData(City* c, int slot, const ArmyProto *prod)
1011 d_city = c->getId();
1013 d_prod = prod->getTypeId();
1018 //-----------------------------------------------------------------------------
1019 //Action_Change_Production
1021 Action_Production::Action_Production()
1022 :Action(Action::CITY_PROD), d_city(0), d_prod(0)
1026 Action_Production::Action_Production (const Action_Production &action)
1027 : Action(action), d_city(action.d_city), d_prod(action.d_prod)
1031 Action_Production::Action_Production(XML_Helper* helper)
1034 helper->getData(d_city, "city");
1035 helper->getData(d_prod, "production");
1038 Action_Production::~Action_Production()
1042 std::string Action_Production::dump() const
1044 std::stringstream s;
1046 s <<"Production in city " <<d_city <<" changed to " <<d_prod;
1052 bool Action_Production::doSave(XML_Helper* helper) const
1056 retval &= helper->saveData("city", d_city);
1057 retval &= helper->saveData("production", d_prod);
1062 bool Action_Production::fillData(City* c, int slot)
1064 d_city = c->getId();
1070 //-----------------------------------------------------------------------------
1073 Action_Reward::Action_Reward()
1074 :Action(Action::REWARD)
1078 bool Action_Reward::load(std::string tag, XML_Helper *helper)
1080 if (tag == Reward::d_tag)
1083 std::string type_str;
1084 helper->getData(type_str, "type");
1085 t = Reward::rewardTypeFromString(type_str);
1089 d_reward = new Reward_Gold(helper); break;
1090 case Reward::ALLIES:
1091 d_reward = new Reward_Allies(helper); break;
1093 d_reward = new Reward_Item(helper); break;
1095 d_reward = new Reward_Ruin(helper); break;
1097 d_reward = new Reward_Map(helper); break;
1104 Action_Reward::Action_Reward (const Action_Reward &action)
1105 : Action(action), d_stack(action.d_stack)
1107 const Reward *reward = action.d_reward;
1108 d_reward = Reward::copy(reward);
1111 Action_Reward::Action_Reward(XML_Helper* helper)
1114 helper->getData(d_stack, "stack");
1115 helper->registerTag(Reward::d_tag, sigc::mem_fun(this, &Action_Reward::load));
1118 Action_Reward::~Action_Reward()
1122 bool Action_Reward::fillData(Stack *s, Reward* r)
1124 d_stack = s->getId();
1129 std::string Action_Reward::dump() const
1131 std::stringstream s;
1134 s <<"Got a reward of " <<d_reward->getType() <<"\n";
1139 bool Action_Reward::doSave(XML_Helper* helper) const
1143 retval &= helper->saveData("stack", d_stack);
1144 if (d_reward->getType() == Reward::GOLD)
1145 retval &= dynamic_cast<Reward_Gold*>(d_reward)->save(helper);
1146 else if (d_reward->getType() == Reward::ALLIES)
1147 retval &= dynamic_cast<Reward_Allies*>(d_reward)->save(helper);
1148 else if (d_reward->getType() == Reward::ITEM)
1149 retval &= dynamic_cast<Reward_Item*>(d_reward)->save(helper);
1150 else if (d_reward->getType() == Reward::RUIN)
1151 retval &= dynamic_cast<Reward_Ruin*>(d_reward)->save(helper);
1152 else if (d_reward->getType() == Reward::MAP)
1153 retval &= dynamic_cast<Reward_Map*>(d_reward)->save(helper);
1158 //-----------------------------------------------------------------------------
1161 Action_Quest::Action_Quest()
1162 :Action(Action::QUEST), d_hero(0), d_data(0), d_victim_player(0)
1166 Action_Quest::Action_Quest (const Action_Quest &action)
1167 : Action(action), d_hero(action.d_hero), d_questtype(action.d_questtype),
1168 d_data(action.d_data), d_victim_player(action.d_victim_player)
1172 Action_Quest::Action_Quest(XML_Helper* helper)
1176 helper->getData(d_hero, "hero");
1178 helper->getData(s, "quest");
1179 d_questtype = Quest::questTypeFromString(s);
1180 helper->getData(d_data, "data");
1181 helper->getData(d_victim_player, "victim_player");
1184 Action_Quest::~Action_Quest()
1188 std::string Action_Quest::dump() const
1190 std::stringstream ss;
1192 ss <<"Hero " <<d_hero <<"has got quest of type " <<d_questtype;
1193 ss <<" with data " <<d_data <<" to fulfill\n";
1198 bool Action_Quest::doSave(XML_Helper* helper) const
1202 retval &= helper->saveData("hero", d_hero);
1203 std::string s = Quest::questTypeToString(Quest::Type(d_questtype));
1204 retval &= helper->saveData("quest", s);
1205 retval &= helper->saveData("data", d_data);
1206 retval &= helper->saveData("victim_player", d_victim_player);
1211 bool Action_Quest::fillData(Quest* q)
1213 d_hero = q->getHeroId();
1214 d_questtype = q->getType();
1216 // fill the data depending on the quest's type
1217 switch (d_questtype)
1219 case Quest::KILLHERO:
1220 d_data = dynamic_cast<QuestKillHero*>(q)->getVictim();
1222 case Quest::KILLARMIES:
1223 d_data = dynamic_cast<QuestEnemyArmies*>(q)->getArmiesToKill();
1224 d_victim_player = dynamic_cast<QuestEnemyArmies*>(q)->getVictimPlayerId();
1226 case Quest::CITYSACK:
1227 d_data = dynamic_cast<QuestCitySack*>(q)->getCityId();
1229 case Quest::CITYRAZE:
1230 d_data = dynamic_cast<QuestCityRaze*>(q)->getCityId();
1232 case Quest::CITYOCCUPY:
1233 d_data = dynamic_cast<QuestCityOccupy*>(q)->getCityId();
1235 case Quest::KILLARMYTYPE:
1236 d_data = dynamic_cast<QuestEnemyArmytype*>(q)->getArmytypeToKill();
1238 case Quest::PILLAGEGOLD:
1239 d_data = dynamic_cast<QuestPillageGold*>(q)->getGoldToPillage();
1246 //-----------------------------------------------------------------------------
1249 Action_Equip::Action_Equip()
1250 :Action(Action::HERO_EQUIP), d_hero(0), d_item(0), d_pos(Vector<int>(-1,-1))
1254 Action_Equip::Action_Equip (const Action_Equip &action)
1255 : Action(action), d_hero(action.d_hero), d_item(action.d_item),
1256 d_slot(action.d_slot), d_pos(action.d_pos)
1260 Action_Equip::Action_Equip(XML_Helper* helper)
1263 helper->getData(d_hero, "hero");
1264 helper->getData(d_item, "item");
1265 helper->getData(d_slot, "dest");
1267 helper->getData(i, "x");
1269 helper->getData(i, "y");
1273 Action_Equip::~Action_Equip()
1277 std::string Action_Equip::dump() const
1279 std::stringstream ss;
1281 ss <<"Hero " <<d_hero <<" moved item " <<d_item <<" to slot " <<d_slot;
1282 ss <<" at tile " << d_pos.x << "," << d_pos.y;
1288 bool Action_Equip::doSave(XML_Helper* helper) const
1292 retval &= helper->saveData("hero", d_hero);
1293 retval &= helper->saveData("item", d_item);
1294 retval &= helper->saveData("dest", d_slot);
1296 retval &= helper->saveData("x", i);
1298 retval &= helper->saveData("y", i);
1303 bool Action_Equip::fillData(Hero *hero, Item *item, Action_Equip::Slot slot,
1306 d_hero = hero->getId();
1307 d_item = item->getId();
1314 //-----------------------------------------------------------------------------
1317 Action_Level::Action_Level()
1318 :Action(Action::UNIT_ADVANCE), d_army(0)
1322 Action_Level::Action_Level (const Action_Level &action)
1323 : Action(action), d_army(action.d_army), d_stat(action.d_stat)
1327 Action_Level::Action_Level(XML_Helper* helper)
1330 helper->getData(d_army, "army");
1331 helper->getData(d_stat, "stat");
1334 Action_Level::~Action_Level()
1338 std::string Action_Level::dump() const
1340 std::stringstream ss;
1342 ss <<"Unit " <<d_army <<" advanced level and increased stat " <<d_stat;
1348 bool Action_Level::doSave(XML_Helper* helper) const
1352 retval &= helper->saveData("army", d_army);
1353 retval &= helper->saveData("stat", d_stat);
1358 bool Action_Level::fillData(Army *unit, Army::Stat raised)
1360 d_army = unit->getId();
1366 //-----------------------------------------------------------------------------
1369 Action_Disband::Action_Disband()
1370 :Action(Action::STACK_DISBAND), d_stack(0)
1374 Action_Disband::Action_Disband(const Action_Disband &action)
1375 : Action(action), d_stack(action.d_stack)
1379 Action_Disband::Action_Disband(XML_Helper* helper)
1382 helper->getData(d_stack, "stack");
1385 Action_Disband::~Action_Disband()
1389 std::string Action_Disband::dump() const
1391 std::stringstream s;
1393 s <<"Stack " <<d_stack <<" disbanded\n";
1398 bool Action_Disband::doSave(XML_Helper* helper) const
1402 retval &= helper->saveData("stack", d_stack);
1407 bool Action_Disband::fillData(Stack* s)
1409 d_stack = s->getId();
1413 //-----------------------------------------------------------------------------
1414 //Action_ModifySignpost
1416 Action_ModifySignpost::Action_ModifySignpost()
1417 :Action(Action::MODIFY_SIGNPOST), d_signpost(0), d_message("")
1421 Action_ModifySignpost::Action_ModifySignpost(const Action_ModifySignpost &action)
1422 : Action(action), d_signpost(action.d_signpost), d_message(action.d_message)
1426 Action_ModifySignpost::Action_ModifySignpost(XML_Helper* helper)
1429 helper->getData(d_signpost, "signpost");
1430 helper->getData(d_message, "message");
1433 Action_ModifySignpost::~Action_ModifySignpost()
1437 std::string Action_ModifySignpost::dump() const
1439 std::stringstream s;
1441 s <<"Signpost " <<d_signpost <<" modified to read" << d_message <<".\n";
1446 bool Action_ModifySignpost::doSave(XML_Helper* helper) const
1450 retval &= helper->saveData("signpost", d_signpost);
1451 retval &= helper->saveData("message", d_message);
1456 bool Action_ModifySignpost::fillData(Signpost * s, std::string message)
1458 d_signpost = s->getId();
1459 d_message = message;
1463 //-----------------------------------------------------------------------------
1466 Action_RenameCity::Action_RenameCity()
1467 :Action(Action::CITY_RENAME), d_city(0), d_name("")
1471 Action_RenameCity::Action_RenameCity(const Action_RenameCity &action)
1472 : Action(action), d_city(action.d_city), d_name(action.d_name)
1476 Action_RenameCity::Action_RenameCity(XML_Helper* helper)
1479 helper->getData(d_city, "city");
1480 helper->getData(d_name, "name");
1483 Action_RenameCity::~Action_RenameCity()
1487 std::string Action_RenameCity::dump() const
1489 std::stringstream s;
1491 s <<"City " <<d_city <<" renamed to " << d_name<<".\n";
1496 bool Action_RenameCity::doSave(XML_Helper* helper) const
1500 retval &= helper->saveData("city", d_city);
1501 retval &= helper->saveData("name", d_name);
1506 bool Action_RenameCity::fillData(City* c, std::string name)
1508 d_city = c->getId();
1513 //-----------------------------------------------------------------------------
1516 Action_Vector::Action_Vector()
1517 :Action(Action::CITY_VECTOR)
1521 Action_Vector::Action_Vector(const Action_Vector &action)
1522 : Action(action), d_city(action.d_city), d_dest(action.d_dest)
1526 Action_Vector::Action_Vector(XML_Helper* helper)
1529 helper->getData(d_city, "city");
1531 helper->getData(i, "x");
1533 helper->getData(i, "y");
1537 Action_Vector::~Action_Vector()
1541 std::string Action_Vector::dump() const
1543 std::stringstream s;
1545 s <<"Vectoring new units from city " <<d_city <<" to ";
1546 s <<d_dest.x <<"," <<d_dest.y <<")\n";
1551 bool Action_Vector::doSave(XML_Helper* helper) const
1555 retval &= helper->saveData("city", d_city);
1556 retval &= helper->saveData("x", d_dest.x);
1557 retval &= helper->saveData("y", d_dest.y);
1562 bool Action_Vector::fillData(City* src, Vector <int> dest)
1564 d_city = src->getId();
1569 //-----------------------------------------------------------------------------
1572 Action_FightOrder::Action_FightOrder()
1573 :Action(Action::FIGHT_ORDER)
1577 Action_FightOrder::Action_FightOrder(const Action_FightOrder &action)
1578 : Action(action), d_order(action.d_order)
1582 Action_FightOrder::Action_FightOrder(XML_Helper* helper)
1585 std::string fight_order;
1586 std::stringstream sfight_order;
1588 helper->getData(fight_order, "order");
1589 sfight_order.str(fight_order);
1590 guint32 size = Armysetlist::getInstance()->getSize(Playerlist::getInstance()->getFirstLiving()->getArmyset());
1591 for (unsigned int i = 0; i < size; i++)
1593 sfight_order >> val;
1594 d_order.push_back(val);
1598 Action_FightOrder::~Action_FightOrder()
1602 std::string Action_FightOrder::dump() const
1604 std::stringstream s;
1606 s <<"changed fight order to:" ;
1607 std::list<guint32>::const_iterator it = d_order.begin();
1608 for ( ;it != d_order.end(); it++)
1617 bool Action_FightOrder::doSave(XML_Helper* helper) const
1621 std::stringstream fight_order;
1622 for (std::list<guint32>::const_iterator it = d_order.begin();
1623 it != d_order.end(); it++)
1625 fight_order << (*it) << " ";
1627 retval &= helper->saveData("order", fight_order.str());
1632 bool Action_FightOrder::fillData(std::list<guint32> order)
1638 //-----------------------------------------------------------------------------
1641 Action_Resign::Action_Resign()
1642 :Action(Action::RESIGN)
1646 Action_Resign::Action_Resign(const Action_Resign &action)
1651 Action_Resign::Action_Resign(XML_Helper* helper)
1656 Action_Resign::~Action_Resign()
1660 std::string Action_Resign::dump() const
1662 std::stringstream s;
1663 s << "this player resigns\n";
1668 bool Action_Resign::doSave(XML_Helper* helper) const
1675 bool Action_Resign::fillData()
1680 //-----------------------------------------------------------------------------
1683 Action_Plant::Action_Plant()
1684 :Action(Action::ITEM_PLANT)
1688 Action_Plant::Action_Plant(const Action_Plant &action)
1689 : Action(action), d_hero(action.d_hero), d_item(action.d_item)
1693 Action_Plant::Action_Plant(XML_Helper* helper)
1696 helper->getData(d_hero, "hero");
1697 helper->getData(d_item, "item");
1700 Action_Plant::~Action_Plant()
1704 std::string Action_Plant::dump() const
1706 std::stringstream s;
1707 s << "hero " << d_hero << " plants item " << d_item;
1712 bool Action_Plant::doSave(XML_Helper* helper) const
1716 retval &= helper->saveData("hero", d_hero);
1717 retval &= helper->saveData("item", d_item);
1722 bool Action_Plant::fillData(Hero *hero, Item *item)
1724 d_hero = hero->getId();
1725 d_item = item->getId();
1729 //-----------------------------------------------------------------------------
1732 Action_Produce::Action_Produce()
1733 :Action(Action::PRODUCE_UNIT)
1737 Action_Produce::Action_Produce(const Action_Produce &action)
1738 : Action(action), d_city(action.d_city), d_vectored(action.d_vectored),
1739 d_dest(action.d_dest), d_army_id(action.d_army_id)
1741 d_army = new ArmyProdBase (*action.d_army);
1744 Action_Produce::Action_Produce(XML_Helper* helper)
1747 helper->getData(d_city, "city");
1748 helper->getData(d_vectored, "vectored");
1749 helper->getData(d_dest.x, "dest_x");
1750 helper->getData(d_dest.y, "dest_y");
1751 helper->getData(d_army_id, "army_id");
1752 helper->registerTag(ArmyProdBase::d_tag, sigc::mem_fun(this, &Action_Produce::load));
1755 bool Action_Produce::load(std::string tag, XML_Helper *helper)
1757 if (tag == ArmyProdBase::d_tag)
1759 d_army = new ArmyProdBase(helper);
1766 Action_Produce::~Action_Produce()
1772 std::string Action_Produce::dump() const
1774 std::stringstream s;
1775 s << "army id " << d_army_id << " of type " << d_army->getTypeId() << " shows up at city " << d_city;
1777 s <<" but it is vectored to another city at " << d_dest.x << "," << d_dest.y;
1779 s <<" at position " << d_dest.x << "," << d_dest.y;
1785 bool Action_Produce::doSave(XML_Helper* helper) const
1789 retval &= helper->saveData("city", d_city);
1790 retval &= helper->saveData("vectored", d_vectored);
1791 retval &= helper->saveData("dest_x", d_dest.x);
1792 retval &= helper->saveData("dest_y", d_dest.y);
1793 retval &= helper->saveData("army_id", d_army_id);
1794 retval &= d_army->save(helper);
1799 bool Action_Produce::fillData(const ArmyProdBase *army, City *city, bool vectored, Vector<int> pos, guint32 army_id)
1801 d_army = new ArmyProdBase(*army);
1802 d_city = city->getId();
1803 d_vectored = vectored;
1805 d_army_id = army_id;
1809 //-----------------------------------------------------------------------------
1810 //Action_ProduceVectored
1812 Action_ProduceVectored::Action_ProduceVectored()
1813 :Action(Action::PRODUCE_VECTORED_UNIT)
1816 d_dest = Vector<int>(-1,-1);
1817 d_src = Vector<int>(-1,-1);
1820 Action_ProduceVectored::Action_ProduceVectored(const Action_ProduceVectored &action)
1821 : Action(action), d_dest(action.d_dest), d_src(action.d_src)
1824 d_army = new ArmyProdBase(*action.d_army);
1829 Action_ProduceVectored::Action_ProduceVectored(XML_Helper* helper)
1830 :Action(helper), d_army(NULL)
1833 helper->getData(i, "dest_x");
1835 helper->getData(i, "dest_y");
1837 helper->getData(i, "src_x");
1839 helper->getData(i, "src_y");
1841 helper->registerTag(ArmyProdBase::d_tag, sigc::mem_fun(this, &Action_ProduceVectored::load));
1844 bool Action_ProduceVectored::load(std::string tag, XML_Helper *helper)
1846 if (tag == ArmyProdBase::d_tag)
1848 d_army = new ArmyProdBase(helper);
1855 Action_ProduceVectored::~Action_ProduceVectored()
1861 std::string Action_ProduceVectored::dump() const
1863 std::stringstream s;
1864 s << "vectored army of type " << d_army->getTypeId() << " shows up at ";
1865 s <<d_dest.x <<"," <<d_dest.y << " from " << d_src.x << "," << d_src.y;
1871 bool Action_ProduceVectored::doSave(XML_Helper* helper) const
1875 retval &= helper->saveData("dest_x", d_dest.x);
1876 retval &= helper->saveData("dest_y", d_dest.y);
1877 retval &= helper->saveData("src_x", d_src.x);
1878 retval &= helper->saveData("src_y", d_src.y);
1879 retval &= d_army->save(helper);
1884 bool Action_ProduceVectored::fillData(ArmyProdBase *army, Vector<int> dest,
1888 d_army = new ArmyProdBase (*army);
1894 //-----------------------------------------------------------------------------
1895 //Action_DiplomacyState
1897 Action_DiplomacyState::Action_DiplomacyState()
1898 :Action(Action::DIPLOMATIC_STATE)
1902 Action_DiplomacyState::Action_DiplomacyState(const Action_DiplomacyState &action)
1903 : Action(action), d_opponent_id(action.d_opponent_id),
1904 d_diplomatic_state(action.d_diplomatic_state)
1908 Action_DiplomacyState::Action_DiplomacyState(XML_Helper* helper)
1911 guint32 diplomatic_state;
1912 helper->getData(d_opponent_id, "opponent_id");
1913 helper->getData(diplomatic_state, "state");
1914 d_diplomatic_state = Player::DiplomaticState(diplomatic_state);
1917 Action_DiplomacyState::~Action_DiplomacyState()
1921 std::string Action_DiplomacyState::dump() const
1923 std::stringstream s;
1925 switch (d_diplomatic_state)
1927 case Player::AT_WAR: s <<"war"; break;
1928 case Player::AT_WAR_IN_FIELD: s <<"war in the field"; break;
1929 case Player::AT_PEACE: s <<"peace"; break;
1931 s << " with player " << d_opponent_id <<".\n";
1936 bool Action_DiplomacyState::doSave(XML_Helper* helper) const
1940 retval &= helper->saveData("opponent_id", d_opponent_id);
1941 retval &= helper->saveData("state", (guint32)d_diplomatic_state);
1946 bool Action_DiplomacyState::fillData(Player *opponent,
1947 Player::DiplomaticState state)
1949 d_opponent_id = opponent->getId();
1950 d_diplomatic_state = state;
1954 //-----------------------------------------------------------------------------
1955 //Action_DiplomacyProposal
1957 Action_DiplomacyProposal::Action_DiplomacyProposal()
1958 :Action(Action::DIPLOMATIC_PROPOSAL)
1962 Action_DiplomacyProposal::Action_DiplomacyProposal(const Action_DiplomacyProposal &action)
1963 : Action(action), d_opponent_id(action.d_opponent_id),
1964 d_diplomatic_proposal(action.d_diplomatic_proposal)
1968 Action_DiplomacyProposal::Action_DiplomacyProposal(XML_Helper* helper)
1971 guint32 diplomatic_proposal;
1972 helper->getData(d_opponent_id, "opponent_id");
1973 helper->getData(diplomatic_proposal, "proposal");
1974 d_diplomatic_proposal = Player::DiplomaticProposal(diplomatic_proposal);
1977 Action_DiplomacyProposal::~Action_DiplomacyProposal()
1981 std::string Action_DiplomacyProposal::dump() const
1983 std::stringstream s;
1985 switch (d_diplomatic_proposal)
1987 case Player::NO_PROPOSAL: s <<"nothing"; break;
1988 case Player::PROPOSE_WAR: s <<"war"; break;
1989 case Player::PROPOSE_WAR_IN_FIELD: s <<"war in the field"; break;
1990 case Player::PROPOSE_PEACE: s <<"peace"; break;
1992 s << " with player " << d_opponent_id << ".\n";
1997 bool Action_DiplomacyProposal::doSave(XML_Helper* helper) const
2001 retval &= helper->saveData("opponent_id", d_opponent_id);
2002 retval &= helper->saveData("proposal", (guint32)d_diplomatic_proposal);
2007 bool Action_DiplomacyProposal::fillData(Player *opponent,
2008 Player::DiplomaticProposal proposal)
2010 d_opponent_id = opponent->getId();
2011 d_diplomatic_proposal = proposal;
2015 //-----------------------------------------------------------------------------
2016 //Action_DiplomacyScore
2018 Action_DiplomacyScore::Action_DiplomacyScore()
2019 :Action(Action::DIPLOMATIC_SCORE)
2023 Action_DiplomacyScore::Action_DiplomacyScore(const Action_DiplomacyScore &action)
2024 : Action(action), d_opponent_id(action.d_opponent_id), d_amount(action.d_amount)
2028 Action_DiplomacyScore::Action_DiplomacyScore(XML_Helper* helper)
2031 helper->getData(d_opponent_id, "opponent_id");
2032 helper->getData(d_amount, "amount");
2035 Action_DiplomacyScore::~Action_DiplomacyScore()
2039 std::string Action_DiplomacyScore::dump() const
2041 std::stringstream s;
2043 s << "adding " << d_amount << " to " ;
2045 s << "subtracting " << d_amount << " from ";
2046 s << "player " << d_opponent_id << ".\n";
2051 bool Action_DiplomacyScore::doSave(XML_Helper* helper) const
2055 retval &= helper->saveData("opponent_id", d_opponent_id);
2056 retval &= helper->saveData("amount", d_amount);
2061 bool Action_DiplomacyScore::fillData(Player *opponent, int amount)
2063 d_opponent_id = opponent->getId();
2068 //-----------------------------------------------------------------------------
2071 Action_EndTurn::Action_EndTurn()
2072 :Action(Action::END_TURN)
2076 Action_EndTurn::Action_EndTurn(const Action_EndTurn &action)
2081 Action_EndTurn::Action_EndTurn(XML_Helper* helper)
2086 Action_EndTurn::~Action_EndTurn()
2090 std::string Action_EndTurn::dump() const
2092 return "ending turn\n";
2095 bool Action_EndTurn::doSave(XML_Helper* helper) const
2102 //-----------------------------------------------------------------------------
2103 //Action_ConquerCity
2105 Action_ConquerCity::Action_ConquerCity()
2106 :Action(Action::CITY_CONQUER), d_city(0), d_stack(0)
2110 Action_ConquerCity::Action_ConquerCity(const Action_ConquerCity &action)
2111 : Action(action), d_city(action.d_city), d_stack(action.d_stack)
2115 Action_ConquerCity::Action_ConquerCity(XML_Helper* helper)
2118 helper->getData(d_city, "city");
2119 helper->getData(d_stack, "stack");
2122 Action_ConquerCity::~Action_ConquerCity()
2126 std::string Action_ConquerCity::dump() const
2128 std::stringstream s;
2130 s <<"City " <<d_city <<" occupied by " << d_stack << "\n";
2135 bool Action_ConquerCity::doSave(XML_Helper* helper) const
2139 retval &= helper->saveData("city", d_city);
2140 retval &= helper->saveData("stack", d_stack);
2145 bool Action_ConquerCity::fillData(City* c, Stack *s)
2147 d_city = c->getId();
2148 d_stack = s->getId();
2152 //-----------------------------------------------------------------------------
2153 //Action_RecruitHero
2155 Action_RecruitHero::Action_RecruitHero()
2156 :Action(Action::RECRUIT_HERO), d_hero(0)
2160 Action_RecruitHero::Action_RecruitHero(XML_Helper* helper)
2163 helper->getData(d_city, "city");
2164 helper->getData(d_cost, "cost");
2165 helper->getData(d_allies, "allies");
2166 helper->getData(d_ally_army_type, "ally_army_type");
2167 helper->registerTag(HeroProto::d_tag, sigc::mem_fun(this, &Action_RecruitHero::load));
2170 Action_RecruitHero::Action_RecruitHero(const Action_RecruitHero &action)
2171 : Action(action), d_city(action.d_city), d_cost(action.d_cost),
2172 d_allies(action.d_allies), d_ally_army_type(action.d_ally_army_type)
2174 d_hero = new HeroProto(*action.d_hero);
2177 bool Action_RecruitHero::load(std::string tag, XML_Helper *helper)
2179 if (tag == HeroProto::d_tag)
2181 d_hero = new HeroProto(helper);
2188 Action_RecruitHero::~Action_RecruitHero()
2192 std::string Action_RecruitHero::dump() const
2194 std::stringstream s;
2196 s << "Hero " << d_hero->getName() << " recruited with " << d_allies << " allies\n";
2201 bool Action_RecruitHero::doSave(XML_Helper* helper) const
2205 retval &= helper->saveData("city", d_city);
2206 retval &= helper->saveData("cost", d_cost);
2207 retval &= helper->saveData("allies", d_allies);
2208 retval &= helper->saveData("ally_army_type", d_ally_army_type);
2209 retval &= d_hero->save(helper);
2214 bool Action_RecruitHero::fillData(HeroProto* hero, City *city, int cost, int alliesCount, const ArmyProto *ally)
2217 d_city = city->getId();
2219 d_allies = alliesCount;
2220 if (alliesCount > 0)
2221 d_ally_army_type = ally->getTypeId();
2223 d_ally_army_type = 0;
2227 //-----------------------------------------------------------------------------
2228 //Action_RenamePlayer
2230 Action_RenamePlayer::Action_RenamePlayer()
2231 :Action(Action::PLAYER_RENAME), d_name("")
2235 Action_RenamePlayer::Action_RenamePlayer(const Action_RenamePlayer &action)
2236 :Action(action), d_name(action.d_name)
2240 Action_RenamePlayer::Action_RenamePlayer(XML_Helper* helper)
2243 helper->getData(d_name, "name");
2246 Action_RenamePlayer::~Action_RenamePlayer()
2250 std::string Action_RenamePlayer::dump() const
2252 std::stringstream s;
2254 s << "Player changes name to " << d_name <<".\n";
2259 bool Action_RenamePlayer::doSave(XML_Helper* helper) const
2263 retval &= helper->saveData("name", d_name);
2268 bool Action_RenamePlayer::fillData(std::string name)
2274 //-----------------------------------------------------------------------------
2275 //Action_CityTooPoorToProduce
2277 Action_CityTooPoorToProduce::Action_CityTooPoorToProduce()
2278 :Action(Action::CITY_DESTITUTE), d_city(0), d_army_type(0)
2282 Action_CityTooPoorToProduce::Action_CityTooPoorToProduce(const Action_CityTooPoorToProduce &action)
2283 : Action(action), d_city(action.d_city), d_army_type(action.d_army_type)
2287 Action_CityTooPoorToProduce::Action_CityTooPoorToProduce(XML_Helper* helper)
2290 helper->getData(d_city, "city");
2291 helper->getData(d_army_type, "army_type");
2294 Action_CityTooPoorToProduce::~Action_CityTooPoorToProduce()
2298 std::string Action_CityTooPoorToProduce::dump() const
2300 std::stringstream s;
2302 s << "City " << d_city << " is too poor to produce army type "
2303 << d_army_type << "\n";
2308 bool Action_CityTooPoorToProduce::doSave(XML_Helper* helper) const
2312 retval &= helper->saveData("city", d_city);
2313 retval &= helper->saveData("army_type", d_army_type);
2318 bool Action_CityTooPoorToProduce::fillData(City* c, const ArmyProdBase *army)
2320 d_city = c->getId();
2321 d_army_type = army->getTypeId();
2326 //-----------------------------------------------------------------------------
2329 Action_InitTurn::Action_InitTurn()
2330 :Action(Action::INIT_TURN)
2334 Action_InitTurn::Action_InitTurn(const Action_InitTurn &action)
2339 Action_InitTurn::Action_InitTurn(XML_Helper* helper)
2344 Action_InitTurn::~Action_InitTurn()
2348 std::string Action_InitTurn::dump() const
2350 return "initializing turn\n";
2353 bool Action_InitTurn::doSave(XML_Helper* helper) const
2360 //-----------------------------------------------------------------------------
2363 Action_Loot::Action_Loot()
2364 :Action(Action::CITY_LOOT), d_looting_player_id(0), d_looted_player_id(0),
2365 d_gold_added(0), d_gold_removed(0)
2369 Action_Loot::Action_Loot(const Action_Loot &action)
2370 : Action(action), d_looting_player_id(action.d_looting_player_id),
2371 d_looted_player_id(action.d_looted_player_id),
2372 d_gold_added(action.d_gold_added), d_gold_removed(action.d_gold_removed)
2376 Action_Loot::Action_Loot(XML_Helper* helper)
2379 helper->getData(d_looting_player_id, "looting_player_id");
2380 helper->getData(d_looted_player_id, "looted_player_id");
2381 helper->getData(d_gold_added, "gold_added");
2382 helper->getData(d_gold_removed, "gold_removed");
2385 Action_Loot::~Action_Loot()
2389 std::string Action_Loot::dump() const
2391 std::stringstream s;
2392 s <<"player " <<d_looting_player_id << " took " << d_gold_added <<
2393 " gold pieces from player " << d_looted_player_id <<
2394 " who lost a total of " << d_gold_removed << "gold pieces.\n";
2398 bool Action_Loot::doSave(XML_Helper* helper) const
2402 retval &= helper->saveData("looting_player_id", d_looting_player_id);
2403 retval &= helper->saveData("looted_player_id", d_looted_player_id);
2404 retval &= helper->saveData("gold_added", d_gold_added);
2405 retval &= helper->saveData("gold_removed", d_gold_removed);
2411 bool Action_Loot::fillData(Player *looter, Player *looted, guint32 amount_to_add,
2412 guint32 amount_to_subtract)
2414 d_looting_player_id = looter->getId();
2415 d_looted_player_id = looted->getId();
2416 d_gold_added = amount_to_add;
2417 d_gold_removed = amount_to_subtract;
2421 std::string Action::actionTypeToString(Action::Type type)
2425 case Action::STACK_MOVE:
2426 return "Action::STACK_MOVE";
2427 case Action::STACK_SPLIT:
2428 return "Action::STACK_SPLIT";
2429 case Action::STACK_FIGHT:
2430 return "Action::STACK_FIGHT";
2431 case Action::STACK_JOIN:
2432 return "Action::STACK_JOIN";
2433 case Action::RUIN_SEARCH:
2434 return "Action::RUIN_SEARCH";
2435 case Action::TEMPLE_SEARCH:
2436 return "Action::TEMPLE_SEARCH";
2437 case Action::CITY_OCCUPY:
2438 return "Action::CITY_OCCUPY";
2439 case Action::CITY_PILLAGE:
2440 return "Action::CITY_PILLAGE";
2441 case Action::CITY_SACK:
2442 return "Action::CITY_SACK";
2443 case Action::CITY_RAZE:
2444 return "Action::CITY_RAZE";
2445 case Action::CITY_UPGRADE:
2446 return "Action::CITY_UPGRADE";
2447 case Action::CITY_BUY:
2448 return "Action::CITY_BUY";
2449 case Action::CITY_PROD:
2450 return "Action::CITY_PROD";
2451 case Action::REWARD:
2452 return "Action::REWARD" ;
2454 return "Action::QUEST";
2455 case Action::HERO_EQUIP:
2456 return "Action::HERO_EQUIP";
2457 case Action::UNIT_ADVANCE:
2458 return "Action::UNIT_ADVANCE";
2459 case Action::STACK_DISBAND:
2460 return "Action::STACK_DISBAND";
2461 case Action::MODIFY_SIGNPOST:
2462 return "Action::MODIFY_SIGNPOST";
2463 case Action::CITY_RENAME:
2464 return "Action::CITY_RENAME";
2465 case Action::CITY_VECTOR:
2466 return "Action::CITY_VECTOR";
2467 case Action::FIGHT_ORDER:
2468 return "Action::FIGHT_ORDER";
2469 case Action::RESIGN:
2470 return "Action::RESIGN";
2471 case Action::ITEM_PLANT:
2472 return "Action::ITEM_PLANT";
2473 case Action::PRODUCE_UNIT:
2474 return "Action::PRODUCE_UNIT";
2475 case Action::PRODUCE_VECTORED_UNIT:
2476 return "Action::PRODUCE_VECTORED_UNIT";
2477 case Action::DIPLOMATIC_STATE:
2478 return "Action::DIPLOMATIC_STATE";
2479 case Action::DIPLOMATIC_PROPOSAL:
2480 return "Action::DIPLOMATIC_PROPOSAL";
2481 case Action::DIPLOMATIC_SCORE:
2482 return "Action::DIPLOMATIC_SCORE";
2483 case Action::END_TURN:
2484 return "Action::END_TURN";
2485 case Action::CITY_CONQUER:
2486 return "Action::CITY_CONQUER";
2487 case Action::RECRUIT_HERO:
2488 return "Action::RECRUIT_HERO";
2489 case Action::PLAYER_RENAME:
2490 return "Action::PLAYER_RENAME";
2491 case Action::CITY_DESTITUTE:
2492 return "Action::CITY_DESTITUTE";
2493 case Action::INIT_TURN:
2494 return "Action::INIT_TURN";
2495 case Action::CITY_LOOT:
2496 return "Action::CITY_LOOT";
2499 return "Action::MOVE";
2502 Action::Type Action::actionTypeFromString(std::string str)
2504 if (str.size() > 0 && isdigit(str.c_str()[0]))
2505 return Action::Type(atoi(str.c_str()));
2506 if (str == "Action::STACK_MOVE")
2507 return Action::STACK_MOVE;
2508 else if (str == "Action::STACK_SPLIT")
2509 return Action::STACK_SPLIT;
2510 else if (str == "Action::STACK_FIGHT")
2511 return Action::STACK_FIGHT;
2512 else if (str == "Action::STACK_JOIN")
2513 return Action::STACK_JOIN;
2514 else if (str == "Action::RUIN_SEARCH")
2515 return Action::RUIN_SEARCH;
2516 else if (str == "Action::TEMPLE_SEARCH")
2517 return Action::TEMPLE_SEARCH;
2518 else if (str == "Action::CITY_OCCUPY")
2519 return Action::CITY_OCCUPY;
2520 else if (str == "Action::CITY_PILLAGE")
2521 return Action::CITY_PILLAGE;
2522 else if (str == "Action::CITY_SACK")
2523 return Action::CITY_SACK;
2524 else if (str == "Action::CITY_RAZE")
2525 return Action::CITY_RAZE;
2526 else if (str == "Action::CITY_UPGRADE")
2527 return Action::CITY_UPGRADE;
2528 else if (str == "Action::CITY_BUY")
2529 return Action::CITY_BUY;
2530 else if (str == "Action::CITY_PROD")
2531 return Action::CITY_PROD;
2532 else if (str == "Action::REWARD" )
2533 return Action::REWARD;
2534 else if (str == "Action::QUEST")
2535 return Action::QUEST;
2536 else if (str == "Action::HERO_EQUIP")
2537 return Action::HERO_EQUIP;
2538 else if (str == "Action::UNIT_ADVANCE")
2539 return Action::UNIT_ADVANCE;
2540 else if (str == "Action::STACK_DISBAND")
2541 return Action::STACK_DISBAND;
2542 else if (str == "Action::MODIFY_SIGNPOST")
2543 return Action::MODIFY_SIGNPOST;
2544 else if (str == "Action::CITY_RENAME")
2545 return Action::CITY_RENAME;
2546 else if (str == "Action::CITY_VECTOR")
2547 return Action::CITY_VECTOR;
2548 else if (str == "Action::FIGHT_ORDER")
2549 return Action::FIGHT_ORDER;
2550 else if (str == "Action::RESIGN")
2551 return Action::RESIGN;
2552 else if (str == "Action::ITEM_PLANT")
2553 return Action::ITEM_PLANT;
2554 else if (str == "Action::PRODUCE_UNIT")
2555 return Action::PRODUCE_UNIT;
2556 else if (str == "Action::PRODUCE_VECTORED_UNIT")
2557 return Action::PRODUCE_VECTORED_UNIT;
2558 else if (str == "Action::DIPLOMATIC_STATE")
2559 return Action::DIPLOMATIC_STATE;
2560 else if (str == "Action::DIPLOMATIC_PROPOSAL")
2561 return Action::DIPLOMATIC_PROPOSAL;
2562 else if (str == "Action::DIPLOMATIC_SCORE")
2563 return Action::DIPLOMATIC_SCORE;
2564 else if (str == "Action::END_TURN")
2565 return Action::END_TURN;
2566 else if (str == "Action::CITY_CONQUER")
2567 return Action::CITY_CONQUER;
2568 else if (str == "Action::RECRUIT_HERO")
2569 return Action::RECRUIT_HERO;
2570 else if (str == "Action::PLAYER_RENAME")
2571 return Action::PLAYER_RENAME;
2572 else if (str == "Action::CITY_DESTITUTE")
2573 return Action::CITY_DESTITUTE;
2574 else if (str == "Action::INIT_TURN")
2575 return Action::INIT_TURN;
2576 else if (str == "Action::CITY_LOOT")
2577 return Action::CITY_LOOT;
2578 return Action::STACK_MOVE;