void Colosseum::pushAllVillains(int r, int c, int dir) { // pushes all villains at [r,c] in the given direction // Note that if r,c isn't a valid location, this will // do nothing. We could instead have checked // to see if it's in range, and skipped the loop // in that case. // (or we could do bounds checking before calling, etc) for (int k = m_nVillains-1; k >= 0; k--) { Villain* vp = m_villains[k]; if( vp->row() == r && vp->col() == c ) { vp->push( dir ); if (vp->isDead()) { delete vp; // The order of Villain pointers in the m_villains array is // irrelevant, so it's easiest to move the last pointer to // replace the one pointing to the now-deleted villain. Since // we are traversing the array from last to first, we know this // last pointer does not point to a dead villain. m_villains[k] = m_villains[m_nVillains-1]; m_nVillains--; } } } }
int Colosseum::numberOfVillainsAt(int r, int c) const { int count = 0; for (int k = 0; k < m_nVillains; k++) { Villain* vp = m_villains[k]; if (vp->row() == r && vp->col() == c) count++; } return count; }
int Colosseum::numberOfVillainsAt(int r, int c) const { //This function keeps track of the number of villains at each grid position (r, c) int countVillains = 0; //Counter to keep track of number of villains for (int i = 0; i < m_nVillains; i++) //Check each spot until we reach the total amount of villains in the game { Villain* vp = m_villains[i]; if (vp->row() == r && vp -> col() == c) countVillains++; } return countVillains; }
void Colosseum::moveVillains() { // Move all villains for (int k = m_nVillains-1; k >= 0; k--) { Villain* vp = m_villains[k]; vp->move(); if (m_player != NULL && vp->row() == m_player->row() && vp->col() == m_player->col()) m_player->setDead(); } // Another turn has been taken m_turns++; }
void VillageControl::launchAttack(Villain& villain, vector<Creature*> attackers) { optional<int> ransom; int hisGold = villain.collective->numResource(CollectiveResourceId::GOLD); if (villain.ransom && hisGold >= villain.ransom->second) ransom = max<int>(villain.ransom->second, (Random.getDouble(villain.ransom->first * 0.6, villain.ransom->first * 1.5)) * hisGold); villain.collective->addAttack(CollectiveAttack(getCollective(), attackers, ransom)); TeamId team = getCollective()->getTeams().createPersistent(attackers); getCollective()->getTeams().activate(team); getCollective()->freeTeamMembers(team); for (Creature* c : attackers) getCollective()->setTask(c, villain.getAttackTask(this)); attackSizes[team] = attackers.size(); }