I have a tile map each tile has its own class, each class is stored in a two dimensional array, one of the things I store in the Tile class is how many ships are present each ship is assigned a Unique number to identify it. If there are more then 1 ship in a given Tile the program knows what one you wish to move (I pass the identifying number to the function). I have this piece of code that is supposed to find this ship that the player clicked on a move it to where they clicked however it only ever moves the first ship in the vector.
Code:
vector<int>::iterator MoveShip = Tile[OldMouseMapX][OldMouseMapY]->ShipsHere.begin();
for(; *MoveShip < Tile[OldMouseMapX][OldMouseMapY]->ShipsHere.size();) {
if(Tile[OldMouseMapX][OldMouseMapY]->ShipsHere[*MoveShip] == IShipID) {
MoveShip = Tile[OldMouseMapX][OldMouseMapY]->ShipsHere.erase(MoveShip);
Tile[MouseMap(X)][MouseMap(Y)]->ShipsHere.push_back(*MoveShip);
}
else {
++MoveShip;
}
}
I know its passing along the right ship number and it is looping until it finds the ship but it will only ever move the first ship contained in the vector.