//Guy = AI unit, enemies = party const bool Map::AIAttackOrNot(const vector<Character*>& everyone , const vector<Character*>& enemies, Character* guy) { PointVec myMove = GetMovementRange(everyone, enemies, guy); Point storeMyPoint = guy->GetPoint(); PointVec myAttack; for(vector<Point>::iterator mpoint = myMove.begin(); mpoint != myMove.end(); mpoint++) { guy->Move((*mpoint)); PointVec temp = guy->CalcAction(); myAttack.insert( myAttack.end(), temp.begin(), temp.end() ); } guy->Move(storeMyPoint); for(vector<Point>::iterator mpoint = myAttack.begin(); mpoint != myAttack.end(); mpoint++) { if(guy->GetTarget()->GetPoint() == (*mpoint)) { return true; } } return false; }
void Render(Image &dest) const { int points = vertex_.size(); Sint16 x[points]; Sint16 y[points]; int i = 0; for ( PointVec::const_iterator it = vertex_.begin(); it != vertex_.end(); ++it, ++i) { x[i] = it->X(); y[i] = it->Y(); } dest.Polygon(x, y, points, color_); }
bool Mutate() { bool dirty = false; if (DoMutate(AddPointMutation)) dirty |= AddPoint(); if (DoMutate(DelPointMutation)) dirty |= DelPoint(); if (DoMutate(AlphaMutation)) dirty |= Alpha(IntervalRand(Settings::AlphaMin, Settings::AlphaMax)); if (DoMutate(ComponentMutation)) dirty |= RandomRed(); if (DoMutate(ComponentMutation)) dirty |= RandomGreen(); if (DoMutate(ComponentMutation)) dirty |= RandomBlue(); for (PointIt it = vertex_.begin(); it != vertex_.end(); ++it) dirty |= it->Mutate(); return dirty; }
const vector<Point> Map::AIGoWhere(const vector<Character*>& everyone, const vector<Character*>& enemies, const vector<Character*>& allies, Character* guy) { //Get my range PointVec myMove = GetMovementRange(everyone, enemies, guy); Point storeMyPoint = guy->GetPoint(); PointVec possibleChoice; if(guy->GetCharacterClassName() != "Healer") { for(vector<Point>::iterator mpoint = myMove.begin(); mpoint != myMove.end(); mpoint++) { guy->Move((*mpoint)); for(vector<Character*>::const_iterator citer = enemies.begin(); citer != enemies.end(); citer++) { PointVec temp = guy->CalcAction(); if( find( temp.begin(), temp.end(), (*citer)->GetPoint() ) != temp.end() ) { possibleChoice.push_back(guy->GetPoint()); guy->Move(storeMyPoint); return possibleChoice; } } } } guy->Move(storeMyPoint); PointVec theirMove; PointVec totalAttack; //iterate through all of party's members for(vector<Character*>::const_iterator citer = enemies.begin(); citer != enemies.end(); citer++) { if(!((*citer)->IsDead()))//if they are not dead then lets check their attack { theirMove = GetMovementRange(everyone, allies, (*citer)); //get their move Point storeTheirPoint = (*citer)->GetPoint(); //store their cur position //for all movement possibilities, calculate their attack. for(vector<Point>::iterator mpoint = theirMove.begin(); mpoint != theirMove.end(); mpoint++) { //store all points of attack (*citer)->Move(*mpoint); PointVec temp = (*citer)->CalcAction(); totalAttack.insert( totalAttack.end(), temp.begin(), temp.end() ); } (*citer)->Move(storeTheirPoint);//restore their position } } /*for(vector<Point>::iterator piter = totalAttack.begin(); piter != totalAttack.end(); piter++) { cout << (*piter).GetX() << ", " << (*piter).GetY() << endl; }*/ //cross reference my movement with theirs, return only points that they can't attack me on. for(vector<Point>::iterator piter = myMove.begin(); piter != myMove.end(); piter++) { bool ok = true; if( find( totalAttack.begin(), totalAttack.end(), *piter ) != totalAttack.end() ) { ok = false; } if(ok) { //std::cout << (*piter).GetX() << ", " << (*piter).GetY() << std::endl; possibleChoice.push_back((*piter)); totalAttack.push_back((*piter)); //hack to not store same points in return } } return possibleChoice; }