From: Hendrik <nh...@us...> - 2006-07-17 02:57:14
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv3697/src/games/stendhal/server Modified Files: RespawnPoint.java Log Message: use TurnNotifier instead of count-down in logic-loop. Index: RespawnPoint.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/RespawnPoint.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** RespawnPoint.java 20 Jun 2006 22:53:34 -0000 1.36 --- RespawnPoint.java 17 Jul 2006 02:57:11 -0000 1.37 *************** *** 15,63 **** import games.stendhal.common.Rand; import games.stendhal.server.entity.creature.Creature; import java.util.LinkedList; import java.util.List; import marauroa.common.Log4J; ! import marauroa.server.game.RPWorld; import org.apache.log4j.Logger; ! public class RespawnPoint { /** the logger instance. */ private static final Logger logger = Log4J.getLogger(RespawnPoint.class); ! private int x; - private int y; - private int maximum; - private Creature entity; - private List<Creature> entities; - private boolean respawning; - - final public static int TURNSTORESPAWN = 90; // Five minute at 300ms - private int respawnTime; - private int turnsToRespawn; - - /** - * Remember which turn we were called last to compute remaining respawn time - */ - private int lastTurn = 0; - - private StendhalRPZone zone; - - protected static StendhalRPRuleProcessor rp; - - protected static RPWorld world; - - public static void setRPContext(StendhalRPRuleProcessor rpContext, - RPWorld worldContext) { - rp = rpContext; - world = worldContext; - } - public RespawnPoint(int x, int y, int radius) { this.x = x; --- 15,41 ---- import games.stendhal.common.Rand; import games.stendhal.server.entity.creature.Creature; + import games.stendhal.server.events.TurnEvent; + import java.util.LinkedList; import java.util.List; + import marauroa.common.Log4J; ! import org.apache.log4j.Logger; ! public class RespawnPoint implements TurnEvent { ! private static final int TURNSTORESPAWN = 90; ! /** the logger instance. */ private static final Logger logger = Log4J.getLogger(RespawnPoint.class); ! private StendhalRPZone zone; private int x; private int y; private int maximum; private Creature entity; private List<Creature> entities; private boolean respawning; private int respawnTime; public RespawnPoint(int x, int y, int radius) { this.x = x; *************** *** 66,70 **** respawning = true; ! turnsToRespawn = 0; // respawn now respawnTime = TURNSTORESPAWN; } --- 44,48 ---- respawning = true; ! TurnNotifier.get().notifyInTurns(0, this); // respawn in next turn respawnTime = TURNSTORESPAWN; } *************** *** 83,89 **** public void notifyDead(Creature dead) { Log4J.startMethod(logger, "notifyDead"); if (!respawning) { respawning = true; ! turnsToRespawn = Rand.rand(respawnTime, respawnTime / 30); } --- 61,68 ---- public void notifyDead(Creature dead) { Log4J.startMethod(logger, "notifyDead"); + if (!respawning) { respawning = true; ! TurnNotifier.get().notifyInTurns(Rand.rand(respawnTime, respawnTime / 30), this); } *************** *** 92,128 **** } ! public void checkRespawn(int aktTurn) { ! Log4J.startMethod(logger, "checkRespawn"); ! if (respawning) { ! logger.debug("Turns to respawn: " + turnsToRespawn); ! ! if(lastTurn==0) { ! lastTurn = aktTurn - 1; ! } ! ! if (turnsToRespawn <= 0) { ! turnsToRespawn = respawnTime; ! ! respawn(); ! ! if (entities.size() == maximum) { ! respawning = false; ! } ! } ! ! turnsToRespawn -= aktTurn - lastTurn; ! } ! lastTurn = aktTurn; ! Log4J.finishMethod(logger, "checkRespawn"); ! } ! ! public void logic() { ! Log4J.startMethod(logger, "logic"); ! for (Creature creature : entities) { ! creature.logic(); } - - Log4J.finishMethod(logger, "logic"); } --- 71,83 ---- } ! public void onTurnReached(int currentTurn) { ! respawn(); ! // Is this all or should we spawn more creatures? ! if (entities.size() == maximum) { ! respawning = false; ! } else { ! TurnNotifier.get().notifyInTurns(Rand.rand(respawnTime, respawnTime / 30), this); } } *************** *** 160,162 **** --- 115,127 ---- } } + + public void logic() { + Log4J.startMethod(logger, "logic"); + + for (Creature creature : entities) { + creature.logic(); + } + + Log4J.finishMethod(logger, "logic"); + } } |