~ubuntu-branches/ubuntu/raring/lordsawar/raring

« back to all changes in this revision

Viewing changes to src/action.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Barry deFreese, Gonéri Le Bouder
  • Date: 2008-06-17 11:15:26 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080617111526-yjyvu9df50zmpdo0
Tags: 0.0.9-1
[ Barry deFreese ]
* New upstream release.
  + Fixes gcc-4.3 builds so drop ftbfs_gcc-4.3_fix.diff.
  + Add new build-dependency for libgnet-dev.
* Add simple man page for new lordsawar-tile-editor.
* Add desktop file for lordsawar-tile-editor.
* Remove French translation on install.

[ Gonéri Le Bouder ]
* bump Debian Policy to 3.8.0. No change needed.
* fix wording in the 0.0.8-3 entry of the Debian changelog

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
//
1
6
//  This program is free software; you can redistribute it and/or modify
2
7
//  it under the terms of the GNU General Public License as published by
3
8
//  the Free Software Foundation; either version 2 of the License, or
10
15
//
11
16
//  You should have received a copy of the GNU General Public License
12
17
//  along with this program; if not, write to the Free Software
13
 
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 
19
//  02110-1301, USA.
14
20
 
15
21
#include <stdlib.h>
16
22
#include <sstream>
45
51
{
46
52
}
47
53
 
 
54
Action::Action(XML_Helper *helper)
 
55
{
 
56
  Uint32 t;
 
57
  helper->getData(t, "type");
 
58
  d_type = Action::Type(t);
 
59
  helper->getData(d_player, "player");
 
60
}
 
61
 
48
62
Action::~Action()
49
63
{
50
64
}
51
65
 
 
66
bool Action::save(XML_Helper* helper) const
 
67
{
 
68
    bool retval = true;
 
69
 
 
70
    retval &= helper->openTag("action");
 
71
    retval &= helper->saveData("type", d_type);
 
72
    retval &= helper->saveData("player", d_player);
 
73
    retval &= doSave(helper);
 
74
    retval &= helper->closeTag();
 
75
 
 
76
    return retval;
 
77
}
 
78
 
52
79
Action* Action::handle_load(XML_Helper* helper)
53
80
{
54
81
    Uint32 t;
114
141
            return (new Action_DiplomacyProposal(helper));
115
142
        case DIPLOMATIC_SCORE:
116
143
            return (new Action_DiplomacyScore(helper));
 
144
        case END_TURN:
 
145
            return (new Action_EndTurn(helper));
 
146
        case CITY_CONQUER:
 
147
            return (new Action_ConquerCity(helper));
 
148
        case RECRUIT_HERO:
 
149
            return (new Action_RecruitHero(helper));
117
150
    }
118
151
 
119
152
    return 0;
189
222
            return 
190
223
              (new Action_DiplomacyScore
191
224
                (*dynamic_cast<const Action_DiplomacyScore*>(a)));
 
225
        case END_TURN:
 
226
            return 
 
227
              (new Action_EndTurn
 
228
                (*dynamic_cast<const Action_EndTurn*>(a)));
 
229
        case CITY_CONQUER:
 
230
            return 
 
231
              (new Action_ConquerCity
 
232
                (*dynamic_cast<const Action_ConquerCity*>(a)));
 
233
        case RECRUIT_HERO:
 
234
            return 
 
235
              (new Action_RecruitHero
 
236
                (*dynamic_cast<const Action_RecruitHero*>(a)));
192
237
    }
193
238
 
194
239
    return 0;
204
249
}
205
250
 
206
251
Action_Move::Action_Move(XML_Helper* helper)
207
 
    :Action(Action::STACK_MOVE)
 
252
    :Action(helper)
208
253
{
209
254
    helper->getData(d_stack, "stack");
210
255
 
229
274
    return s.str();
230
275
}
231
276
 
232
 
bool Action_Move::save(XML_Helper* helper) const
 
277
bool Action_Move::doSave(XML_Helper* helper) const
233
278
{
234
279
    bool retval = true;
235
280
 
236
 
    retval &= helper->openTag("action");
237
 
    retval &= helper->saveData("type", d_type);
238
281
    retval &= helper->saveData("stack", d_stack);
239
282
    retval &= helper->saveData("x", d_dest.x);
240
283
    retval &= helper->saveData("y", d_dest.y);
241
 
    retval &= helper->closeTag();
242
284
 
243
285
    return retval;
244
286
}
261
303
}
262
304
 
263
305
Action_Split::Action_Split(XML_Helper* helper)
264
 
    :Action(Action::STACK_SPLIT)
 
306
    :Action(helper)
265
307
{
266
308
    helper->getData(d_orig, "orig_stack");
267
309
    helper->getData(d_added, "new_stack");
294
336
    return s.str();
295
337
}
296
338
 
297
 
bool Action_Split::save(XML_Helper* helper) const
 
339
bool Action_Split::doSave(XML_Helper* helper) const
298
340
{
299
341
    bool retval = true;
300
342
    std::stringstream s;
303
345
        s <<d_armies_moved[i] <<" ";
304
346
    s <<d_armies_moved[MAX_STACK_SIZE - 1];
305
347
 
306
 
    retval &= helper->openTag("action");
307
 
    retval &= helper->saveData("type", Action::STACK_SPLIT);
308
348
    retval &= helper->saveData("orig_stack", d_orig);
309
349
    retval &= helper->saveData("new_stack", d_added);
310
350
    retval &= helper->saveData("moved", s.str());
311
 
    retval &= helper->closeTag();
312
351
 
313
352
    return retval;
314
353
}
346
385
}
347
386
 
348
387
Action_Fight::Action_Fight(XML_Helper* helper)
349
 
    :Action(Action::STACK_FIGHT)
 
388
    :Action(helper)
350
389
{
351
390
    std::string s;
352
391
    std::istringstream si;
359
398
    si.str(s);
360
399
    while (si >> ui)
361
400
        d_attackers.push_back(ui);
 
401
    si.clear();
362
402
 
363
403
    helper->getData(s, "defenders");
364
404
    si.str(s);
386
426
    return s.str();
387
427
}
388
428
 
389
 
bool Action_Fight::save(XML_Helper* helper) const
 
429
bool Action_Fight::doSave(XML_Helper* helper) const
390
430
{
391
431
    std::stringstream si;
392
432
    std::list<Uint32>::const_iterator uit;
393
433
    bool retval = true;
394
434
    
395
 
    retval &= helper->openTag("action");
396
 
    retval &= helper->saveData("type", Action::STACK_FIGHT);
397
435
 
398
436
    // save the stack's ids
399
437
    for (uit = d_attackers.begin(); uit != d_attackers.end(); uit++)
415
453
        retval &= helper->closeTag();
416
454
    }
417
455
 
418
 
    retval &= helper->closeTag();
419
 
 
420
456
    return retval;
421
457
}
422
458
 
431
467
    list = f->getDefenders();
432
468
 
433
469
    for (it = list.begin(); it != list.end(); it++)
434
 
        d_attackers.push_back((*it)->getId());
 
470
        d_defenders.push_back((*it)->getId());
435
471
    
436
 
    d_history   = f->getCourseOfEvents();
 
472
    d_history = f->getCourseOfEvents();
437
473
 
438
474
    return true;
439
475
}
446
482
    helper->getData(item.id, "id");
447
483
    helper->getData(item.damage, "damage");
448
484
 
 
485
    d_history.push_back(item);
 
486
 
449
487
    return true;
450
488
}
451
489
 
458
496
}
459
497
 
460
498
Action_Join::Action_Join(XML_Helper* helper)
461
 
    :Action(Action::STACK_JOIN)
 
499
    :Action(helper)
462
500
{
463
501
    helper->getData(d_orig_id, "receiver");
464
502
    helper->getData(d_joining_id, "joining");
477
515
    return s.str();
478
516
}
479
517
 
480
 
bool Action_Join::save(XML_Helper* helper) const
 
518
bool Action_Join::doSave(XML_Helper* helper) const
481
519
{
482
520
    bool retval = true;
483
521
 
484
 
    retval &= helper->openTag("action");
485
 
    retval &= helper->saveData("type", d_type);
486
522
    retval &= helper->saveData("receiver", d_orig_id);
487
523
    retval &= helper->saveData("joining", d_joining_id);
488
 
    retval &= helper->closeTag();
489
524
 
490
525
    return retval;
491
526
}
517
552
}
518
553
 
519
554
Action_Ruin::Action_Ruin(XML_Helper* helper)
520
 
    :Action(Action::RUIN_SEARCH)
 
555
    :Action(helper)
521
556
{
522
557
    helper->getData(d_ruin, "ruin");
523
558
    helper->getData(d_stack, "seeker");
538
573
    return s.str();
539
574
}
540
575
 
541
 
bool Action_Ruin::save(XML_Helper* helper) const
 
576
bool Action_Ruin::doSave(XML_Helper* helper) const
542
577
{
543
578
    bool retval = true;
544
579
 
545
 
    retval &= helper->openTag("action");
546
 
    retval &= helper->saveData("type", Action::RUIN_SEARCH);
547
580
    retval &= helper->saveData("ruin", d_ruin);
548
581
    retval &= helper->saveData("seeker", d_stack);
549
582
    retval &= helper->saveData("searched", d_searched);
550
 
    retval &= helper->closeTag();
551
583
 
552
584
    return retval;
553
585
}
571
603
}
572
604
 
573
605
Action_Temple::Action_Temple(XML_Helper* helper)
574
 
    :Action(Action::TEMPLE_SEARCH)
 
606
    :Action(helper)
575
607
{
576
608
    helper->getData(d_temple, "temple");
577
609
    helper->getData(d_stack, "stack");
590
622
    return s.str();
591
623
}
592
624
 
593
 
bool Action_Temple::save(XML_Helper* helper) const
 
625
bool Action_Temple::doSave(XML_Helper* helper) const
594
626
{
595
627
    bool retval = true;
596
628
 
597
 
    retval &= helper->openTag("action");
598
 
    retval &= helper->saveData("type", Action::TEMPLE_SEARCH);
599
629
    retval &= helper->saveData("temple", d_temple);
600
630
    retval &= helper->saveData("stack", d_stack);
601
 
    retval &= helper->closeTag();
602
631
 
603
632
    return retval;
604
633
}
621
650
}
622
651
 
623
652
Action_Occupy::Action_Occupy(XML_Helper* helper)
624
 
    :Action(Action::CITY_OCCUPY)
 
653
    :Action(helper)
625
654
{
626
655
    helper->getData(d_city, "city");
627
656
}
639
668
    return s.str();
640
669
}
641
670
 
642
 
bool Action_Occupy::save(XML_Helper* helper) const
 
671
bool Action_Occupy::doSave(XML_Helper* helper) const
643
672
{
644
673
    bool retval = true;
645
674
 
646
 
    retval &= helper->openTag("action");
647
 
    retval &= helper->saveData("type", Action::CITY_OCCUPY);
648
675
    retval &= helper->saveData("city", d_city);
649
 
    retval &= helper->closeTag();
650
676
 
651
677
    return retval;
652
678
}
666
692
}
667
693
 
668
694
Action_Pillage::Action_Pillage(XML_Helper* helper)
669
 
    :Action(Action::CITY_PILLAGE)
 
695
    :Action(helper)
670
696
{
671
697
    helper->getData(d_city, "city");
672
698
}
682
708
    return s.str();
683
709
}
684
710
 
685
 
bool Action_Pillage::save(XML_Helper* helper) const
 
711
bool Action_Pillage::doSave(XML_Helper* helper) const
686
712
{
687
713
    bool retval = true;
688
714
 
689
 
    retval &= helper->openTag("action");
690
 
    retval &= helper->saveData("type", Action::CITY_PILLAGE);
691
715
    retval &= helper->saveData("city", d_city);
692
 
    retval &= helper->closeTag();
693
716
 
694
717
    return retval;
695
718
}
709
732
}
710
733
 
711
734
Action_Sack::Action_Sack(XML_Helper* helper)
712
 
    :Action(Action::CITY_SACK)
 
735
    :Action(helper)
713
736
{
714
737
    helper->getData(d_city, "city");
715
738
}
725
748
    return s.str();
726
749
}
727
750
 
728
 
bool Action_Sack::save(XML_Helper* helper) const
 
751
bool Action_Sack::doSave(XML_Helper* helper) const
729
752
{
730
753
    bool retval = true;
731
754
 
732
 
    retval &= helper->openTag("action");
733
 
    retval &= helper->saveData("type", Action::CITY_SACK);
734
755
    retval &= helper->saveData("city", d_city);
735
 
    retval &= helper->closeTag();
736
756
 
737
757
    return retval;
738
758
}
752
772
}
753
773
 
754
774
Action_Raze::Action_Raze(XML_Helper* helper)
755
 
    :Action(Action::CITY_RAZE)
 
775
    :Action(helper)
756
776
{
757
777
    helper->getData(d_city, "city");
758
778
}
770
790
    return s.str();
771
791
}
772
792
 
773
 
bool Action_Raze::save(XML_Helper* helper) const
 
793
bool Action_Raze::doSave(XML_Helper* helper) const
774
794
{
775
795
    bool retval = true;
776
796
 
777
 
    retval &= helper->openTag("action");
778
 
    retval &= helper->saveData("type", Action::CITY_RAZE);
779
797
    retval &= helper->saveData("city", d_city);
780
 
    retval &= helper->closeTag();
781
798
 
782
799
    return retval;
783
800
}
797
814
}
798
815
 
799
816
Action_Upgrade::Action_Upgrade(XML_Helper* helper)
800
 
    :Action(Action::CITY_UPGRADE)
 
817
    :Action(helper)
801
818
{
802
819
    helper->getData(d_city, "city");
803
820
}
815
832
    return s.str();
816
833
}
817
834
 
818
 
bool Action_Upgrade::save(XML_Helper* helper) const
 
835
bool Action_Upgrade::doSave(XML_Helper* helper) const
819
836
{
820
837
    bool retval = true;
821
838
 
822
 
    retval &= helper->openTag("action");
823
 
    retval &= helper->saveData("type", Action::CITY_UPGRADE);
824
839
    retval &= helper->saveData("city", d_city);
825
 
    retval &= helper->closeTag();
826
840
 
827
841
    return retval;
828
842
}
842
856
}
843
857
 
844
858
Action_Buy::Action_Buy(XML_Helper* helper)
845
 
    :Action(Action::CITY_BUY)
 
859
    :Action(helper)
846
860
{
847
861
    helper->getData(d_city, "city");
848
862
    helper->getData(d_slot, "slot");
863
877
    return s.str();
864
878
}
865
879
 
866
 
bool Action_Buy::save(XML_Helper* helper) const
 
880
bool Action_Buy::doSave(XML_Helper* helper) const
867
881
{
868
882
    bool retval = true;
869
883
 
870
 
    retval &= helper->openTag("action");
871
 
    retval &= helper->saveData("type", Action::CITY_BUY);
872
884
    retval &= helper->saveData("city", d_city);
873
885
    retval &= helper->saveData("slot", d_slot);
874
886
    retval &= helper->saveData("production", d_prod);
875
 
    retval &= helper->closeTag();
876
887
 
877
888
    return retval;
878
889
}
879
890
 
880
 
bool Action_Buy::fillData(City* c, int slot, int prod)
 
891
bool Action_Buy::fillData(City* c, int slot, const Army *prod)
881
892
{
882
893
    d_city = c->getId();
883
894
    d_slot = slot;
884
 
    d_prod = prod;
 
895
    d_prod = prod->getType();
885
896
 
886
897
    return true;
887
898
}
895
906
}
896
907
 
897
908
Action_Production::Action_Production(XML_Helper* helper)
898
 
    :Action(Action::CITY_PROD)
 
909
    :Action(helper)
899
910
{
900
911
    helper->getData(d_city, "city");
901
912
    helper->getData(d_prod, "production");
915
926
    return s.str();
916
927
}
917
928
 
918
 
bool Action_Production::save(XML_Helper* helper) const
 
929
bool Action_Production::doSave(XML_Helper* helper) const
919
930
{
920
931
    bool retval = true;
921
932
 
922
 
    retval &= helper->openTag("action");
923
 
    retval &= helper->saveData("type", Action::CITY_PROD);
924
933
    retval &= helper->saveData("city", d_city);
925
934
    retval &= helper->saveData("production", d_prod);
926
 
    retval &= helper->closeTag();
927
935
 
928
936
    return retval;
929
937
}
930
938
 
931
 
bool Action_Production::fillData(City* c, int prod)
 
939
bool Action_Production::fillData(City* c, int slot)
932
940
{
933
941
    d_city = c->getId();
934
 
    d_prod = prod;
 
942
    d_prod = slot;
935
943
 
936
944
    return true;
937
945
}
968
976
}
969
977
 
970
978
Action_Reward::Action_Reward(XML_Helper* helper)
971
 
:Action(Action::REWARD)
 
979
:Action(helper)
972
980
{
973
 
  helper->registerTag("reward", sigc::mem_fun((*this), &Action_Reward::load));
 
981
  helper->getData(d_stack, "stack");
 
982
  helper->registerTag("reward", sigc::mem_fun(this, &Action_Reward::load));
974
983
}
975
984
 
976
985
Action_Reward::~Action_Reward()
977
986
{
978
987
}
979
988
 
980
 
bool Action_Reward::fillData(Reward* r)
 
989
bool Action_Reward::fillData(Stack *s, Reward* r)
981
990
{
 
991
  d_stack = s->getId();
982
992
  d_reward = r;
983
993
  return true;
984
994
}
993
1003
  return s.str();
994
1004
}
995
1005
 
996
 
bool Action_Reward::save(XML_Helper* helper) const
 
1006
bool Action_Reward::doSave(XML_Helper* helper) const
997
1007
{
998
1008
  bool retval = true;
999
1009
 
1000
 
  retval &= helper->openTag("action");
1001
 
  retval &= helper->saveData("type", Action::REWARD);
 
1010
  retval &= helper->saveData("stack", d_stack);
1002
1011
  if (d_reward->getType() == Reward::GOLD)
1003
1012
    static_cast<Reward_Gold*>(d_reward)->save(helper);
1004
1013
  else if (d_reward->getType() == Reward::ALLIES)
1009
1018
    static_cast<Reward_Ruin*>(d_reward)->save(helper);
1010
1019
  else if (d_reward->getType() == Reward::MAP)
1011
1020
    static_cast<Reward_Map*>(d_reward)->save(helper);
1012
 
  retval &= helper->closeTag();
1013
1021
 
1014
1022
  return retval;
1015
1023
}
1023
1031
}
1024
1032
 
1025
1033
Action_Quest::Action_Quest(XML_Helper* helper)
1026
 
:Action(Action::QUEST)
 
1034
:Action(helper)
1027
1035
{
1028
1036
 
1029
1037
  helper->getData(d_hero, "hero");
1046
1054
  return ss.str();
1047
1055
}
1048
1056
 
1049
 
bool Action_Quest::save(XML_Helper* helper) const
 
1057
bool Action_Quest::doSave(XML_Helper* helper) const
1050
1058
{
1051
1059
  bool retval = true;
1052
1060
 
1053
 
  retval &= helper->openTag("action");
1054
 
  retval &= helper->saveData("type", d_type);
1055
1061
  retval &= helper->saveData("hero", d_hero);
1056
1062
  retval &= helper->saveData("quest", d_questtype);
1057
1063
  retval &= helper->saveData("data", d_data);
1058
1064
  retval &= helper->saveData("victim_player", d_victim_player);
1059
 
  retval &= helper->closeTag();
1060
1065
 
1061
1066
  return retval;
1062
1067
}
1105
1110
}
1106
1111
 
1107
1112
Action_Equip::Action_Equip(XML_Helper* helper)
1108
 
:Action(Action::HERO_EQUIP)
 
1113
:Action(helper)
1109
1114
{
1110
1115
  helper->getData(d_hero, "hero");
1111
1116
  helper->getData(d_item, "item");
1126
1131
  return ss.str();
1127
1132
}
1128
1133
 
1129
 
bool Action_Equip::save(XML_Helper* helper) const
 
1134
bool Action_Equip::doSave(XML_Helper* helper) const
1130
1135
{
1131
1136
  bool retval = true;
1132
1137
 
1133
 
  retval &= helper->openTag("action");
1134
 
  retval &= helper->saveData("type", d_type);
1135
1138
  retval &= helper->saveData("hero", d_hero);
1136
1139
  retval &= helper->saveData("item", d_item);
1137
1140
  retval &= helper->saveData("dest", d_slot);
1138
 
  retval &= helper->closeTag();
1139
1141
 
1140
1142
  return retval;
1141
1143
}
1142
1144
 
1143
 
bool Action_Equip::fillData(Uint32 hero, Uint32 item, Action_Equip::Slot slot)
 
1145
bool Action_Equip::fillData(Hero *hero, Item *item, Action_Equip::Slot slot)
1144
1146
{
1145
 
  d_hero = hero;
1146
 
  d_item = item;
 
1147
  d_hero = hero->getId();
 
1148
  d_item = item->getId();
1147
1149
  d_slot = slot;
1148
1150
 
1149
1151
  return true;
1158
1160
}
1159
1161
 
1160
1162
Action_Level::Action_Level(XML_Helper* helper)
1161
 
:Action(Action::UNIT_ADVANCE)
 
1163
:Action(helper)
1162
1164
{
1163
1165
  helper->getData(d_army, "army");
1164
1166
  helper->getData(d_stat, "stat");
1178
1180
  return ss.str();
1179
1181
}
1180
1182
 
1181
 
bool Action_Level::save(XML_Helper* helper) const
 
1183
bool Action_Level::doSave(XML_Helper* helper) const
1182
1184
{
1183
1185
  bool retval = true;
1184
1186
 
1185
 
  retval &= helper->openTag("action");
1186
 
  retval &= helper->saveData("type", d_type);
1187
1187
  retval &= helper->saveData("army", d_army);
1188
1188
  retval &= helper->saveData("stat", d_stat);
1189
 
  retval &= helper->closeTag();
1190
1189
 
1191
1190
  return retval;
1192
1191
}
1193
1192
 
1194
 
bool Action_Level::fillData(Uint32 unit, Army::Stat raised)
 
1193
bool Action_Level::fillData(Army *unit, Army::Stat raised)
1195
1194
{
1196
 
  d_army = unit;
 
1195
  d_army = unit->getId();
1197
1196
  d_stat = raised;
1198
1197
 
1199
1198
  return true;
1208
1207
}
1209
1208
 
1210
1209
Action_Disband::Action_Disband(XML_Helper* helper)
1211
 
:Action(Action::STACK_DISBAND)
 
1210
:Action(helper)
1212
1211
{
1213
1212
  helper->getData(d_stack, "stack");
1214
1213
}
1226
1225
  return s.str();
1227
1226
}
1228
1227
 
1229
 
bool Action_Disband::save(XML_Helper* helper) const
 
1228
bool Action_Disband::doSave(XML_Helper* helper) const
1230
1229
{
1231
1230
  bool retval = true;
1232
1231
 
1233
 
  retval &= helper->openTag("action");
1234
 
  retval &= helper->saveData("type", d_type);
1235
1232
  retval &= helper->saveData("stack", d_stack);
1236
 
  retval &= helper->closeTag();
1237
1233
 
1238
1234
  return retval;
1239
1235
}
1253
1249
}
1254
1250
 
1255
1251
Action_ModifySignpost::Action_ModifySignpost(XML_Helper* helper)
1256
 
:Action(Action::MODIFY_SIGNPOST)
 
1252
:Action(helper)
1257
1253
{
1258
1254
  helper->getData(d_signpost, "signpost");
1259
1255
  helper->getData(d_message, "message");
1272
1268
  return s.str();
1273
1269
}
1274
1270
 
1275
 
bool Action_ModifySignpost::save(XML_Helper* helper) const
 
1271
bool Action_ModifySignpost::doSave(XML_Helper* helper) const
1276
1272
{
1277
1273
  bool retval = true;
1278
1274
 
1279
 
  retval &= helper->openTag("action");
1280
 
  retval &= helper->saveData("type", d_type);
1281
1275
  retval &= helper->saveData("signpost", d_signpost);
1282
1276
  retval &= helper->saveData("message", d_message);
1283
 
  retval &= helper->closeTag();
1284
1277
 
1285
1278
  return retval;
1286
1279
}
1301
1294
}
1302
1295
 
1303
1296
Action_RenameCity::Action_RenameCity(XML_Helper* helper)
1304
 
:Action(Action::CITY_RENAME)
 
1297
:Action(helper)
1305
1298
{
1306
1299
  helper->getData(d_city, "city");
1307
1300
  helper->getData(d_name, "name");
1320
1313
  return s.str();
1321
1314
}
1322
1315
 
1323
 
bool Action_RenameCity::save(XML_Helper* helper) const
 
1316
bool Action_RenameCity::doSave(XML_Helper* helper) const
1324
1317
{
1325
1318
  bool retval = true;
1326
1319
 
1327
 
  retval &= helper->openTag("action");
1328
 
  retval &= helper->saveData("type", d_type);
1329
1320
  retval &= helper->saveData("city", d_city);
1330
1321
  retval &= helper->saveData("name", d_name);
1331
 
  retval &= helper->closeTag();
1332
1322
 
1333
1323
  return retval;
1334
1324
}
1349
1339
}
1350
1340
 
1351
1341
Action_Vector::Action_Vector(XML_Helper* helper)
1352
 
:Action(Action::CITY_VECTOR)
 
1342
:Action(helper)
1353
1343
{
1354
1344
  helper->getData(d_city, "city");
1355
1345
  int i;
1373
1363
  return s.str();
1374
1364
}
1375
1365
 
1376
 
bool Action_Vector::save(XML_Helper* helper) const
 
1366
bool Action_Vector::doSave(XML_Helper* helper) const
1377
1367
{
1378
1368
  bool retval = true;
1379
1369
 
1380
 
  retval &= helper->openTag("action");
1381
 
  retval &= helper->saveData("type", d_type);
1382
1370
  retval &= helper->saveData("city", d_city);
1383
1371
  retval &= helper->saveData("x", d_dest.x);
1384
1372
  retval &= helper->saveData("y", d_dest.y);
1385
 
  retval &= helper->closeTag();
1386
1373
 
1387
1374
  return retval;
1388
1375
}
1403
1390
}
1404
1391
 
1405
1392
Action_FightOrder::Action_FightOrder(XML_Helper* helper)
1406
 
:Action(Action::FIGHT_ORDER)
 
1393
:Action(helper)
1407
1394
{
1408
1395
  std::string fight_order;
1409
1396
  std::stringstream sfight_order;
1437
1424
  return s.str();
1438
1425
}
1439
1426
 
1440
 
bool Action_FightOrder::save(XML_Helper* helper) const
 
1427
bool Action_FightOrder::doSave(XML_Helper* helper) const
1441
1428
{
1442
1429
  bool retval = true;
1443
1430
 
1444
 
  retval &= helper->openTag("action");
1445
 
  retval &= helper->saveData("type", d_type);
1446
1431
  std::stringstream fight_order;
1447
1432
  for (std::list<Uint32>::const_iterator it = d_order.begin();
1448
1433
       it != d_order.end(); it++)
1450
1435
      fight_order << (*it) << " ";
1451
1436
    }
1452
1437
  retval &= helper->saveData("order", fight_order.str());
1453
 
  retval &= helper->closeTag();
1454
1438
 
1455
1439
  return retval;
1456
1440
}
1470
1454
}
1471
1455
 
1472
1456
Action_Resign::Action_Resign(XML_Helper* helper)
1473
 
:Action(Action::RESIGN)
 
1457
:Action(helper)
1474
1458
{
1475
1459
}
1476
1460
 
1486
1470
  return s.str();
1487
1471
}
1488
1472
 
1489
 
bool Action_Resign::save(XML_Helper* helper) const
 
1473
bool Action_Resign::doSave(XML_Helper* helper) const
1490
1474
{
1491
1475
  bool retval = true;
1492
1476
 
1493
 
  retval &= helper->openTag("action");
1494
 
  retval &= helper->saveData("type", d_type);
1495
 
  retval &= helper->closeTag();
1496
 
 
1497
1477
  return retval;
1498
1478
}
1499
1479
 
1511
1491
}
1512
1492
 
1513
1493
Action_Plant::Action_Plant(XML_Helper* helper)
1514
 
:Action(Action::ITEM_PLANT)
 
1494
:Action(helper)
1515
1495
{
1516
1496
  helper->getData(d_hero, "hero");
1517
1497
  helper->getData(d_item, "item");
1529
1509
  return s.str();
1530
1510
}
1531
1511
 
1532
 
bool Action_Plant::save(XML_Helper* helper) const
 
1512
bool Action_Plant::doSave(XML_Helper* helper) const
1533
1513
{
1534
1514
  bool retval = true;
1535
1515
 
1536
 
  retval &= helper->openTag("action");
1537
 
  retval &= helper->saveData("type", d_type);
1538
1516
  retval &= helper->saveData("hero", d_hero);
1539
1517
  retval &= helper->saveData("item", d_item);
1540
 
  retval &= helper->closeTag();
1541
1518
 
1542
1519
  return retval;
1543
1520
}
1544
1521
 
1545
 
bool Action_Plant::fillData(Uint32 hero, Uint32 item)
 
1522
bool Action_Plant::fillData(Hero *hero, Item *item)
1546
1523
{
1547
 
  d_hero = hero;
1548
 
  d_item = item;
 
1524
  d_hero = hero->getId();
 
1525
  d_item = item->getId();
1549
1526
  return true;
1550
1527
}
1551
1528
 
1558
1535
}
1559
1536
 
1560
1537
Action_Produce::Action_Produce(XML_Helper* helper)
1561
 
:Action(Action::PRODUCE_UNIT)
 
1538
:Action(helper)
1562
1539
{
1563
1540
  helper->getData(d_army_type, "army_type");
1564
1541
  helper->getData(d_city, "city");
1580
1557
  return s.str();
1581
1558
}
1582
1559
 
1583
 
bool Action_Produce::save(XML_Helper* helper) const
 
1560
bool Action_Produce::doSave(XML_Helper* helper) const
1584
1561
{
1585
1562
  bool retval = true;
1586
1563
 
1587
 
  retval &= helper->openTag("action");
1588
 
  retval &= helper->saveData("type", d_type);
1589
1564
  retval &= helper->saveData("army_type", d_army_type);
1590
1565
  retval &= helper->saveData("city", d_city);
1591
1566
  retval &= helper->saveData("vectored", d_vectored);
1592
 
  retval &= helper->closeTag();
1593
1567
 
1594
1568
  return retval;
1595
1569
}
1596
1570
 
1597
 
bool Action_Produce::fillData(Uint32 army_type, City *city, bool vectored)
 
1571
bool Action_Produce::fillData(const Army *army, City *city, bool vectored)
1598
1572
{
1599
 
  d_army_type = army_type;
 
1573
  if (army == NULL)
 
1574
    d_army_type = -1;
 
1575
  else
 
1576
    d_army_type = army->getType();
1600
1577
  d_city = city->getId();
1601
1578
  d_vectored = vectored;
1602
1579
  return true;
1611
1588
}
1612
1589
 
1613
1590
Action_ProduceVectored::Action_ProduceVectored(XML_Helper* helper)
1614
 
:Action(Action::PRODUCE_VECTORED_UNIT)
 
1591
:Action(helper)
1615
1592
{
1616
1593
  helper->getData(d_army_type, "army_type");
1617
1594
  int i;
1634
1611
  return s.str();
1635
1612
}
1636
1613
 
1637
 
bool Action_ProduceVectored::save(XML_Helper* helper) const
 
1614
bool Action_ProduceVectored::doSave(XML_Helper* helper) const
1638
1615
{
1639
1616
  bool retval = true;
1640
1617
 
1641
 
  retval &= helper->openTag("action");
1642
 
  retval &= helper->saveData("type", d_type);
1643
1618
  retval &= helper->saveData("army_type", d_army_type);
1644
1619
  retval &= helper->saveData("x", d_dest.x);
1645
1620
  retval &= helper->saveData("y", d_dest.y);
1646
 
  retval &= helper->closeTag();
1647
1621
 
1648
1622
  return retval;
1649
1623
}
1664
1638
}
1665
1639
 
1666
1640
Action_DiplomacyState::Action_DiplomacyState(XML_Helper* helper)
1667
 
:Action(Action::DIPLOMATIC_STATE)
 
1641
:Action(helper)
1668
1642
{
1669
1643
  Uint32 diplomatic_state;
1670
1644
  helper->getData(d_opponent_id, "opponent_id");
1691
1665
  return s.str();
1692
1666
}
1693
1667
 
1694
 
bool Action_DiplomacyState::save(XML_Helper* helper) const
 
1668
bool Action_DiplomacyState::doSave(XML_Helper* helper) const
1695
1669
{
1696
1670
  bool retval = true;
1697
1671
 
1698
 
  retval &= helper->openTag("action");
1699
 
  retval &= helper->saveData("type", d_type);
1700
1672
  retval &= helper->saveData("opponent_id", d_opponent_id);
1701
1673
  retval &= helper->saveData("state", (Uint32)d_diplomatic_state);
1702
 
  retval &= helper->closeTag();
1703
1674
 
1704
1675
  return retval;
1705
1676
}
1721
1692
}
1722
1693
 
1723
1694
Action_DiplomacyProposal::Action_DiplomacyProposal(XML_Helper* helper)
1724
 
:Action(Action::DIPLOMATIC_PROPOSAL)
 
1695
:Action(helper)
1725
1696
{
1726
1697
  Uint32 diplomatic_proposal;
1727
1698
  helper->getData(d_opponent_id, "opponent_id");
1749
1720
  return s.str();
1750
1721
}
1751
1722
 
1752
 
bool Action_DiplomacyProposal::save(XML_Helper* helper) const
 
1723
bool Action_DiplomacyProposal::doSave(XML_Helper* helper) const
1753
1724
{
1754
1725
  bool retval = true;
1755
1726
 
1756
 
  retval &= helper->openTag("action");
1757
 
  retval &= helper->saveData("type", d_type);
1758
1727
  retval &= helper->saveData("opponent_id", d_opponent_id);
1759
1728
  retval &= helper->saveData("proposal", (Uint32)d_diplomatic_proposal);
1760
 
  retval &= helper->closeTag();
1761
1729
 
1762
1730
  return retval;
1763
1731
}
1779
1747
}
1780
1748
 
1781
1749
Action_DiplomacyScore::Action_DiplomacyScore(XML_Helper* helper)
1782
 
:Action(Action::DIPLOMATIC_SCORE)
 
1750
:Action(helper)
1783
1751
{
1784
1752
  helper->getData(d_opponent_id, "opponent_id");
1785
1753
  helper->getData(d_amount, "amount");
1801
1769
  return s.str();
1802
1770
}
1803
1771
 
1804
 
bool Action_DiplomacyScore::save(XML_Helper* helper) const
 
1772
bool Action_DiplomacyScore::doSave(XML_Helper* helper) const
1805
1773
{
1806
1774
  bool retval = true;
1807
1775
 
1808
 
  retval &= helper->openTag("action");
1809
 
  retval &= helper->saveData("type", d_type);
1810
1776
  retval &= helper->saveData("opponent_id", d_opponent_id);
1811
1777
  retval &= helper->saveData("amount", d_amount);
1812
 
  retval &= helper->closeTag();
1813
1778
 
1814
1779
  return retval;
1815
1780
}
1820
1785
  d_amount = amount;
1821
1786
  return true;
1822
1787
}
 
1788
 
 
1789
//-----------------------------------------------------------------------------
 
1790
//Action_EndTurn
 
1791
 
 
1792
Action_EndTurn::Action_EndTurn()
 
1793
:Action(Action::END_TURN)
 
1794
{
 
1795
}
 
1796
 
 
1797
Action_EndTurn::Action_EndTurn(XML_Helper* helper)
 
1798
:Action(helper)
 
1799
{
 
1800
}
 
1801
 
 
1802
Action_EndTurn::~Action_EndTurn()
 
1803
{
 
1804
}
 
1805
 
 
1806
std::string Action_EndTurn::dump() const
 
1807
{
 
1808
  return "ending turn\n";
 
1809
}
 
1810
 
 
1811
bool Action_EndTurn::doSave(XML_Helper* helper) const
 
1812
{
 
1813
  bool retval = true;
 
1814
 
 
1815
  return retval;
 
1816
}
 
1817
 
 
1818
//-----------------------------------------------------------------------------
 
1819
//Action_ConquerCity
 
1820
 
 
1821
Action_ConquerCity::Action_ConquerCity()
 
1822
  :Action(Action::CITY_CONQUER), d_city(0), d_stack(0)
 
1823
{
 
1824
}
 
1825
 
 
1826
Action_ConquerCity::Action_ConquerCity(XML_Helper* helper)
 
1827
  :Action(helper)
 
1828
{
 
1829
    helper->getData(d_city, "city");
 
1830
    helper->getData(d_stack, "stack");
 
1831
}
 
1832
 
 
1833
Action_ConquerCity::~Action_ConquerCity()
 
1834
{
 
1835
}
 
1836
 
 
1837
std::string Action_ConquerCity::dump() const
 
1838
{
 
1839
    std::stringstream s;
 
1840
 
 
1841
    s <<"City " <<d_city <<" occupied by " << d_stack << "\n";
 
1842
 
 
1843
    return s.str();
 
1844
}
 
1845
 
 
1846
bool Action_ConquerCity::doSave(XML_Helper* helper) const
 
1847
{
 
1848
    bool retval = true;
 
1849
 
 
1850
    retval &= helper->saveData("city", d_city);
 
1851
    retval &= helper->saveData("stack", d_stack);
 
1852
 
 
1853
    return retval;
 
1854
}
 
1855
 
 
1856
bool Action_ConquerCity::fillData(City* c, Stack *s)
 
1857
{
 
1858
    d_city = c->getId();
 
1859
    d_stack = s->getId();
 
1860
    return true;
 
1861
}
 
1862
 
 
1863
//-----------------------------------------------------------------------------
 
1864
//Action_RecruitHero
 
1865
 
 
1866
Action_RecruitHero::Action_RecruitHero()
 
1867
  :Action(Action::RECRUIT_HERO), d_hero(0)
 
1868
{
 
1869
}
 
1870
 
 
1871
Action_RecruitHero::Action_RecruitHero(XML_Helper* helper)
 
1872
  :Action(helper)
 
1873
{
 
1874
    helper->getData(d_city, "city");
 
1875
    helper->getData(d_cost, "cost");
 
1876
    helper->getData(d_allies, "allies");
 
1877
    helper->getData(d_ally_army_type, "ally_army_type");
 
1878
    helper->registerTag("hero", sigc::mem_fun(this, &Action_RecruitHero::load));
 
1879
}
 
1880
 
 
1881
bool Action_RecruitHero::load(std::string tag, XML_Helper *helper)
 
1882
{
 
1883
    if (tag == "hero")
 
1884
      {
 
1885
        d_hero = new Hero(helper);
 
1886
 
 
1887
        return true;
 
1888
      }
 
1889
    return false;
 
1890
}
 
1891
 
 
1892
Action_RecruitHero::~Action_RecruitHero()
 
1893
{
 
1894
}
 
1895
 
 
1896
std::string Action_RecruitHero::dump() const
 
1897
{
 
1898
    std::stringstream s;
 
1899
 
 
1900
    s << "Hero " << d_hero->getId() << " recruited with " << d_allies << "allies\n";
 
1901
 
 
1902
    return s.str();
 
1903
}
 
1904
 
 
1905
bool Action_RecruitHero::doSave(XML_Helper* helper) const
 
1906
{
 
1907
    bool retval = true;
 
1908
 
 
1909
    retval &= helper->saveData("city", d_city);
 
1910
    retval &= helper->saveData("cost", d_cost);
 
1911
    retval &= helper->saveData("allies", d_allies);
 
1912
    retval &= helper->saveData("ally_army_type", d_ally_army_type);
 
1913
    retval &= d_hero->save(helper);
 
1914
 
 
1915
    return retval;
 
1916
}
 
1917
 
 
1918
bool Action_RecruitHero::fillData(Hero* hero, City *city, int cost, int alliesCount, const Army *ally)
 
1919
{
 
1920
    d_hero = hero;
 
1921
    d_city = city->getId();
 
1922
    d_cost = cost;
 
1923
    d_allies = alliesCount;
 
1924
    if (alliesCount > 0)
 
1925
      d_ally_army_type = ally->getType();
 
1926
    else
 
1927
      d_ally_army_type = 0;
 
1928
    return true;
 
1929
}