53
53
d_path = new Path();
56
Stack::Stack(Stack& s)
56
Stack::Stack(Uint32 id, Player* player, Vector<int> pos)
57
: UniquelyIdentified(id), Movable(pos), Ownable(player),
58
d_defending(false), d_parked(false), d_deleting(false)
63
Stack::Stack(const Stack& s)
57
64
: UniquelyIdentified(s), Movable(s), Ownable(s),
58
65
d_defending(s.d_defending), d_parked(s.d_parked), d_deleting(false)
61
68
d_path = new Path();
62
69
//deep copy the other stack's armies
64
for (iterator sit = s.begin(); sit != s.end(); sit++)
71
for (const_iterator sit = s.begin(); sit != s.end(); sit++)
68
73
if ((*sit)->isHero())
70
h = new Hero(dynamic_cast<Hero&>(**sit));
75
Army *h = new Hero(dynamic_cast<Hero&>(**sit));
75
a = new Army((**sit), (*sit)->getOwner());
80
Army *a = new Army((**sit), (*sit)->getOwner());
85
90
helper->getData(d_defending, "defending");
86
91
helper->getData(d_parked, "parked");
88
helper->registerTag("path", sigc::mem_fun((*this), &Stack::load));
89
helper->registerTag("army", sigc::mem_fun((*this), &Stack::load));
90
helper->registerTag("hero", sigc::mem_fun((*this), &Stack::load));
93
helper->registerTag(Path::d_tag, sigc::mem_fun((*this), &Stack::load));
94
helper->registerTag(Army::d_tag, sigc::mem_fun((*this), &Stack::load));
95
helper->registerTag(Hero::d_tag, sigc::mem_fun((*this), &Stack::load));
95
100
d_deleting = true;
107
113
(*it)->setOwner(p);
110
void Stack::moveOneStep()
116
void Stack::moveOneStep(bool skipping)
112
debug("move_one_step()");
118
debug("moveOneStep()");
114
120
Vector<int> dest = *getPath()->front();
121
moveToDest(dest, skipping);
117
123
//now remove first point of the path
118
124
d_path->eraseFirstPoint();
121
void Stack::moveToDest(Vector<int> dest)
127
bool Stack::isMovingToOrFromAShip(Vector<int> dest, bool &on_ship) const
123
129
Vector<int> pos = getPos();
125
Uint32 maptype = GameMap::getInstance()->getTile(dest.x,dest.y)->getMaptileType();
126
City* to_city = Citylist::getInstance()->getObjectAt(dest.x, dest.y);
127
City* on_city = Citylist::getInstance()->getObjectAt(pos.x, pos.y);
128
Port* on_port = Portlist::getInstance()->getObjectAt(pos.x, pos.y);
131
bool to_city = GameMap::getInstance()->getTile(dest)->getBuilding() == Maptile::CITY;
132
bool on_city = GameMap::getInstance()->getTile(pos)->getBuilding() == Maptile::CITY;
134
bool on_port = GameMap::getInstance()->getTile(pos)->getBuilding() == Maptile::PORT;
135
bool on_bridge = GameMap::getInstance()->getTile(pos)->getBuilding() == Maptile::BRIDGE;
136
bool to_bridge = GameMap::getInstance()->getTile(dest)->getBuilding() == Maptile::BRIDGE;
129
137
bool on_water = (GameMap::getInstance()->getTile(pos.x,pos.y)->getMaptileType() == Tile::WATER);
130
138
bool to_water = (GameMap::getInstance()->getTile(dest.x,dest.y)->getMaptileType() == Tile::WATER);
139
//here we mark the armies as being on or off a boat
140
/* skipping refers to when we have to move over another friendly stack
141
* of a size that's too big to join with. */
142
if ((on_water && to_city && !on_bridge) ||
143
(on_water && on_port && !to_water && on_ship) ||
144
((on_city || on_port) && to_water && !to_bridge) ||
145
(on_bridge && to_water && !to_bridge) ||
146
(on_bridge && !to_water && on_ship) ||
147
(on_water && to_water && !on_bridge && !on_port && !to_bridge &&
149
(!on_water && !to_water && on_ship == true))
157
void Stack::moveToDest(Vector<int> dest, bool skipping)
131
159
bool ship_load_unload = false;
132
//here we mark the armies as being on or off a boat
135
if ((on_water && to_city) ||
136
(on_water && on_port && !to_water) ||
137
((on_city || on_port) && to_water))
162
bool on_ship = hasShip();
163
if (isMovingToOrFromAShip(dest, on_ship) == true)
139
ship_load_unload = true;
140
for (Stack::iterator it = begin(); it != end(); it++)
143
((*it)->getStat(Army::MOVE_BONUS) & Tile::WATER) == 0)
144
(*it)->setInShip(true);
146
(*it)->setInShip(false);
167
ship_load_unload = true;
168
Vector<int> pos = getPos();
169
GameMap *gm = GameMap::getInstance();
170
bool to_water = (gm->getTile(dest.x,dest.y)->getMaptileType()
172
for (Stack::iterator it = begin(); it != end(); it++)
175
((*it)->getStat(Army::MOVE_BONUS) & Tile::WATER) == 0)
176
(*it)->setInShip(true);
178
(*it)->setInShip(false);
443
493
for (const_iterator it = begin(); it != end(); it++)
444
494
if ((*it)->isHero())
446
std::list<Item*> backpack = dynamic_cast<Hero*>((*it))->getBackpack();
447
std::list<Item*>::const_iterator item;
448
for (item = backpack.begin(); item != backpack.end(); item++)
450
if ((*item)->getBonus(Item::DOUBLEMOVESTACK))
451
movement_multiplier*=2;
496
Hero *hero = dynamic_cast<Hero*>(*it);
497
Uint32 bonus = hero->getBackpack()->countMovementDoublers();
498
for (Uint32 i = 0; i < bonus; i++)
499
movement_multiplier*=2;
455
502
//set the multipler on all armies in the stack
456
503
for (const_iterator it = begin(); it != end(); it++)
457
504
(*it)->setStat(Army::MOVES_MULTIPLIER, movement_multiplier);
459
//now let's see if we have any items that give us gold per city
460
for (const_iterator it = begin(); it != end(); it++)
463
std::list<Item*> backpack = dynamic_cast<Hero*>((*it))->getBackpack();
464
std::list<Item*>::const_iterator item;
465
for (item = backpack.begin(); item != backpack.end(); item++)
468
if ((*item)->getBonus(Item::ADD2GOLDPERCITY))
469
p->addGold(2 * Citylist::getInstance()->countCities(p));
470
if ((*item)->getBonus(Item::ADD3GOLDPERCITY))
471
p->addGold(3 * Citylist::getInstance()->countCities(p));
472
if ((*item)->getBonus(Item::ADD4GOLDPERCITY))
473
p->addGold(4 * Citylist::getInstance()->countCities(p));
474
if ((*item)->getBonus(Item::ADD5GOLDPERCITY))
475
p->addGold(5 * Citylist::getInstance()->countCities(p));
478
506
if (d_defending == true)
479
507
setFortified(true);
481
509
for (iterator it = begin(); it != end(); ++it)
483
511
(*it)->resetMoves();
484
// TODO: should be moved in a more appropriate place => class Player
486
d_owner->withdrawGold((*it)->getUpkeep());
609
634
if ((*it)->isHero())
611
636
Hero *h = dynamic_cast<Hero*>(*it);
612
std::list<Item*> backpack = h->getBackpack();
613
std::list<Item*>::const_iterator item;
614
for (item = backpack.begin(); item != backpack.end(); item++)
637
if (h->getBackpack()->countStackFlightGivers() > 0)
616
if ((*item)->getBonus(Item::FLYSTACK))
618
d_bonus = Tile::GRASS | Tile::WATER | Tile::FOREST |
619
Tile::HILLS | Tile::MOUNTAIN | Tile::SWAMP;
639
d_bonus = Tile::isFlying();
679
697
std::list<Uint32> lhs_fight_order = lhs->getOwner()->getFightOrder();
680
698
std::list<Uint32> rhs_fight_order = rhs->getOwner()->getFightOrder();
681
Uint32 lhs_rank = getFightOrder (lhs_fight_order, lhs->getType());
682
Uint32 rhs_rank = getFightOrder (rhs_fight_order, rhs->getType());
683
//if (lhs_rank == rhs_rank)
684
//return lhs->getId() < rhs->getId();
699
Uint32 lhs_rank = getFightOrder (lhs_fight_order, lhs->getTypeId());
700
Uint32 rhs_rank = getFightOrder (rhs_fight_order, rhs->getTypeId());
685
701
return lhs_rank < rhs_rank;
809
825
Uint32 Stack::scout(Player *p, Vector<int> src, Vector<int> dest,
826
const ArmyProdBase *prodbase)
812
Stack *stack = new Stack(p, src);
815
proto = Armysetlist::getInstance()->getScout(p->getArmyset());
819
Army *army = new Army (*proto);
828
Stack *stack = Stack::createNonUniqueStack(p, src);
833
ArmyProto *proto = Armysetlist::getInstance()->getScout(p->getArmyset());
836
army = Army::createNonUniqueArmy (*proto, p);
839
army = Army::createNonUniqueArmy (*prodbase, p);
822
843
stack->push_back(army);
831
853
delete scout_stack;
857
Stack* Stack::createNonUniqueStack(Player *player, Vector<int> pos)
859
return new Stack(0, player, pos);
862
Uint32 Stack::getMaxGroupLandMoves() const
869
//copy the stack, reset the moves and return the group moves
870
Stack *copy = new Stack (*this);
871
if (copy->countGroupedArmies() == 0)
873
copy->decrementMoves(copy->getGroupMoves());
875
Uint32 moves = copy->getGroupMoves();
876
if (isFlying() == true)
882
//alright, we're not flying. what would our group moves be if we were on land
883
//remove ship status from all army units
884
copy->decrementMoves(copy->getGroupMoves());
885
for (Stack::iterator it = copy->begin(); it != copy->end(); it++)
886
(*it)->setInShip(false);
889
moves = copy->getGroupMoves();
894
Uint32 Stack::getMaxGroupBoatMoves() const
901
//copy the stack, reset the moves and return the group moves
902
Stack *copy = new Stack (*this);
903
if (copy->countGroupedArmies() == 0)
906
Uint32 moves = copy->getGroupMoves();
907
if (isFlying() == true)
912
//alright, we're not flying. what would our group moves be if we were on water?
913
copy->decrementMoves(copy->getGroupMoves());
915
for (Stack::iterator it = copy->begin(); it != copy->end(); it++)
917
if (((*it)->getStat(Army::MOVE_BONUS) & Tile::WATER) == 0)
918
(*it)->setInShip(true);
920
(*it)->setInShip(false);
924
moves = copy->getGroupMoves();