View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.analyzer;
2   
3   import java.io.File;
4   import java.io.PrintWriter;
5   
6   import com.google.inject.Inject;
7   
8   import cz.cuni.amis.pogamut.base.communication.command.IAct;
9   import cz.cuni.amis.pogamut.base.communication.worldview.event.IWorldEventListener;
10  import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObjectEventListener;
11  import cz.cuni.amis.pogamut.base.communication.worldview.object.event.WorldObjectUpdatedEvent;
12  import cz.cuni.amis.pogamut.base.component.bus.IComponentBus;
13  import cz.cuni.amis.pogamut.base.utils.logging.IAgentLogger;
14  import cz.cuni.amis.pogamut.base.utils.math.DistanceUtils;
15  import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
16  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.ConfigurationObserver;
17  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.InitializeObserver;
18  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AddInventoryMsg;
19  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AdrenalineGained;
20  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled;
21  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Bumped;
22  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ChangedWeapon;
23  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ComboStarted;
24  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.FallEdge;
25  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo;
26  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameRestarted;
27  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GlobalChat;
28  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.HearNoise;
29  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.HearPickup;
30  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.IncomingProjectile;
31  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ItemPickedUp;
32  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.JumpPerformed;
33  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Landed;
34  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.LostChild;
35  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.MyInventory;
36  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
37  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerDamaged;
38  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerJoinsGame;
39  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerKilled;
40  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerLeft;
41  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerScore;
42  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.RecordingEnded;
43  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.RecordingStarted;
44  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self;
45  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ShootingStarted;
46  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ShootingStopped;
47  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Spawn;
48  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Thrown;
49  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.WallCollision;
50  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.WeaponUpdate;
51  import cz.cuni.amis.pogamut.ut2004.communication.worldview.UT2004WorldView;
52  import cz.cuni.amis.pogamut.ut2004.observer.impl.UT2004Observer;
53  import cz.cuni.amis.utils.exception.PogamutException;
54  
55  /**
56   * Similar to {@link UT2004AnalyzerObserver}, but it may output ALL MESSAGES for a given bot.
57   * 
58   * @author Jimmy
59   */
60  public class UT2004AnalyzerFullObserver extends UT2004Observer implements IUT2004AnalyzerObserver {
61  	
62  	private UnrealId observedBotId;	
63  	
64  	private IWorldEventListener<GameRestarted> gameRestartedListener = new IWorldEventListener<GameRestarted>() {
65  
66  		@Override
67  		public void notify(GameRestarted event) {
68  			if (event.isStarted()) {
69  				gameRestartStarted();
70  			} else 
71  			if (event.isFinished()) {
72  				gameRestartEnd();
73  			} else {
74  				throw new PogamutException("GameRestarted has started==false && finished==false as well, invalid!", this);
75  			}
76  		}
77  		
78  	};
79  	
80  	@Inject
81  	public UT2004AnalyzerFullObserver(UT2004AnalyzerFullObserverParameters params,
82  			IComponentBus bus, IAgentLogger agentLogger,
83  			UT2004WorldView worldView, IAct act) {
84  		super(params, bus, agentLogger, worldView, act);
85  		observedBotId = UnrealId.get(params.getObservedAgentId());
86  		getWorldView().addEventListener(GameRestarted.class, gameRestartedListener);
87  		if (params.isHumanLikeObservingEnabled()) {
88  			initializeHumanLikeObserving(params.getHumanLikeBotName(), params.getHumanLikeWriter());
89  		}
90  	}
91  	
92  	@Override
93  	public UT2004AnalyzerFullObserverParameters getParams() {
94  		return (UT2004AnalyzerFullObserverParameters) super.getParams();
95  	}
96  
97  	@Override
98  	public UnrealId getObservedBotId() {
99  		return observedBotId;
100 	}
101 	
102 	/**
103 	 * Returns path to file that should be used for outputting the data
104 	 * @return
105 	 */
106 	public String getOutputFilePath() {
107 		String path = getParams().getOutputPath();
108 		if (path == null) path = ".";
109 		path += File.separator;
110 		if (getParams().getFileName() != null) {
111 			path += getParams().getFileName();
112 		} else {
113 			path += getObservedBotId().getStringId();
114 			path += ".csv";
115 		}
116 		return path;
117 	}
118 	
119 	/**
120 	 * Called whenever {@link GameRestart} message with {@link GameRestarted#isStarted()} is received.
121 	 * <p><p>
122 	 * You probably won't need to override this method, better override {@link UT2004AnalyzerFullObserver#gameRestartEnd()}, that
123 	 * is the place where you should reset data collection statistics / start them in case of {@link UT2004AnalyzerObserverParameters#isWaitForMatchRestart()}.
124 	 * <p><p>
125 	 * Current implementation is empty.
126 	 */
127 	protected void gameRestartStarted() {
128 	}
129 	
130 	/**
131 	 * Called whenever {@link GameRestart} message with {@link GameRestarted#isFinished()} is received.
132 	 * <p><p>
133 	 * Place where you should reset data collection statistics / start them 
134 	 * in case of {@link UT2004AnalyzerObserverParameters#isWaitForMatchRestart()}.
135 	 * <p><p>
136 	 * Current implementation is empty.
137 	 */
138 	protected void gameRestartEnd() {
139 	}
140 	
141 	/**
142 	 * Initialize the observer to listen on the {@link UT2004AnalyzerObserverParameters#getObservedAgentId()} that is obtained from
143 	 * the {@link UT2004AnalyzerFullObserver#getParams()}.
144 	 */
145 	@Override
146 	protected void startAgent() {
147 		super.startAgent();
148 		getAct().act(new InitializeObserver().setId(getParams().getObservedAgentId()));
149 		configureObserver();
150 	}
151 	
152 	@Override
153 	protected void startPausedAgent() {
154 		super.startPausedAgent();
155 		getAct().act(new InitializeObserver().setId(getParams().getObservedAgentId()));
156 		configureObserver();
157 	}
158 	
159 	/**
160 	 * Called from the {@link UT2004AnalyzerFullObserver#startAgent()} after {@link InitializeObserver} command
161 	 * is sent to configure the observer instance.
162 	 * <p><p>
163 	 * Actually enables {@link Self}, {@link MyInventory} and async messages (i.e., {@link BotKilled}).
164 	 */
165 	protected void configureObserver() {
166 		if (getParams().isHumanLikeObservingEnabled()) {
167 			getAct().act(new ConfigurationObserver().setUpdate(0.2).setAll(true).setSelf(true).setAsync(true).setGame(true).setSee(false).setSpecial(false));
168 		} else {
169 			getAct().act(new ConfigurationObserver().setUpdate(0.2).setAll(true).setSelf(true).setAsync(true).setGame(false).setSee(false).setSpecial(false));
170 		}
171 	}
172 	
173 	//
174 	// HUMAN-LIKE OBSERVING
175 	//
176 	
177 	/**
178      * Enemy of the particular observed player.
179      */
180     private Player humanLike_enemy = null;
181     /**
182      * Name of the particular observed player.
183      */
184     private String humanLike_playerName;
185     /**
186      * Where we should output humanLike log.
187      */
188     private PrintWriter humanLike_writer; 
189     /**
190      * Delimiter separating parts of saved log messages. Parts are player name,
191      * time, type of message and a GameBots message.
192      */
193     public static final String humanLike_DELIMITER = "$";
194     
195     /**
196      * Add inventory message.
197      */
198     IWorldEventListener<AddInventoryMsg> humanLike_addInventoryMsgListener = new IWorldEventListener<AddInventoryMsg>() {
199         @Override
200         public void notify(AddInventoryMsg event) {
201             processAddInventoryMsgEvent(event);
202         }
203     };
204     /**
205      * Adrenaline gained.
206      */
207     IWorldEventListener<AdrenalineGained> humanLike_adrenalineGainedListener = new IWorldEventListener<AdrenalineGained>() {
208         @Override
209         public void notify(AdrenalineGained event) {
210             processAdrenalineGainedEvent(event);
211         }
212     };
213     /**
214      * Bumped.
215      */
216     IWorldEventListener<Bumped> humanLike_bumpedListener = new IWorldEventListener<Bumped>() {
217         @Override
218         public void notify(Bumped event) {
219             processBumpedEvent(event);
220         }
221     };
222     /**
223      * Changed weapon.
224      */
225     IWorldEventListener<ChangedWeapon> humanLike_changedWeaponListener = new IWorldEventListener<ChangedWeapon>() {
226         @Override
227         public void notify(ChangedWeapon event) {
228             processChangedWeaponEvent(event);
229         }
230     };
231     /**
232      * Combo started.
233      */
234     IWorldEventListener<ComboStarted> humanLike_comboStartedListener = new IWorldEventListener<ComboStarted>() {
235         @Override
236         public void notify(ComboStarted event) {
237             processComboStartedEvent(event);
238         }
239     };
240     /**
241      * Fall edge.
242      */
243     IWorldEventListener<FallEdge> humanLike_fallEdgeListener = new IWorldEventListener<FallEdge>() {
244         @Override
245         public void notify(FallEdge event) {
246             processFallEdgeEvent(event);
247         }
248     };
249     /**
250      * Game info.
251      */
252     IWorldEventListener<GameInfo> humanLike_gameInfoListener = new IWorldEventListener<GameInfo>() {
253         @Override
254         public void notify(GameInfo event) {
255             processGameInfoEvent(event);
256         }
257     };
258     /**
259      * Global chat.
260      */
261     IWorldEventListener<GlobalChat> humanLike_globalChatListener = new IWorldEventListener<GlobalChat>() {
262         @Override
263         public void notify(GlobalChat event) {
264             processGlobalChatEvent(event);
265         }
266     };
267     /**
268      * Hear noise.
269      */
270     IWorldEventListener<HearNoise> humanLike_hearNoiseListener = new IWorldEventListener<HearNoise>() {
271         @Override
272         public void notify(HearNoise event) {
273             processHearNoiseEvent(event);
274         }
275     };
276     /**
277      * Hear pickup.
278      */
279     IWorldEventListener<HearPickup> humanLike_hearPickupListener = new IWorldEventListener<HearPickup>() {
280         @Override
281         public void notify(HearPickup event) {
282             processHearPickupEvent(event);
283         }
284     };
285     /**
286      * Incoming projectile.
287      */
288     IWorldEventListener<IncomingProjectile> humanLike_incomingProjectileListener = new IWorldEventListener<IncomingProjectile>() {
289         @Override
290         public void notify(IncomingProjectile event) {
291             processIncomingProjectileEvent(event);
292         }
293     };
294     /**
295      * Item picked up.
296      */
297     IWorldEventListener<ItemPickedUp> humanLike_itemPickedUpListener = new IWorldEventListener<ItemPickedUp>() {
298         @Override
299         public void notify(ItemPickedUp event) {
300             processItemPickedUpEvent(event);
301         }
302     };
303     /**
304      * Jump performed.
305      */
306     IWorldEventListener<JumpPerformed> humanLike_jumpPerformedListener = new IWorldEventListener<JumpPerformed>() {
307         @Override
308         public void notify(JumpPerformed event) {
309             processJumpPerformedEvent(event);
310         }
311     };
312     /**
313      * Landed.
314      */
315     IWorldEventListener<Landed> humanLike_landedListener = new IWorldEventListener<Landed>() {
316         @Override
317         public void notify(Landed event) {
318             processLandedEvent(event);
319         }
320     };
321     /**
322      * Lost child.
323      */
324     IWorldEventListener<LostChild> humanLike_lostChildListener = new IWorldEventListener<LostChild>() {
325         @Override
326         public void notify(LostChild event) {
327             processLostChildEvent(event);
328         }
329     };
330     /**
331      * Player damaged.
332      */
333     IWorldEventListener<PlayerDamaged> humanLike_playerDamagedListener = new IWorldEventListener<PlayerDamaged>() {
334         @Override
335         public void notify(PlayerDamaged event) {
336             processPlayerDamagedEvent(event);
337         }
338     };
339     /**
340      * Player joins game.
341      */
342     IWorldEventListener<PlayerJoinsGame> humanLike_playerJoinsGameListener = new IWorldEventListener<PlayerJoinsGame>() {
343         @Override
344         public void notify(PlayerJoinsGame event) {
345             processPlayerJoinsGameEvent(event);
346         }
347     };
348     /**
349      * Player killed.
350      */
351     IWorldEventListener<PlayerKilled> humanLike_playerKilledListener = new IWorldEventListener<PlayerKilled>() {
352         @Override
353         public void notify(PlayerKilled event) {
354             processPlayerKilledEvent(event);
355         }
356     };
357     /**
358      * Player left.
359      */
360     IWorldEventListener<PlayerLeft> humanLike_playerLeftListener = new IWorldEventListener<PlayerLeft>() {
361         @Override
362         public void notify(PlayerLeft event) {
363             processPlayerLeftEvent(event);
364         }
365     };
366     /**
367      * Player score.
368      */
369     IWorldEventListener<PlayerScore> humanLike_playerScoreListener = new IWorldEventListener<PlayerScore>() {
370         @Override
371         public void notify(PlayerScore event) {
372             processPlayerScoreEvent(event);
373         }
374     };
375     /**
376      * Recording ended.
377      */
378     IWorldEventListener<RecordingEnded> humanLike_recordingEndedListener = new IWorldEventListener<RecordingEnded>() {
379         @Override
380         public void notify(RecordingEnded event) {
381             processRecordingEndedEvent(event);
382         }
383     };
384     /**
385      * Player score.
386      */
387     IWorldEventListener<RecordingStarted> humanLike_recordingStartedListener = new IWorldEventListener<RecordingStarted>() {
388         @Override
389         public void notify(RecordingStarted event) {
390             processRecordingStartedEvent(event);
391         }
392     };
393     /**
394      * Self.
395      */
396     IWorldObjectEventListener<Self, WorldObjectUpdatedEvent<Self>> humanLike_selfListener = new IWorldObjectEventListener<Self, WorldObjectUpdatedEvent<Self>>() {
397         @Override
398         public void notify(WorldObjectUpdatedEvent<Self> event) {
399             processSelfEvent(event);
400         }
401     };
402     /**
403      * Shooting started.
404      */
405     IWorldEventListener<ShootingStarted> humanLike_shootingStartedListener = new IWorldEventListener<ShootingStarted>() {
406         @Override
407         public void notify(ShootingStarted event) {
408             processShootingStartedEvent(event);
409         }
410     };
411     /**
412      * Shooting stopped.
413      */
414     IWorldEventListener<ShootingStopped> humanLike_shootingStoppedListener = new IWorldEventListener<ShootingStopped>() {
415         @Override
416         public void notify(ShootingStopped event) {
417             processShootingStoppedEvent(event);
418         }
419     };
420     /**
421      * Spawn.
422      */
423     IWorldEventListener<Spawn> humanLike_spawnListener = new IWorldEventListener<Spawn>() {
424         @Override
425         public void notify(Spawn event) {
426             processSpawnEvent(event);
427         }
428     };
429     /**
430      * Thrown.
431      */
432     IWorldEventListener<Thrown> humanLike_thrownListener = new IWorldEventListener<Thrown>() {
433         @Override
434         public void notify(Thrown event) {
435             processThrownEvent(event);
436         }
437     };
438     /**
439      * Wall collision.
440      */
441     IWorldEventListener<WallCollision> humanLike_wallCollisionListener = new IWorldEventListener<WallCollision>() {
442         @Override
443         public void notify(WallCollision event) {
444             processWallCollisionEvent(event);
445         }
446     };
447     /**
448      * Weapon update.
449      */
450     IWorldEventListener<WeaponUpdate> humanLike_weaponUpdateListener = new IWorldEventListener<WeaponUpdate>() {
451         @Override
452         public void notify(WeaponUpdate event) {
453             processWeaponUpdateEvent(event);
454         }
455     };
456     
457    protected void save(String name, Long time, String type, String message) {
458         String output = name + humanLike_DELIMITER + time.toString() + humanLike_DELIMITER + type + humanLike_DELIMITER + message + "\n";
459         synchronized(humanLike_writer) {
460         	humanLike_writer.print(output);
461         }
462     }
463 
464     /**
465      * Process add inventory message event.
466      *
467      * @param event inventory message event
468      */
469     private void processAddInventoryMsgEvent(AddInventoryMsg event) {
470         save(humanLike_playerName, event.getSimTime(), "AddInventoryMsg", event.toString());
471     }
472 
473     /**
474      * Process adrenaline gained event.
475      *
476      * @param event adrenaline gained event
477      */
478     private void processAdrenalineGainedEvent(AdrenalineGained event) {
479         save(humanLike_playerName, event.getSimTime(), "AdrenalineGained", event.toString());
480     }
481 
482     /**
483      * Process bumped event.
484      *
485      * @param event bumped event
486      */
487     private void processBumpedEvent(Bumped event) {
488         save(humanLike_playerName, event.getSimTime(), "Bumped", event.toString());
489     }
490 
491     /**
492      * Process changed weapon event.
493      *
494      * @param event changed weapon event
495      */
496     private void processChangedWeaponEvent(ChangedWeapon event) {
497         save(humanLike_playerName, event.getSimTime(), "ChangedWeapon", event.toString());
498     }
499 
500     /**
501      * Process combo started event.
502      *
503      * @param event combo started event
504      */
505     private void processComboStartedEvent(ComboStarted event) {
506         save(humanLike_playerName, event.getSimTime(), "ComboStarted", event.toString());
507     }
508 
509     /**
510      * Process fall edge event.
511      *
512      * @param event fall edge event
513      */
514     private void processFallEdgeEvent(FallEdge event) {
515         save(humanLike_playerName, event.getSimTime(), "FallEdge", event.toString());
516     }
517 
518     /**
519      * Process game info event.
520      *
521      * @param event game info event
522      */
523     private void processGameInfoEvent(GameInfo event) {
524         save(humanLike_playerName, event.getSimTime(), "GameInfo", event.toString());
525     }
526 
527     /**
528      * Process global chat event.
529      *
530      * @param event global chat event
531      */
532     private void processGlobalChatEvent(GlobalChat event) {
533         save(humanLike_playerName, event.getSimTime(), "GlobalChat", event.toString());
534     }
535 
536     /**
537      * Process hear noise event.
538      *
539      * @param event hear noise event
540      */
541     private void processHearNoiseEvent(HearNoise event) {
542         save(humanLike_playerName, event.getSimTime(), "HearNoise", event.toString());
543     }
544 
545     /**
546      * Process hear pickup event.
547      *
548      * @param event hear pickup event
549      */
550     private void processHearPickupEvent(HearPickup event) {
551         save(humanLike_playerName, event.getSimTime(), "HearPickup", event.toString());
552     }
553 
554     /**
555      * Process incoming projectile event.
556      *
557      * @param event incoming projectile event
558      */
559     private void processIncomingProjectileEvent(IncomingProjectile event) {
560         save(humanLike_playerName, event.getSimTime(), "IncomingProjectile", event.toString());
561     }
562 
563     /**
564      * Process item picked up event.
565      *
566      * @param event item picked up event
567      */
568     private void processItemPickedUpEvent(ItemPickedUp event) {
569         save(humanLike_playerName, event.getSimTime(), "ItemPickedUp", event.toString());
570     }
571 
572     /**
573      * Process jump performed event.
574      *
575      * @param event jump performed event
576      */
577     private void processJumpPerformedEvent(JumpPerformed event) {
578         save(humanLike_playerName, event.getSimTime(), "JumpPerformed", event.toString());
579     }
580 
581     /**
582      * Process landed event.
583      *
584      * @param event landed event
585      */
586     private void processLandedEvent(Landed event) {
587         save(humanLike_playerName, event.getSimTime(), "Landed", event.toString());
588     }
589 
590     /**
591      * Process lost child event.
592      *
593      * @param event lost child event
594      */
595     private void processLostChildEvent(LostChild event) {
596         save(humanLike_playerName, event.getSimTime(), "LostChild", event.toString());
597     }
598 
599     /**
600      * Process player damaged event.
601      *
602      * @param event player damaged event
603      */
604     private void processPlayerDamagedEvent(PlayerDamaged event) {
605         save(humanLike_playerName, event.getSimTime(), "PlayerDamaged", event.toString());
606     }
607 
608     /**
609      * Process player joins game event.
610      *
611      * @param event player joins game event
612      */
613     private void processPlayerJoinsGameEvent(PlayerJoinsGame event) {
614         save(humanLike_playerName, event.getSimTime(), "PlayerJoinsGame", event.toString());
615     }
616 
617     /**
618      * Process player killed event.
619      *
620      * @param event player killed event
621      */
622     private void processPlayerKilledEvent(PlayerKilled event) {
623         save(humanLike_playerName, event.getSimTime(), "PlayerKilled", event.toString());
624     }
625 
626     /**
627      * Process player left event.
628      *
629      * @param event player left event
630      */
631     private void processPlayerLeftEvent(PlayerLeft event) {
632         save(humanLike_playerName, event.getSimTime(), "PlayerLeft", event.toString());
633     }
634 
635     /**
636      * Process player score event.
637      *
638      * @param event player score event
639      */
640     private void processPlayerScoreEvent(PlayerScore event) {
641         save(humanLike_playerName, event.getSimTime(), "PlayerScore", event.toString());
642     }
643 
644     /**
645      * Process recording ended event.
646      *
647      * @param event recording ended event
648      */
649     private void processRecordingEndedEvent(RecordingEnded event) {
650         save(humanLike_playerName, event.getSimTime(), "RecordingEnded", event.toString());
651     }
652 
653     /**
654      * Process recording started event.
655      *
656      * @param event recording started event
657      */
658     private void processRecordingStartedEvent(RecordingStarted event) {
659         save(humanLike_playerName, event.getSimTime(), "RecordingStarted", event.toString());
660     }
661 
662     /**
663      * Process self event.
664      *
665      * @param event self event
666      */
667     private void processSelfEvent(WorldObjectUpdatedEvent<Self> event) {
668         save(humanLike_playerName, event.getObject().getSimTime(), "Self", event.getObject().toString());
669         processEnemyEvent(event);
670     }
671 
672     /**
673      * Process shooting started event.
674      *
675      * @param event shooting started event
676      */
677     private void processShootingStartedEvent(ShootingStarted event) {
678         save(humanLike_playerName, event.getSimTime(), "ShootingStarted", event.toString());
679     }
680 
681     /**
682      * Process shooting stopped event.
683      *
684      * @param event shooting stopped event
685      */
686     private void processShootingStoppedEvent(ShootingStopped event) {
687         save(humanLike_playerName, event.getSimTime(), "ShootingStopped", event.toString());
688     }
689 
690     /**
691      * Process spawn event.
692      *
693      * @param event spawn event
694      */
695     private void processSpawnEvent(Spawn event) {
696         save(humanLike_playerName, event.getSimTime(), "Spawn", event.toString());
697     }
698 
699     /**
700      * Process thrown event.
701      *
702      * @param event thrown event
703      */
704     private void processThrownEvent(Thrown event) {
705         save(humanLike_playerName, event.getSimTime(), "Thrown", event.toString());
706     }
707 
708     /**
709      * Process wall collision event.
710      *
711      * @param event wall collision event
712      */
713     private void processWallCollisionEvent(WallCollision event) {
714         save(humanLike_playerName, event.getSimTime(), "WallCollision", event.toString());
715     }
716 
717     /**
718      * Process weapon update event.
719      *
720      * @param event weapon update event
721      */
722     private void processWeaponUpdateEvent(WeaponUpdate event) {
723         save(humanLike_playerName, event.getSimTime(), "WeaponUpdate", event.toString());
724     }
725 
726     /**
727      * Process enemy event.
728      *
729      * @param event enemy event
730      */
731     private void processEnemyEvent(WorldObjectUpdatedEvent<Self> event) {
732         locateEnemy(event);
733         if (humanLike_enemy != null) {
734             save(humanLike_playerName, event.getObject().getSimTime(), "Enemy", humanLike_enemy.toString());
735         }
736     }
737 
738     /**
739      * Locate player's enemy. Save reference on player's enemy. If there is no
740      * new enemy, it will keep the last one in memory.
741      *
742      * @param event enemy update
743      */
744     private void locateEnemy(WorldObjectUpdatedEvent<Self> event) {
745         humanLike_enemy = DistanceUtils.getNearestVisible(getWorldView().getAllVisible(Player.class).values(), event.getObject().getLocation());
746         if (humanLike_enemy != null && humanLike_enemy.getName().toString().equals(humanLike_playerName)) {
747             humanLike_enemy = null;
748         }
749     }
750 
751     /**
752      * Initialize listeners. We call this method manually - we register
753      * listeners here.
754      *
755      * @param observedPlayer name of observed player
756      * @param printWriter 
757      */
758     protected void initializeHumanLikeObserving(String observedPlayer, PrintWriter printWriter) {
759 
760     	// init writer
761     	humanLike_writer = printWriter;
762     	if (humanLike_writer == null) {
763     		throw new RuntimeException("humanLike_writer is null! Invalid observer parameters passed...");
764     	}
765     	
766         // initialize listeners
767         getWorldView().addEventListener(AddInventoryMsg.class, humanLike_addInventoryMsgListener);
768         getWorldView().addEventListener(AdrenalineGained.class, humanLike_adrenalineGainedListener);
769         getWorldView().addEventListener(Bumped.class, humanLike_bumpedListener);
770         getWorldView().addEventListener(ChangedWeapon.class, humanLike_changedWeaponListener);
771         getWorldView().addEventListener(ComboStarted.class, humanLike_comboStartedListener);
772         getWorldView().addEventListener(FallEdge.class, humanLike_fallEdgeListener);
773         getWorldView().addEventListener(GameInfo.class, humanLike_gameInfoListener);
774         getWorldView().addEventListener(GlobalChat.class, humanLike_globalChatListener);
775         getWorldView().addEventListener(HearNoise.class, humanLike_hearNoiseListener);
776         getWorldView().addEventListener(HearPickup.class, humanLike_hearPickupListener);
777         getWorldView().addEventListener(IncomingProjectile.class, humanLike_incomingProjectileListener);
778         getWorldView().addEventListener(ItemPickedUp.class, humanLike_itemPickedUpListener);
779         getWorldView().addEventListener(JumpPerformed.class, humanLike_jumpPerformedListener);
780         getWorldView().addEventListener(Landed.class, humanLike_landedListener);
781         getWorldView().addEventListener(LostChild.class, humanLike_lostChildListener);
782         getWorldView().addEventListener(PlayerDamaged.class, humanLike_playerDamagedListener);
783         getWorldView().addEventListener(PlayerJoinsGame.class, humanLike_playerJoinsGameListener);
784         getWorldView().addEventListener(PlayerKilled.class, humanLike_playerKilledListener);
785         getWorldView().addEventListener(PlayerLeft.class, humanLike_playerLeftListener);
786         getWorldView().addEventListener(PlayerScore.class, humanLike_playerScoreListener);
787         getWorldView().addEventListener(RecordingEnded.class, humanLike_recordingEndedListener);
788         getWorldView().addEventListener(RecordingStarted.class, humanLike_recordingStartedListener);
789         getWorldView().addObjectListener(Self.class, WorldObjectUpdatedEvent.class, humanLike_selfListener);
790         getWorldView().addEventListener(ShootingStarted.class, humanLike_shootingStartedListener);
791         getWorldView().addEventListener(ShootingStopped.class, humanLike_shootingStoppedListener);
792         getWorldView().addEventListener(Spawn.class, humanLike_spawnListener);
793         getWorldView().addEventListener(Thrown.class, humanLike_thrownListener);
794         getWorldView().addEventListener(WallCollision.class, humanLike_wallCollisionListener);
795         getWorldView().addEventListener(WeaponUpdate.class, humanLike_weaponUpdateListener);
796 
797         // save player name
798         humanLike_playerName = observedPlayer;
799     }
800 
801 }