Ejemplo n.º 1
0
    bool AddPoint() {
        if (vertex_.size() == Settings::MaxPoints)
            return false;

        int idx = RangeRand(vertex_.size());
        PointIt it = vertex_.begin();
        std::advance(it, idx);
        vertex_.insert(it, DnaPoint(RangeRand(Settings::ScreenWidth), 
                                    RangeRand(Settings::ScreenHeight)));

        return true;
    }
Ejemplo n.º 2
0
//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;
}
Ejemplo n.º 3
0
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;
}