[customwars] r754 committed - Fix some CO methods. Return random String instead of the whole array. ...

1 view
Skip to first unread message

codesite...@google.com

unread,
Mar 25, 2011, 11:51:17 AM3/25/11
to customwar...@googlegroups.com
Revision: 754
Author: ace.stef
Date: Fri Mar 25 08:50:39 2011
Log: Fix some CO methods. Return random String instead of the whole
array. Add piercing vision for lin.
http://code.google.com/p/customwars/source/detail?r=754

Modified:
/trunk/v2/resources/res/plugin/dor/data/co/co.bsh
/trunk/v2/src/com/customwars/client/model/co/AbstractCO.java
/trunk/v2/src/com/customwars/client/model/co/BasicCO.java
/trunk/v2/src/com/customwars/client/model/co/CO.java
/trunk/v2/src/com/customwars/client/model/game/Game.java
/trunk/v2/src/com/customwars/client/model/gameobject/Unit.java
/trunk/v2/src/com/customwars/client/model/map/Map.java
/trunk/v2/src/com/customwars/client/script/Parameter.java
/trunk/v2/src/com/customwars/client/script/ScriptedCO.java

=======================================
--- /trunk/v2/resources/res/plugin/dor/data/co/co.bsh Wed Feb 23 09:46:07
2011
+++ /trunk/v2/resources/res/plugin/dor/data/co/co.bsh Fri Mar 25 08:50:39
2011
@@ -1,11 +1,13 @@
// CO scripts
// All method consists of 2 parts: <co name>_<method name>
// The syntax is based on Java, more info @
http://www.beanshell.org/manual/syntax.html
-
-// Methods that can be used:
-// Method name Available parameters
-// void power Game game
-// void superPower Game game
+// When a method is to be linked to a co simply prefix the method with the
co name in lower case.
+// The parameters are java objects that can be used within the method.
+// Use out.println("your text"); to print a message on the console.
+
+// Available CO methods:
+// Method name Parameters
+//
// int unitMovementHook Unit mover, int movement
// int getAttackBonusPercentage Unit attacker, Unit defender
// int getDefenseBonusPercentage Unit attacker, Unit defender
@@ -14,15 +16,12 @@
// int unitPriceHook int price
// int healRateHook int healRate
// int terrainDefenseHook int terrainDefenseBonus
-// int fireRangeHook int fireRange
-// int visionHook int vision
-// void dayStart Game game
-
- public void brenner_power() {
- for (Unit unit : game.activePlayer.army) {
- if(!unit.hasMaxHP()) unit.addHp(3);
- }
- }
+// int fireRangeHook int fireRange, Unit unit
+// int visionHook int vision, Unit unit
+// void dayStart Player player
+// void power Game game
+// void superPower Game game
+// bool piercingVision

public int brenner_getAttackBonusPercentage() {
if (power || attacker.isInCOZone())
@@ -37,6 +36,12 @@
else
return 100;
}
+
+ public void brenner_power() {
+ for (Unit unit : game.activePlayer.army) {
+ if(!unit.hasMaxHP()) unit.addHp(3);
+ }
+ }

public int caulder_getAttackBonusPercentage() {
if (power || attacker.isInCOZone())
@@ -53,7 +58,7 @@
}

public void caulder_dayStart() {
- for (Unit unit : game.activePlayer.army) {
+ for (Unit unit : player.army) {
if (unit.isInCOZone() && !unit.hasMaxHP()) {
unit.heal(5);
out.println("Caulder day start: Healed unit " + unit.stats.name
+ " hp+5");
@@ -86,7 +91,7 @@
}

public int gage_fireRangeHook() {
- if (power)
+ if (power && unit.isInDirect())
return fireRange + 2;
else
return fireRange;
@@ -123,8 +128,9 @@
}

public void greyfield_power() {
- for (Unit unit : game.activePlayer.army()) {
+ for (Unit unit : game.activePlayer.army) {
unit.resupply();
+ unit.setMaxConstructionMaterials();
}
}

@@ -150,11 +156,30 @@
}

public int isabella_fireRangeHook() {
- if (power)
+ if (power && unit.isInDirect())
return fireRange + 2;
else
return fireRange;
}
+
+ public int tabitha_getAttackBonusPercentage() {
+ if (power || attacker.isInCOZone()) {
+ return 150;
+ } else {
+ return 100;
+ }
+ }
+
+ public int tabitha_getDefenseBonusPercentage() {
+ if (power || defender.isInCOZone())
+ return 150;
+ else
+ return 100;
+ }
+
+ public void tabitha_power() {
+ // todo showLaunchRocketCursor
+ }

public int lin_getAttackBonusPercentage() {
if (power || attacker.isInCOZone()) {
@@ -181,11 +206,15 @@
}

public int lin_unitVisionHook() {
- if (power)
+ if (power && unit.isLand())
return vision + 2;
else
return vision;
}
+
+ public boolean lin_piercingVision() {
+ return power;
+ }

public int penny_getAttackBonusPercentage() {
if (power || attacker.isInCOZone())
@@ -231,7 +260,7 @@
}

public int tasha_unitMovementHook() {
- if (power)
+ if (power && unit.isAir())
return movement + 2;
else
return movement;
@@ -283,7 +312,7 @@
}

public int will_unitMovementHook() {
- if (power)
+ if (power && unit.isDirect())
return movement + 2;
else
return movement;
=======================================
--- /trunk/v2/src/com/customwars/client/model/co/AbstractCO.java Wed Feb 23
09:46:07 2011
+++ /trunk/v2/src/com/customwars/client/model/co/AbstractCO.java Fri Mar 25
08:50:39 2011
@@ -3,6 +3,7 @@
import com.customwars.client.App;
import com.customwars.client.model.fight.Defender;
import com.customwars.client.model.game.Game;
+import com.customwars.client.model.game.Player;
import com.customwars.client.model.gameobject.Unit;
import com.customwars.client.model.map.Location;
import com.customwars.client.model.map.TileMap;
@@ -119,7 +120,7 @@
}

@Override
- public void dayStart(Game game) {
+ public void dayStart(Player player) {
if (isPowerActive()) {
deActivatePower();
} else if (isSuperPowerActive()) {
@@ -255,18 +256,22 @@
}

@Override
- public String[] getQuotes() {
- return quotes;
+ public String getQuote() {
+ return getRandom(quotes);
}

@Override
- public String[] getVictory() {
- return victory;
+ public String getVictory() {
+ return getRandom(victory);
}

@Override
- public String[] getDefeat() {
- return defeat;
+ public String getDefeat() {
+ return getRandom(defeat);
+ }
+
+ private static String getRandom(String[] array) {
+ return array[((int) (Math.random() * array.length))];
}

@Override
=======================================
--- /trunk/v2/src/com/customwars/client/model/co/BasicCO.java Wed Feb 23
09:46:07 2011
+++ /trunk/v2/src/com/customwars/client/model/co/BasicCO.java Fri Mar 25
08:50:39 2011
@@ -1,6 +1,6 @@
package com.customwars.client.model.co;

-import com.customwars.client.model.game.Game;
+import com.customwars.client.model.game.Player;
import com.customwars.client.model.gameobject.Unit;

/**
@@ -35,8 +35,8 @@
// ------------------------------------------------

@Override
- public void dayStart(Game game) {
- super.dayStart(game);
+ public void dayStart(Player player) {
+ super.dayStart(player);
}

@Override
@@ -78,12 +78,12 @@
}

@Override
- public int fireRangeHook(int fireRange) {
+ public int fireRangeHook(Unit unit, int fireRange) {
return fireRange;
}

@Override
- public int unitVisionHook(int vision) {
+ public int unitVisionHook(Unit unit, int vision) {
return vision;
}

@@ -91,4 +91,9 @@
public int cityVisionHook(int vision) {
return vision;
}
-}
+
+ @Override
+ public boolean isPiercingVision() {
+ return false;
+ }
+}
=======================================
--- /trunk/v2/src/com/customwars/client/model/co/CO.java Wed Feb 23
09:46:07 2011
+++ /trunk/v2/src/com/customwars/client/model/co/CO.java Fri Mar 25
08:50:39 2011
@@ -2,6 +2,7 @@

import com.customwars.client.model.fight.Defender;
import com.customwars.client.model.game.Game;
+import com.customwars.client.model.game.Player;
import com.customwars.client.model.gameobject.Unit;
import com.customwars.client.model.map.Location;

@@ -20,7 +21,7 @@

void deActivateSuperPower();

- void dayStart(Game game);
+ void dayStart(Player player);

int getAttackBonusPercentage(Unit attacker, Unit defender);

@@ -38,9 +39,9 @@

int terrainDefenseHook(int terrainDefenseBonus);

- int fireRangeHook(int fireRange);
-
- int unitVisionHook(int vision);
+ int fireRangeHook(Unit unit, int fireRange);
+
+ int unitVisionHook(Unit unit, int vision);

int cityVisionHook(int vision);

@@ -125,22 +126,27 @@
int getMaxBars();

/**
- * @return a collection of quotes
+ * @return a random quote
*/
- String[] getQuotes();
+ String getQuote();

/**
- * @return a collection of possible victory strings
+ * @return a random victory strings
*/
- String[] getVictory();
+ String getVictory();

/**
- * @return a collection of possible defeat strings
+ * @return a random defeat string
*/
- String[] getDefeat();
+ String getDefeat();

/**
* @return The distance in tiles around a unit that covers the co zone..
*/
int getZoneRange();
-}
+
+ /**
+ * @return Can this CO see through hidden terrains.
+ */
+ boolean isPiercingVision();
+}
=======================================
--- /trunk/v2/src/com/customwars/client/model/game/Game.java Sun Mar 20
07:04:58 2011
+++ /trunk/v2/src/com/customwars/client/model/game/Game.java Fri Mar 25
08:50:39 2011
@@ -115,7 +115,7 @@
}

void startTurn(Player player) {
- player.getCO().dayStart(this);
+ player.getCO().dayStart(player);
destroyUnitsWithoutSupplies(player);
supplyUnitsAdjacentOfTransport(player);
super.startTurn(player);
=======================================
--- /trunk/v2/src/com/customwars/client/model/gameobject/Unit.java Sun Mar
20 13:51:30 2011
+++ /trunk/v2/src/com/customwars/client/model/gameobject/Unit.java Fri Mar
25 08:50:39 2011
@@ -607,6 +607,10 @@
availableWeapon.addAmmo(additionalAmmo);
}
}
+
+ public void setMaxConstructionMaterials() {
+ this.constructionMaterials = stats.maxConstructionMaterial;
+ }

public void setLocation(Location newLocation) {
Location oldLocation = this.location;
@@ -756,7 +760,7 @@
if (weapon != null) {
int minRange = weapon.getRange().getMinRange();
int maxRange = weapon.getRange().getMaxRange();
- int coMaxRange = owner.getCO().fireRangeHook(maxRange);
+ int coMaxRange = owner.getCO().fireRangeHook(this, maxRange);
return new Range(minRange, coMaxRange);
} else {
return Range.ZERO_RANGE;
=======================================
--- /trunk/v2/src/com/customwars/client/model/map/Map.java Mon Mar 21
08:15:29 2011
+++ /trunk/v2/src/com/customwars/client/model/map/Map.java Fri Mar 25
08:50:39 2011
@@ -2,6 +2,7 @@

import com.customwars.client.App;
import com.customwars.client.model.TurnHandler;
+import com.customwars.client.model.co.CO;
import com.customwars.client.model.fight.Attacker;
import com.customwars.client.model.fight.Defender;
import com.customwars.client.model.fight.Fight;
@@ -494,16 +495,18 @@
City city = getCityOn(t);

if (unit != null && unit.isAlliedWith(player)) {
+ CO co = unit.getOwner().getCO();
int visionBonus = getUnitVisionBonus(unit);
int vision = unit.getStats().getVision();
- int coVision = unit.getOwner().getCO().unitVisionHook(vision +
visionBonus);
- showLos(t, coVision);
+ int coVision = co.unitVisionHook(unit, vision + visionBonus);
+ showLos(t, coVision, co.isPiercingVision());
}

if (city != null && city.isAlliedWith(player)) {
+ CO co = city.getOwner().getCO();
int vision = city.getVision();
- int coVision = city.getOwner().getCO().cityVisionHook(vision);
- showLos(t, coVision);
+ int coVision = co.cityVisionHook(vision);
+ showLos(t, coVision, co.isPiercingVision());
}
}
}
@@ -524,10 +527,11 @@
/**
* Reveals all visible tiles within a vision range including the baseTile
*
- * @param baseTile The tile to show the line of sight around
- * @param vision The amount of tiles that have to be shown around the
baseTile in all directions
+ * @param baseTile The tile to show the line of sight around
+ * @param vision The amount of tiles that have to be shown
around the baseTile in all directions
+ * @param piercingVision Can the player see can see through hidden
terrains.
*/
- private void showLos(Tile baseTile, int vision) {
+ private void showLos(Tile baseTile, int vision, boolean piercingVision) {
int col = baseTile.getCol();
int row = baseTile.getRow();

@@ -539,16 +543,16 @@
{
for (int j = 0; j < i; j++) // for each tile within that layer
{
- clearFog(baseTile, getTile(col + i - j, row + j)); // bottom right
sector
- clearFog(baseTile, getTile(col - i + j, row - j)); // top left
sector
- clearFog(baseTile, getTile(col - j, row + i - j)); // bottom left
sector
- clearFog(baseTile, getTile(col + j, row - i + j)); // top right
sector
+ clearFog(baseTile, getTile(col + i - j, row + j), piercingVision);
// bottom right sector
+ clearFog(baseTile, getTile(col - i + j, row - j), piercingVision);
// top left sector
+ clearFog(baseTile, getTile(col - j, row + i - j), piercingVision);
// bottom left sector
+ clearFog(baseTile, getTile(col + j, row - i + j), piercingVision);
// top right sector
}
}
}

- private void clearFog(Tile baseTile, Tile tile) {
- if (isValid(tile) && canClearFog(baseTile, tile)) {
+ private void clearFog(Tile baseTile, Tile tile, boolean piercingVision) {
+ if (isValid(tile) && canClearFog(baseTile, tile, piercingVision)) {
tile.setFogged(false);
}
}
@@ -558,18 +562,21 @@
* There are some terrains that remain fogged until directly next to the
baseTile.
* Hidden terrains can only be cleared of fog if the terrain is directly
next to the baseTile
*
- * @param tile A tile within vision range
- * @param baseTile The center of the vision range that is being cleared
+ * @param baseTile The center of the vision range that is being
cleared
+ * @param tile A tile within vision range
+ * @param piercingVision Can the player see through hidden terrains.
* @return If the tile should be cleared of fog.
*/
- private boolean canClearFog(Location baseTile, Tile tile) {
+ private boolean canClearFog(Location baseTile, Tile tile, boolean
piercingVision) {
Terrain terrain = tile.getTerrain();
boolean adjacent = isAdjacent(tile, baseTile);

- // If not hidden or directly next to the tile we can see everything
- return !terrain.isHidden() || adjacent;
- }
-
+ if (piercingVision && terrain.isHidden()) {
+ return true;
+ } else
+ // If not hidden or directly next to the tile we can see everything
+ return !terrain.isHidden() || adjacent;
+ }

/**
* Normalise this map
=======================================
--- /trunk/v2/src/com/customwars/client/script/Parameter.java Tue Apr 27
15:47:17 2010
+++ /trunk/v2/src/com/customwars/client/script/Parameter.java Fri Mar 25
08:50:39 2011
@@ -1,7 +1,7 @@
package com.customwars.client.script;

/**
- * A single parameter of a scripted method
+ * A single parameter with a name and a value of type T.
*/
public class Parameter<T> {
private final String name;
@@ -19,4 +19,9 @@
public T getValue() {
return value;
}
-}
+
+ @Override
+ public String toString() {
+ return name + "->" + value;
+ }
+}
=======================================
--- /trunk/v2/src/com/customwars/client/script/ScriptedCO.java Wed Feb 23
09:46:07 2011
+++ /trunk/v2/src/com/customwars/client/script/ScriptedCO.java Fri Mar 25
08:50:39 2011
@@ -4,6 +4,7 @@
import com.customwars.client.model.co.BasicCO;
import com.customwars.client.model.co.CO;
import com.customwars.client.model.game.Game;
+import com.customwars.client.model.game.Player;
import com.customwars.client.model.gameobject.Unit;
import org.apache.log4j.Logger;

@@ -163,24 +164,28 @@
}

@Override
- public int fireRangeHook(int fireRange) {
+ public int fireRangeHook(Unit unit, int fireRange) {
String methodName = getName() + "_fireRangeHook";

if (scriptManager.isMethod(methodName)) {
- return (Integer) scriptManager.invoke(methodName, new
Parameter<Integer>("fireRange", fireRange));
+ return (Integer) scriptManager.invoke(methodName,
+ new Parameter<Unit>("unit", unit),
+ new Parameter<Integer>("fireRange", fireRange));
} else {
- return super.fireRangeHook(fireRange);
+ return super.fireRangeHook(unit, fireRange);
}
}

@Override
- public int unitVisionHook(int vision) {
+ public int unitVisionHook(Unit unit, int vision) {
String methodName = getName() + "_unitVisionHook";

if (scriptManager.isMethod(methodName)) {
- return (Integer) scriptManager.invoke(methodName, new
Parameter<Integer>("vision", vision));
+ return (Integer) scriptManager.invoke(methodName,
+ new Parameter<Unit>("unit", unit),
+ new Parameter<Integer>("vision", vision));
} else {
- return super.unitVisionHook(vision);
+ return super.unitVisionHook(unit, vision);
}
}

@@ -196,12 +201,23 @@
}

@Override
- public void dayStart(Game game) {
- super.dayStart(game);
+ public void dayStart(Player player) {
+ super.dayStart(player);
String methodName = getName() + "_dayStart";

if (scriptManager.isMethod(methodName)) {
- scriptManager.invoke(methodName, new Parameter<Game>("game", game));
+ scriptManager.invoke(methodName, new Parameter<Player>("player",
player));
+ }
+ }
+
+ @Override
+ public boolean isPiercingVision() {
+ String methodName = getName() + "_piercingVision";
+
+ if (scriptManager.isMethod(methodName)) {
+ return (Boolean) scriptManager.invoke(methodName);
+ } else {
+ return super.isPiercingVision();
}
}

Reply all
Reply to author
Forward
0 new messages