Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/creature
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv11841/src/games/stendhal/server/entity/creature
Modified Files:
Creature.java
Log Message:
Load creature sounds from xml and generate sound events for them
Index: Creature.java
===================================================================
RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/creature/Creature.java,v
retrieving revision 1.240
retrieving revision 1.241
diff -C2 -d -r1.240 -r1.241
*** Creature.java 10 Jul 2012 20:38:22 -0000 1.240
--- Creature.java 19 Jan 2013 20:22:32 -0000 1.241
***************
*** 16,19 ****
--- 16,20 ----
import games.stendhal.common.Rand;
import games.stendhal.common.constants.Nature;
+ import games.stendhal.common.constants.SoundLayer;
import games.stendhal.common.grammar.Grammar;
import games.stendhal.server.core.engine.GameEvent;
***************
*** 45,48 ****
--- 46,50 ----
import games.stendhal.server.entity.player.Player;
import games.stendhal.server.entity.slot.EntitySlot;
+ import games.stendhal.server.events.SoundEvent;
import games.stendhal.server.util.CounterMap;
***************
*** 84,88 ****
*/
private static final double SERVER_DROP_GENEROSITY = 1;
!
private HealerBehavior healer = HealerBehaviourFactory.get(null);
--- 86,103 ----
*/
private static final double SERVER_DROP_GENEROSITY = 1;
! /**
! * Probability of generating a sound event at each turn, if the creature has
! * specified sounds.
! */
! private static final int SOUND_PROBABILITY = 20;
! /**
! * Creature sound radius.
! */
! private static final int SOUND_RADIUS = 23;
! /**
! * Minimum delay in milliseconds between playing creature sounds.
! */
! private static final long SOUND_DEAD_TIME = 10000L;
!
private HealerBehavior healer = HealerBehaviourFactory.get(null);
***************
*** 101,104 ****
--- 116,123 ----
*/
protected List<Item> dropItemInstances;
+ /**
+ * Possible sound events.
+ */
+ private List<String> sounds;
/**
***************
*** 142,145 ****
--- 161,166 ----
private CounterMap<String> hitPlayers;
+ /** The time stamp of previous sound event. */
+ private long lastSoundTime;
/**
***************
*** 211,214 ****
--- 232,236 ----
setLevel(copy.getLevel());
+ setSounds(copy.sounds);
for (RPSlot slot : copy.slots()) {
***************
*** 334,337 ****
--- 356,368 ----
return new Creature(this);
}
+
+ /**
+ * Set the possible sound events.
+ *
+ * @param sounds sound name list
+ */
+ public void setSounds(List<String> sounds) {
+ this.sounds = new ArrayList<String>(sounds);
+ }
/**
***************
*** 817,820 ****
--- 848,852 ----
}
}
+ maybeMakeSound();
this.notifyWorldAboutChanges();
} else {
***************
*** 858,861 ****
--- 890,907 ----
}
}
+
+ /**
+ * Generate a sound event with the probability of SOUND_PROBABILITY, if
+ * the previous sound event happened long enough ago.
+ */
+ private void maybeMakeSound() {
+ if ((sounds != null) && !sounds.isEmpty() && (Rand.rand(100) < SOUND_PROBABILITY)) {
+ long time = System.currentTimeMillis();
+ if (lastSoundTime + SOUND_DEAD_TIME < time) {
+ lastSoundTime = time;
+ addEvent(new SoundEvent(Rand.rand(sounds), SOUND_RADIUS, 100, SoundLayer.CREATURE_NOISE));
+ }
+ }
+ }
public boolean hasTargetMoved() {
|