68
75
Stack *LocationBox::addArmy(Army *a) const
70
Stack* stack = getFreeStack(a->getOwner());
72
// No stack found in the entire location
78
if (stack->countGroupedArmies() == 0)
80
if (stack->size() > 1)
81
stack->sortForViewing(true);
82
stack->setDefending(false);
83
stack->setParked(false);
87
Stack* LocationBox::getFreeStack(Player *p) const
89
for (unsigned int i = 0; i < d_size; i++)
90
for (unsigned int j = 0; j < d_size; j++)
92
Stack* stack = Stacklist::getObjectAt(getPos().x + j,
98
temp.x = getPos().x + j;
99
temp.y = getPos().y + i;
100
stack = new Stack(p, temp);
104
else if (stack->size() < MAX_STACK_SIZE) return stack;
77
Vector<int> pos = Vector<int>(-1,-1);
78
Stack* stack = getFreeStack(a->getOwner(), pos);
80
//no stacks with enough room for one more army, found lets create one.
83
// No stack found in the entire location
84
if (pos == Vector<int>(-1,-1))
87
Player *p = a->getOwner();
88
stack = new Stack(p, pos);
95
if (stack->size() > 1)
96
stack->sortForViewing(true);
97
stack->setDefending(false);
98
stack->setParked(false);
102
bool LocationBox::isFull(Player *p) const
104
for (unsigned int i = 0; i < d_size; i++)
105
for (unsigned int j = 0; j < d_size; j++)
107
Vector<int> pos = getPos() + Vector<int>(j,i);
108
StackTile *stile = GameMap::getInstance()->getTile(pos)->getStacks();
109
if (stile->canAdd(1, p) == true)
115
Stack* LocationBox::getFreeStack(Player *p, Vector<int> &tile) const
117
for (unsigned int i = 0; i < d_size; i++)
118
for (unsigned int j = 0; j < d_size; j++)
120
Vector<int> pos = getPos() + Vector<int>(j,i);
121
if (GameMap::canAddArmy(pos) == false)
123
StackTile *stile = GameMap::getInstance()->getTile(pos)->getStacks();
124
Stack *stack = stile->getFriendlyStack(p);
132
Stack *enemy = stile->getEnemyStack(p);
133
if (!enemy && stack->isFull() == false)
137
tile = Vector<int>(-1,-1);
109
141
bool LocationBox::isVisible(Player *player) const
193
Vector<int> LocationBox::getNearestPos(Movable *m) const
195
return getNearestPos(m->getPos());
198
Vector<int> LocationBox::getNearestPos(Vector<int> pos) const
201
Vector<int> closest_tile = Vector<int>(-1,-1);
202
for (unsigned int i = 0; i < d_size; i++)
203
for (unsigned int j = 0; j < d_size; j++)
205
Vector<int> target = Vector<int>(i,j) + getPos();
206
int d = dist(pos, target);
207
if (d < min_dist || min_dist == -1)
210
closest_tile = target;