Example #1
0
const PointVec Knight::CalcAction()
{
    PointVec points;
    points.push_back(Point(mCurPos.GetX()-1, mCurPos.GetY()));
    points.push_back(Point(mCurPos.GetX()+1, mCurPos.GetY()));
    points.push_back(Point(mCurPos.GetX(), mCurPos.GetY()-1));
    points.push_back(Point(mCurPos.GetX(), mCurPos.GetY()+1));
    return points;
}
Example #2
0
 DnaPolygon()  {
     vertex_.push_back(DnaPoint(RangeRand(Settings::ScreenWidth), 
                                RangeRand(Settings::ScreenHeight)));
     vertex_.push_back(DnaPoint(RangeRand(Settings::ScreenWidth), 
                                RangeRand(Settings::ScreenHeight)));
     vertex_.push_back(DnaPoint(RangeRand(Settings::ScreenWidth), 
                                RangeRand(Settings::ScreenHeight)));
     Color(R255, R255, R255);
     Alpha(IntervalRand(Settings::AlphaMin, Settings::AlphaMax));
 }
Example #3
0
const PointVec Healer::CalcAction()
{
    PointVec points;
    points.push_back(Point(mCurPos.GetX()-1, mCurPos.GetY()));
    points.push_back(Point(mCurPos.GetX()+1, mCurPos.GetY()));
    points.push_back(Point(mCurPos.GetX(), mCurPos.GetY()-1));
    points.push_back(Point(mCurPos.GetX(), mCurPos.GetY()+1));
    if(mCurHP < mMaxHP)
    {
        points.push_back(Point(mCurPos.GetX(), mCurPos.GetY()));
    }
    return points;
}
            void Single::_storeBorder(const GEOMETRY::Point<uint32>& pos, PointVec<uint32>& borderTiles, sl::Bitset2D& bitset)
            {
                for (uint32 i = 0; i < 8; ++i)
                {
                    try
                    {
                        auto mapTileInfo = m_Layer.getBorderTileInfo(pos, static_cast<BorderTile>(i));
                        // resize bitset if needed
                        bitset.resize(std::max(bitset.getWidth(), pos.getX() + mapTileInfo.getPosition().getX() + 1),
                            std::max(bitset.getHeight(), pos.getY() + mapTileInfo.getPosition().getY() + 1));
                        if (bitset.get(mapTileInfo.getPosition()))
                            continue;
                        bitset.set(mapTileInfo.getPosition());

                        if (mapTileInfo.isValid() && mapTileInfo.isAutoTile())
                            borderTiles.push_back(mapTileInfo.getPosition());
                    }
                    catch (const EXCEPTION::TileOutOfRangeException&) {}
                }
            }
            void Single::_do(const MapTileInfo& info, MapTileInfoVec& tiles, PointVec<uint32>& borderTiles)
            {
                // first set complete brush size -> bitset is checked
                sl::Bitset2D bitset;
                for (GEOMETRY::Point<uint32> pos; pos.getX() < getBrushSize().getWidth(); ++pos.getX())
                {
                    for (pos.getY() = 0; pos.getY() < getBrushSize().getHeight(); ++pos.getY())
                    {
                        try
                        {
                            auto mapTileInfo = m_Layer.getMapTile(pos + getStartPosition());
                            tiles.push_back(mapTileInfo);
                            if (pos.getX() == 0 || pos.getX() + 1 == getBrushSize().getWidth())
                            {
                                if (pos.getY() == 0 || pos.getY() + 1 == getBrushSize().getHeight())
                                    borderTiles.push_back(mapTileInfo.getPosition());
                            }

                            // resize bitset if needed
                            bitset.resize(std::max(bitset.getWidth(), pos.getX() + mapTileInfo.getPosition().getX() + 1),
                                std::max(bitset.getHeight(), pos.getY() + mapTileInfo.getPosition().getY() + 1));

                            bitset.set(pos + mapTileInfo.getPosition());
                        }
                        catch (const EXCEPTION::TileOutOfRangeException&) {}
                    }
                }

                // after that, we can really check borders
                for (GEOMETRY::Point<uint32> pos; pos.getX() < getBrushSize().getWidth(); ++pos.getX())
                {
                    for (pos.getY() = 0; pos.getY() < getBrushSize().getHeight(); ++pos.getY())
                        _storeBorder(getStartPosition() + pos, borderTiles, bitset);
                }
                
            }
Example #6
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;
}
Example #7
0
const PointVec Map::GetMovementRange( const vector<Character*> & everyone, const vector<Character*> & enemies, Character* guy)
{
    Node* nodes = new Node[mTiles.size()];
    Node* checked = new Node[mTiles.size()];
    PointVec possiblepoints;
    int maxMove = 0;
    for(vector<Character*>::const_iterator citer = everyone.begin(); citer != everyone.end(); citer++)
    {
        if(((*citer)->GetAttr(Character::AGI)/2) > maxMove)
        {
            maxMove = (*citer)->GetAttr(Character::AGI)/2;
        }
    }
    maxMove = maxMove+10;
    Node something;
    int b = 0;
    for(TileVec::iterator iter = mTiles.begin(); iter != mTiles.end(); iter++)
    {
        if((*iter).GetType().compare("ROCK") == 0)
        {
            something.weight = maxMove;
        }
        else
        {
            something.weight = (*iter).GetWeight();
        }
        something.p = (*iter).GetPoint();
        something.pathweight = -1;
        something.checked = false;
        nodes[b] = something;
        b++;
    }
    for(vector<Character*>::const_iterator citer = enemies.begin(); citer != enemies.end(); citer++)
    {
        if(!((*citer)->IsDead()))
        {
            nodes[(*citer)->GetPoint().GetX()*mMaxX + (*citer)->GetPoint().GetY()].weight = maxMove;
        }
    }
    nodes[guy->GetPoint().GetX()*mMaxX + guy->GetPoint().GetY()].pathweight = 0;
    nodes[guy->GetPoint().GetX()*mMaxX + guy->GetPoint().GetY()].checked = true;
    Node currentNode = nodes[guy->GetPoint().GetX()*mMaxX + guy->GetPoint().GetY()];
    checked[0] = currentNode;
    int indexed = 2;
    for(int i = 0; i < (int)mTiles.size(); i++)
    {
        indexed = indexed - 1;
        int up;
        int down;
        if(checked[i].p.GetY() == 0)
        {
            up = -1;
        }
        else
        {
            up =  ((checked[i].p.GetX())*mMaxX + checked[i].p.GetY() - 1);
        }
        if(checked[i].p.GetY() == mMaxY-1)
        {
            down = mTiles.size();
        }
        else
        {
            down = ((checked[i].p.GetX())*mMaxX + checked[i].p.GetY() + 1);
        }
        int curpathweight =nodes[((checked[i].p.GetX())*mMaxX + checked[i].p.GetY())].pathweight;
        int left =  ((checked[i].p.GetX())*mMaxX + checked[i].p.GetY() - mMaxX);
        int right =  ((checked[i].p.GetX())*mMaxX + checked[i].p.GetY() + mMaxX);
        if(up >= 0)
        {
            if(((curpathweight + nodes[up].weight) < nodes[up].pathweight) || ((curpathweight + nodes[up].weight) > 0 && nodes[up].pathweight == -1))
            {
                int needknow = nodes[up].pathweight;
                nodes[up].pathweight = curpathweight + nodes[up].weight;
                needknow = nodes[up].pathweight;
                nodes[up].lp = checked[i].p;
                if(nodes[up].checked == false)
                {
                    nodes[up].checked = true;
                    checked[i + indexed] = nodes[up];
                    indexed++;
                }
            }
        }
        if(down < (int)mTiles.size())
        {
            if(((curpathweight + nodes[down].weight) < nodes[down].pathweight) || ((curpathweight + nodes[down].weight) > 0 && nodes[down].pathweight == -1))
            {
                int needknow = nodes[down].weight;
                nodes[down].pathweight = curpathweight + nodes[down].weight;
                needknow = nodes[down].pathweight;
                nodes[down].lp = checked[i].p;
                if(nodes[down].checked == false)
                {
                    nodes[down].checked = true;
                    checked[i + indexed] = nodes[down];
                    indexed++;
                }
            }

        }
        if(left >= 0)
        {
            if(((curpathweight + nodes[left].weight) < nodes[left].pathweight) || ((curpathweight + nodes[left].weight) > 0 && nodes[left].pathweight == -1))
            {
                int needknow = nodes[left].pathweight;
                nodes[left].pathweight = curpathweight + nodes[left].weight;
                needknow = nodes[left].pathweight;
                nodes[left].lp = checked[i].p;
                if(nodes[left].checked == false)
                {
                    nodes[left].checked = true;
                    checked[i + indexed] = nodes[left];
                    indexed++;
                }
            }
        }
        if(right < (int)mTiles.size())
        {
            if(((curpathweight + nodes[right].weight) < nodes[right].pathweight) || ((curpathweight + nodes[right].weight) > 0 && nodes[right].pathweight == -1))
            {
                int needknow = nodes[right].pathweight;
                nodes[right].pathweight = curpathweight + nodes[right].weight;
                needknow = nodes[right].pathweight;
                nodes[right].lp = checked[i].p;
                if(nodes[right].checked == false)
                {
                    nodes[right].checked = true;
                    checked[i + indexed] = nodes[right];
                    indexed++;
                }
            }
        }
    }
    cout << "Character Move: " << guy->GetAttr(Character::AGI)/2 << endl;
    for(int i = 0; i < (int)mTiles.size(); i++)
    {
        if(nodes[i].pathweight <= (guy->GetAttr(Character::AGI)/2))
        {
            bool valid = true;
            for(vector<Character*>::const_iterator eiter = everyone.begin(); eiter != everyone.end(); eiter++)
            {
                if(nodes[i].p == (*eiter)->GetPoint() && nodes[i].p != guy->GetPoint())
                {
                    valid = false;
                }
            }
            if(valid)
            {
                possiblepoints.push_back(nodes[i].p);
            }
        }
    }

    delete[] nodes;
    delete[] checked;

    return possiblepoints;

}