Archived
1
0

-Added method of verifiying if a NeighborBuilding was created during the current turn.

NeighborBuildings should only be used during the current turn.  References to them that are used later will not function.

Signed-off-by: Tony Grosinger <tony@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-09-15 13:41:48 -07:00
parent 500396b422
commit 77c93d6c2c
4 changed files with 35 additions and 3 deletions

View File

@ -1,6 +1,5 @@
package net.grosinger.nomads;
/**
* An array of NeigborBuildings will be given to a drone that is searching for
* the buildings it is near. This is typically done from the town center.
@ -8,6 +7,7 @@ package net.grosinger.nomads;
public class NeighborBuilding implements GameObject {
private String name;
private int turnCreated;
private int x;
private int y;
private Building building;
@ -27,6 +27,7 @@ public class NeighborBuilding implements GameObject {
this.y = y;
this.name = name;
this.building = building;
turnCreated = Nomads.turn;
}
@Override
@ -67,4 +68,15 @@ public class NeighborBuilding implements GameObject {
name = newName;
}
/**
* Checks to make sure the object was created this turn. Otherwise drones
* could save a reference to the object and use it from anywhere on the map.
*
* @return <code>boolean</code>
*/
protected boolean verifyObjectValidity() {
int currentTurn = Nomads.turn;
return currentTurn == turnCreated;
}
}

View File

@ -2,16 +2,24 @@ package net.grosinger.nomads;
import java.util.ArrayList;
/**
* A representation of a TownHall. Allows Drones to interact with this building.
*/
public class TownHall extends NeighborBuilding {
// TODO - Rewrite class to make more accessible to Drones
public TownHall(int x, int y, String name, Building building) {
super(x, y, name, building);
}
/**
* Will sell all items in inventory that are able to be sold to the Town
* Hall.
*
* @param inventory
* @param team
*/
public void cashInventory(ArrayList<GameObject> inventory, DroneTeam team) {
while (!inventory.isEmpty()) {
GameObject currentObject = inventory.get(0);
@ -26,7 +34,19 @@ public class TownHall extends NeighborBuilding {
}
}
/**
* Will generate a new objective for the drone that requests it.
*
* @param UID
* Depreciated and going away soon.
* @return <code>Point</code> Will return null if the NeighborBuilding was
* created in a previous turn.
*/
public Point requestNewObjective(String UID) {
if (verifyObjectValidity()) {
return Nomads.awesomeWorld.generateObjective(UID);
} else {
return null;
}
}
}