Permalink
Browse files

Crimeplace investigation + lot's of bugfixes

  • Loading branch information...
1 parent 3a0892f commit a5430b63c4477c26f993b9be704f88cb1aaa2611 @bloodrizer committed Mar 28, 2012
View
2 libroguelike/src/com/nuclearunicorn/libroguelike/events/PointBasedEvent.java
@@ -9,7 +9,7 @@
protected Point origin;
public PointBasedEvent(Point origin){
- this.origin = origin;
+ this.origin = new Point(origin); //defensive copying
}
public Point getOrigin(){
View
2 libroguelike/src/com/nuclearunicorn/libroguelike/game/ent/controller/NpcController.java
@@ -208,7 +208,7 @@ public void move_ent(int x, int y){
if (owner.tile == tile){
step = null;
- if (path != null){
+ if (path != null && path.size()>0){
path.remove(0);
}
return;
View
4 libroguelike/src/com/nuclearunicorn/libroguelike/game/world/WorldView.java
@@ -451,7 +451,9 @@ public void e_on_event(Event event){
//camera_x = 0.0f;
//camera_y = 0.0f;
//WorldViewCamera.set(0.0f,0.0f);
- WorldViewCamera.follow_target = true;
+ if (!Input.key_state_alt){
+ WorldViewCamera.follow_target = true;
+ }
}
}
}
View
4 libroguelike/src/com/nuclearunicorn/libroguelike/render/overlay/VersionOverlay.java
@@ -15,8 +15,8 @@
public class VersionOverlay {
//to lazy to implement this shit
- private static final String CLIENT_VER = "0.1.9";
- private static final String BUILD_NUMBER = "1090";
+ private static final String CLIENT_VER = "0.2.0";
+ private static final String BUILD_NUMBER = "2001";
public static void render(){
OverlaySystem.ttf.drawString(WindowRender.get_window_w() - 110, 30,
View
32 serialkiller/src/com/nuclearunicorn/serialkiller/game/ai/PedestrianAI.java
@@ -1,18 +1,20 @@
package com.nuclearunicorn.serialkiller.game.ai;
+import com.nuclearunicorn.libroguelike.core.client.ClientGameEnvironment;
import com.nuclearunicorn.libroguelike.events.Event;
import com.nuclearunicorn.libroguelike.game.ai.BasicMobAI;
import com.nuclearunicorn.libroguelike.game.ai.IAIAction;
import com.nuclearunicorn.libroguelike.game.ent.Entity;
import com.nuclearunicorn.libroguelike.game.ent.EntityActor;
import com.nuclearunicorn.libroguelike.game.ent.controller.NpcController;
+import com.nuclearunicorn.libroguelike.game.player.Player;
import com.nuclearunicorn.libroguelike.game.world.WorldTile;
import com.nuclearunicorn.libroguelike.game.world.WorldTimer;
-import com.nuclearunicorn.serialkiller.game.combat.RLCombat;
import com.nuclearunicorn.serialkiller.game.controllers.RLController;
import com.nuclearunicorn.serialkiller.game.events.NPCReportCrimeEvent;
import com.nuclearunicorn.serialkiller.game.events.NPCWitnessCrimeEvent;
import com.nuclearunicorn.serialkiller.game.events.SuspiciousSoundEvent;
+import com.nuclearunicorn.serialkiller.game.social.SocialController;
import com.nuclearunicorn.serialkiller.game.world.RLTile;
import com.nuclearunicorn.serialkiller.game.world.RLWorldChunk;
import com.nuclearunicorn.serialkiller.game.world.entities.EntBed;
@@ -21,7 +23,6 @@
import com.nuclearunicorn.serialkiller.game.world.entities.EntityRLHuman;
import com.nuclearunicorn.serialkiller.generators.Apartment;
import com.nuclearunicorn.serialkiller.render.RLMessages;
-import com.nuclearunicorn.serialkiller.utils.RLMath;
import org.lwjgl.util.Point;
import org.newdawn.slick.Color;
@@ -276,18 +277,24 @@ public void update(){
@Override
public void e_on_event(Event event) {
+
+
if (event instanceof NPCWitnessCrimeEvent){
NPCWitnessCrimeEvent e = (NPCWitnessCrimeEvent)event;
//TODO: pass criminal to the AI manager, so state will be reset only if no known criminal is in fov
knowCriminals.add((EntityActor) e.criminal);
}
if (event instanceof SuspiciousSoundEvent){
+
/*
Trace vector. If wee see target, we should not report police,
since we probably see criminal already
*/
- if (!RLMath.pointInLOS(
+
+ //disregard that
+
+ /*if (!RLMath.pointInLOS(
owner.origin,
((SuspiciousSoundEvent) event).getOrigin(),
((RLCombat)owner.get_combat()).getFovRadius())
@@ -298,6 +305,24 @@ public void e_on_event(Event event) {
//TODO: report police
NPCReportCrimeEvent reportEvent = new NPCReportCrimeEvent(((SuspiciousSoundEvent) event).getOrigin());
reportEvent.post();
+ } */
+ if (!SocialController.hasCrimeplace(((SuspiciousSoundEvent) event).getOrigin())){
+ RLMessages.message(owner.getName() +" has reported to police of criminal activity", Color.orange);
+
+ //TODO: report police
+ //System.out.println("reporting to the police:");
+ NPCReportCrimeEvent reportEvent = new NPCReportCrimeEvent(((SuspiciousSoundEvent) event).getOrigin());
+ reportEvent.post();
+
+ //notice police npc directly, since they are not event listeners
+ Entity[] ents = ClientGameEnvironment.getEnvironment().getEntityManager().getEntities(Player.get_zindex());
+ for (Entity ent: ents){
+ //if (ent.getAI() != null && ent.getAI() instanceof PoliceAI){
+ if (ent instanceof EntityRLHuman){
+ ((EntityRLHuman)ent).e_on_event(reportEvent);
+ }
+ //}
+ }
}
}
}
@@ -313,3 +338,4 @@ public void e_on_obstacle(int x, int y) {
}
}
}
+
View
38 serialkiller/src/com/nuclearunicorn/serialkiller/game/ai/PoliceAI.java
@@ -7,12 +7,17 @@
import com.nuclearunicorn.libroguelike.game.ent.EntityActor;
import com.nuclearunicorn.libroguelike.game.ent.controller.NpcController;
import com.nuclearunicorn.libroguelike.game.player.Player;
+import com.nuclearunicorn.serialkiller.game.combat.RLCombat;
import com.nuclearunicorn.serialkiller.game.controllers.RLController;
import com.nuclearunicorn.serialkiller.game.events.NPCReportCrimeEvent;
+import com.nuclearunicorn.serialkiller.game.events.SuspiciousSoundEvent;
import com.nuclearunicorn.serialkiller.game.social.SocialController;
import com.nuclearunicorn.serialkiller.game.world.RLTile;
+import com.nuclearunicorn.serialkiller.game.world.entities.EntityRLHuman;
+import com.nuclearunicorn.serialkiller.render.RLMessages;
import com.nuclearunicorn.serialkiller.utils.RLMath;
import org.lwjgl.util.Point;
+import org.newdawn.slick.Color;
import java.util.List;
@@ -39,8 +44,30 @@ private void actionInvestigate(NpcController npcController) {
List<Point> crimeplaces = SocialController.getCrimeplaces();
Point nearestCrimeplace = RLMath.getNearestPoint(crimeplaces, owner.origin);
- controller.calculateAdaptivePath(owner.origin, nearestCrimeplace);
+ if (nearestCrimeplace == null){
+ System.out.println("Failed to get nearest crimeplace of list"+crimeplaces);
+ state = AI_STATE_PATROLLING;
+ return;
+ }
+
+ if (nearestCrimeplace != null && !npcController.hasPath()){
+ controller.calculateAdaptivePath(owner.origin, nearestCrimeplace);
+ }
controller.follow_path();
+
+ if (owner.origin.equals(nearestCrimeplace)){
+ crimeplaces.remove(nearestCrimeplace);
+ RLMessages.message("Police has closed the case", Color.cyan);
+ }
+
+ //a little cheaty way to mark player as criminal if cop locate him near the crimeplace
+
+ int fovRadius = ((RLCombat)((EntityRLHuman)owner).get_combat()).getFovRadius();
+ if (RLMath.isPointInRadius(owner.origin, nearestCrimeplace, fovRadius)){
+ if (RLMath.isPointInRadius(owner.origin, Player.get_ent().origin, fovRadius)){
+ knowCriminals.add((EntityActor)Player.get_ent());
+ }
+ }
}
@Override
@@ -99,12 +126,19 @@ public void e_on_obstacle(int x, int y) {
@Override
public void e_on_event(Event event) {
- super.e_on_event(event);
+ System.out.println("Police AI: event handler for "+event);
if (event instanceof NPCReportCrimeEvent){
System.out.println("Police AI: started investigation");
state = AI_STATE_INVESTIGATING;
+ return;
}
+
+ if (event instanceof SuspiciousSoundEvent){
+ return;
+ }
+
+ super.e_on_event(event);
}
}
View
7 serialkiller/src/com/nuclearunicorn/serialkiller/game/combat/RLCombat.java
@@ -153,8 +153,11 @@ public void attack(Entity ent) {
CriminalActionEvent event = new CriminalActionEvent(ent.origin, (EntityActor)owner);
event.post();
- SuspiciousSoundEvent soundEvent = new SuspiciousSoundEvent(ent.origin, 10); //TODO: differend sound modifiers
- soundEvent.post();
+ //TODO: temporary hack for player ent. TODO: rewrite for support of multiple criminals in town
+ if (owner.isPlayerEnt()){
+ SuspiciousSoundEvent soundEvent = new SuspiciousSoundEvent(ent.origin, 10); //TODO: differend sound modifiers
+ soundEvent.post();
+ }
}
public NPCStats getStats() {
View
3 serialkiller/src/com/nuclearunicorn/serialkiller/game/controllers/RLController.java
@@ -71,6 +71,9 @@ public void calculateAdaptivePath(Point source, Point target) {
*/
tmpPath = this.getAstarPath(prevNode.point, node.point);
+ if (tmpPath == null){ //safe switch lol
+ return;
+ }
tmpPath.remove(0);
}
}
View
27 serialkiller/src/com/nuclearunicorn/serialkiller/game/modes/in_game/InGameMode.java
@@ -198,6 +198,21 @@ public IUserInterface get_ui(){
public void e_on_event(Event event) {
boolean isNextTurn = false;
+ //allow to press ESC even if player is dead
+ if (event instanceof EKeyPress){
+ if (((EKeyPress) event).key == Keyboard.KEY_ESCAPE){
+ SkillerGame game;
+ if (Main.game != null){
+ game = Main.game;
+ }else{
+ game = MainApplet.game;
+ }
+ game.set_state("mainMenu");
+ game.initStateUI();
+ return;
+ }
+ }
+
if (Player.get_ent() != null){
Combat combat = Player.get_ent().get_combat();
if (combat != null && !combat.is_alive()){
@@ -230,18 +245,6 @@ public void e_on_event(Event event) {
case Keyboard.KEY_SPACE:
isNextTurn = true;
break;
-
-
- case Keyboard.KEY_ESCAPE:
- SkillerGame game;
- if (Main.game != null){
- game = Main.game;
- }else{
- game = MainApplet.game;
- }
- game.set_state("mainMenu");
- game.initStateUI();
- break;
}
}
View
6 serialkiller/src/com/nuclearunicorn/serialkiller/game/social/SocialController.java
@@ -36,6 +36,7 @@ public void e_on_event(Event event) {
if (crimeplaces.contains(((NPCReportCrimeEvent) event).getOrigin())){
return;
}
+ System.out.println(">>> added crimeplace <<<");
addCrimeplace(((NPCReportCrimeEvent) event).getOrigin());
}
if (event instanceof SuspiciousSoundEvent){
@@ -51,4 +52,9 @@ public void e_on_event(Event event) {
public void addCrimeplace(Point crimeplace){
crimeplaces.add(crimeplace);
}
+
+
+ public static boolean hasCrimeplace(Point origin) {
+ return crimeplaces.contains(origin);
+ }
}
View
6 serialkiller/src/com/nuclearunicorn/serialkiller/render/ConsoleRenderer.java
@@ -11,6 +11,7 @@
import com.nuclearunicorn.libroguelike.render.overlay.DebugOverlay;
import com.nuclearunicorn.libroguelike.render.overlay.OverlaySystem;
import com.nuclearunicorn.libroguelike.utils.NLTimer;
+import com.nuclearunicorn.serialkiller.game.social.SocialController;
import com.nuclearunicorn.serialkiller.game.world.RLTile;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
@@ -84,6 +85,11 @@ public void render_tile(WorldTile tile, int tile_x, int tile_y) {
drawChar(tile_x, tile_y, ".", Color.red);
}
}
+
+ //crimeplace visualization
+ if (SocialController.hasCrimeplace(tile.origin)){
+ drawChar(tile_x, tile_y, "X", Color.red);
+ }
if (!rltile.getTileModel().isEmpty() && rltile.getTileModelColor() != null){
drawChar(tile_x, tile_y, rltile.getTileModel(), rltile.getTileModelColor());
View
3 serialkiller/src/com/nuclearunicorn/serialkiller/utils/RLMath.java
@@ -19,6 +19,9 @@ public static Point getNearestPoint(List<Point> list, Point anchor){
double min_disst = Double.MAX_VALUE;
Point nearestPoint = null;
for (Point node : list){
+ /*if (node == null || anchor == null){
+ return null; //unexpected behavior, panic flee
+ }*/
Double disst = Math.pow(anchor.getX()-node.getX(),2) + Math.pow(anchor.getY()-node.getY(),2);
if (disst < min_disst){
min_disst = disst;
View
11 serialkiller/src/com/nuclearunicorn/serialkiller/vgui/VGUIDetailedNPCInformation.java
@@ -1,5 +1,6 @@
package com.nuclearunicorn.serialkiller.vgui;
+import com.nuclearunicorn.libroguelike.core.Input;
import com.nuclearunicorn.libroguelike.game.ent.Entity;
import com.nuclearunicorn.libroguelike.vgui.NE_GUI_FrameModern;
import com.nuclearunicorn.libroguelike.vgui.NE_GUI_Text;
@@ -73,23 +74,27 @@ private void updateInfo() {
}
info.add_line("");
if (ent.getAI() != null){
- //info.add_line("AI state is '" + ent.getAI().getState()+"'");
if (ent.getAI().getState() == PedestrianAI.AI_STATE_TIRED){
info.add_line(prefix + " looks tired");
}
if (ent.getAI().getState() == PedestrianAI.AI_STATE_SLEEPING){
info.add_line(prefix + " is sleeping with a happy smile on a face"); //todo: implement mood
}
+
+ if (Input.key_state_alt){
+ info.add_line("AI state is '" + ent.getAI().getState()+"'");
+ }
}
+
if (ent.getApartment() == null){
info.add_line(prefix + " is homeless");
}else{
//Entity bed = ent.getApartment().beds.get((int) Math.random() * ent.getApartment().beds.size());
if (ent.getSex() == EntityRLHuman.Sex.FEMALE){
- info.add_line(prefix + " has " + ent.getApartment().beds.size() + " beds at his apartment" );
- }else{
info.add_line(prefix + " has " + ent.getApartment().beds.size() + " beds at her apartment" );
+ }else{
+ info.add_line(prefix + " has " + ent.getApartment().beds.size() + " beds at his apartment" );
}
}

0 comments on commit a5430b6

Please sign in to comment.