?? gameobject.java
字號:
if(go.myID > ID)
return null; //It isn't in the list (trust me ;)
GameObjects.goNext();
}
return null; //ID is higher than highest ID.
}
/** GameObject scanner! Finds the nearest living enemy. If none is within weapon range, return null
* Will ignore destroyable neutrals (i.e. breakable obstacles like trees)
* @return The nearest living enemy GameObject, or null
*/
protected GameObject scan() {
SelfSortingMutualDistanceSquared SSMDS = firstSSMDS;
GameObject go;
while(true) {
if(SSMDS == null)
return null;
if(SSMDS.getDistanceSquared() > scanRangeSquared())
return null;
go = SSMDS.getOther(this);
if(validTarget(go))
return go;
SSMDS = SSMDS.getNext(this);
}
}
/** Target validation. If a target meets this criteria it can be acquired by scan().
* This had to be separated so Units with non-standard functions (healing, stun)
* can override the normal target acquisition rules.
*/
protected boolean validTarget(GameObject go) {
return (go.myPlayer != null && go.myPlayer != myPlayer && go.damageable());
}
/** Accessor for ID.
* @return This GameObject's unique ID number.
*/
public int getID() {
return myID;
}
/** Accessor for Player
* @return This GameObject's Player (should be null for neutrals)
*/
public Player getPlayer() {
return myPlayer;
}
/** Accessor for vr[0].
* @return The location of the ground-center of the GameObject, in game-space.
*/
public Point3D locate() {
return vr[0];
}
/** Clear the current long-term goal.*/
public abstract void setGoal();
/** Set the current long-term goal to a location, at hex coordinate (gx, gy).
* @param gx The x coordinate of the goal, in hex coords.
* @param gy The y coordinate of the goal, in hex coords.
*/
public abstract void setGoal(int gx, int gy);
/** Set the current long-term goal to a GameObject.
* @param u The GameObject which is the goal.
*/
public abstract void setGoal(GameObject u);
/** Called by the game cycle update system to cause all GameObjects to
* perform one time-step of animations and decision making.
* This calls update() on each GameObject in the GameObjects Vector.
*/
public static void updateAll() {
GameObjects.goFirst();
while(GameObjects.isInList()) {
((GameObject)GameObjects.get()).update();
GameObjects.goNext();
}
}
//The remaining methods are intended to be over-rided by sub-classes of GameObject.
/** Perform operations for this time step.
* Specifically, perform the Point3D transforms for any/all animations,
* fire at an enemy if possible, and do any required decision making.
*/
protected abstract void update();
/** Returns the number of frames of animation for the creation sequence.
* @return The number of frames needed to animate creation.
*/
protected abstract int framesToMake();
/** Returns the number of frames of animation for the death sequence.
* @return The number of frames needed to animate death.
*/
protected abstract int framesToDie();
/** Initialize the Point3Ds used for this Base.
* These are the location of the ground-center of the Base in game-space, and
* the relative locations of the triangle/line vertices relative to that point.
*/
protected void createVectors() {
vr = new Point3D[1];
vr[0] = Hex.getMapPoint(x,y);
}
/** Draw this GameObject onto GameViewer v, by using v's drawing methods.
* @param v The GameViewer which will display this GameObject.
* @see netwar.gui.HexViewer
*/
public abstract void draw(GameViewer v);
/** Perform the data changes for one frame of animation while being made.*/
/** Requests that the GraphicThing(s) used by this object be added to GameViewer v.
* @param v The GameViewer which will be displaying the object.
*/
public void addTo(GameViewer v) {}
protected abstract void animateMake();
/** Perform the data changes for one frame of animation while dying.*/
protected abstract void animateDie();
/** Return the height of this GameObject for selection box and explosion hit calculations.
* @return The height of the GameObject in game-space units.
*/
public abstract float getHeight();
/** Return the width of this GameObject for selection box and explosion hit calculations.
* @return The width of the GameObject in game-space units.
*/
public abstract float getWidth();
/** Return the square of the maximum weapon range of this GameObject.
* @return The square of the weapons range in game-space units.
*/
public abstract float weaponRangeSquared();
/** Determines the distance to scan for nearby enemies.
* By default the range is equal to the weapon range.
* If it is higher, a Unit can detect a distant enemy and close the
* gap in order to fire.
* @return The square of the distance to scan for nearby enemies.
*/
public float scanRangeSquared() { return weaponRangeSquared(); }
/** Return the number of frames to wait between firing shots.
*/
public abstract int weaponDelay();
/**If a turret is available, rotate it toward the target.
* @return true iff the target is within the firing arc.
*/
protected abstract boolean aim();
//Fire a shot. Return true if you did. Default version is for unarmed things.
/** Attempt to fire a shot at the target.
* @return true iff the shot was successfully fired.
*/
protected boolean fire() {
return false;
}
/** Arbitrary initialization. Called by newGameObject() with a passed in parameter.
* param p An integer which may be used or ignored by the GameObject, as needed.
*/
protected void param(int p) {
return;
}
/** Get the Color for displaying this object on the minimap.
* GameObjects are displayed as single pixels on the minimap, so
* a Color is sufficient to draw them.
* @return Unless overridden, this returns Color.orange.darker() for neutrals, Team Color for non-neutrals.
*/
public Color getMinimapColor() {
//return teamcolor;
if(myPlayer == null)
return Color.orange.darker();
else
return myPlayer.getColor();
}
/** Return true if the object is not a valid target for attacks nor following.
* This is always true for indestructable obstacles.
* Otherwise, it is true only when the Unit/obstacle is destroyed.
* This is necessary to allow a GameObject to become completely dereferenced.
* @return True iff the unit is destroyed or it is both immobile and indestructable.
*/
public boolean isDead() {
return true;
}
/** Return true if an explosion can possibly damage this object.
* @return True iff the object is damageable.
*/
public boolean damageable() {
return false;
}
/** Return true if a healer can possibly restore life to the object.
* @return True iff the object is repairable.
*/
public boolean repairable() {
return false;
}
/** Return true if a paralyzing weapon can possibly stun this object.
* @return True iff the object is paralyzable.
*/
public boolean paralyzable() {
return false;
}
/** Apply damage to this object. A GameObject can apply its own rules for
* taking damage. The 'standard' is to track a health integer, which is
* reduced by (dam - armor) for each hit, with a minimum loss of 1 per hit.
* Healing effects call this method with a negative parameter.
* @param dam The number of damage points to be inflicted.
*/
public void recieveDamage(int dam) {}
/** Apply stun effects to this object. A GameObject can apply its own rules for
* being stunned. The 'standard' is to skip a number of updates equal to the
* level of paralysis.
* @param level The strength of the paralyzer.
*/
public void recieveParalysis(int level) {}
/** Cause the HexViewer's view to be centered on this GameObject. */
public void center(Transform t) {
Point2D pt = t.getPoint2D(vr[0]);
t.translate(t.maxX() / 2 - (int)pt.x, t.maxY() / 2 - (int)pt.y);
}
/** Returns the cost to build this object.
* Non-buildable objects have a cost of zero.
* @return The cost of the object.
*/
public int cost() {
return 0;
}
/** A String[] that holds all the propery names of this object. (in order) Capitalized to remind the programmer to return a static final String[]
* @return */
abstract protected String[] PROPERTIES();
/** returns a String for the <CODE>p</CODE>th property of this object.
*/
abstract protected String getProperty(int p);
/** Returns the property of this object, named by the <CODE>p</CODE> argument.
* @throws Exception When the property is not found.
*/
public final String GetProperty(String p) throws Exception {
for(int t = 0; t < PROPERTIES().length ; t++) {
if(PROPERTIES()[t].equals(p))
return getProperty(t);
}
throw new Exception(getClass().getName() + " class does not have the property " + p);
}
/** Returns an array of arrays of the properties of this object. [0][] is the property name, [1][] is the property's value.
*/
public final String[][] getProperties() {
String[][] ret = new String[2][PROPERTIES().length];
for(int t = 0; t < PROPERTIES().length ; t++ ) {
ret[0][t] = PROPERTIES()[t];
ret[1][t] = getProperty(t);
}
return ret;
}
/** Eliminates the visibility of a GameObject.
* This is added only for the mapper.
*/
public abstract void killGraphics();
/** Return health or other status indicator as a fraction.
* 0 = Dead. 1 = Full health
* @return a value from 0 to 1 indicating healthiness.
*/
public float getStatusFraction() {
return 1.0f;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -