Skip to content

Commit

Permalink
Crimeplace investigation + lot's of bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodrizer committed Mar 28, 2012
1 parent 3a0892f commit a5430b6
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 27 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class PointBasedEvent extends Event {
protected Point origin; protected Point origin;


public PointBasedEvent(Point origin){ public PointBasedEvent(Point origin){
this.origin = origin; this.origin = new Point(origin); //defensive copying
} }


public Point getOrigin(){ public Point getOrigin(){
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public void move_ent(int x, int y){


if (owner.tile == tile){ if (owner.tile == tile){
step = null; step = null;
if (path != null){ if (path != null && path.size()>0){
path.remove(0); path.remove(0);
} }
return; return;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ public void e_on_event(Event event){
//camera_x = 0.0f; //camera_x = 0.0f;
//camera_y = 0.0f; //camera_y = 0.0f;
//WorldViewCamera.set(0.0f,0.0f); //WorldViewCamera.set(0.0f,0.0f);
WorldViewCamera.follow_target = true; if (!Input.key_state_alt){
WorldViewCamera.follow_target = true;
}
} }
} }
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
public class VersionOverlay { public class VersionOverlay {


//to lazy to implement this shit //to lazy to implement this shit
private static final String CLIENT_VER = "0.1.9"; private static final String CLIENT_VER = "0.2.0";
private static final String BUILD_NUMBER = "1090"; private static final String BUILD_NUMBER = "2001";


public static void render(){ public static void render(){
OverlaySystem.ttf.drawString(WindowRender.get_window_w() - 110, 30, OverlaySystem.ttf.drawString(WindowRender.get_window_w() - 110, 30,
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.nuclearunicorn.serialkiller.game.ai; package com.nuclearunicorn.serialkiller.game.ai;


import com.nuclearunicorn.libroguelike.core.client.ClientGameEnvironment;
import com.nuclearunicorn.libroguelike.events.Event; import com.nuclearunicorn.libroguelike.events.Event;
import com.nuclearunicorn.libroguelike.game.ai.BasicMobAI; import com.nuclearunicorn.libroguelike.game.ai.BasicMobAI;
import com.nuclearunicorn.libroguelike.game.ai.IAIAction; import com.nuclearunicorn.libroguelike.game.ai.IAIAction;
import com.nuclearunicorn.libroguelike.game.ent.Entity; import com.nuclearunicorn.libroguelike.game.ent.Entity;
import com.nuclearunicorn.libroguelike.game.ent.EntityActor; import com.nuclearunicorn.libroguelike.game.ent.EntityActor;
import com.nuclearunicorn.libroguelike.game.ent.controller.NpcController; 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.WorldTile;
import com.nuclearunicorn.libroguelike.game.world.WorldTimer; 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.controllers.RLController;
import com.nuclearunicorn.serialkiller.game.events.NPCReportCrimeEvent; import com.nuclearunicorn.serialkiller.game.events.NPCReportCrimeEvent;
import com.nuclearunicorn.serialkiller.game.events.NPCWitnessCrimeEvent; import com.nuclearunicorn.serialkiller.game.events.NPCWitnessCrimeEvent;
import com.nuclearunicorn.serialkiller.game.events.SuspiciousSoundEvent; 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.RLTile;
import com.nuclearunicorn.serialkiller.game.world.RLWorldChunk; import com.nuclearunicorn.serialkiller.game.world.RLWorldChunk;
import com.nuclearunicorn.serialkiller.game.world.entities.EntBed; import com.nuclearunicorn.serialkiller.game.world.entities.EntBed;
Expand All @@ -21,7 +23,6 @@
import com.nuclearunicorn.serialkiller.game.world.entities.EntityRLHuman; import com.nuclearunicorn.serialkiller.game.world.entities.EntityRLHuman;
import com.nuclearunicorn.serialkiller.generators.Apartment; import com.nuclearunicorn.serialkiller.generators.Apartment;
import com.nuclearunicorn.serialkiller.render.RLMessages; import com.nuclearunicorn.serialkiller.render.RLMessages;
import com.nuclearunicorn.serialkiller.utils.RLMath;
import org.lwjgl.util.Point; import org.lwjgl.util.Point;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;


Expand Down Expand Up @@ -276,18 +277,24 @@ public void update(){


@Override @Override
public void e_on_event(Event event) { public void e_on_event(Event event) {


if (event instanceof NPCWitnessCrimeEvent){ if (event instanceof NPCWitnessCrimeEvent){
NPCWitnessCrimeEvent e = (NPCWitnessCrimeEvent)event; NPCWitnessCrimeEvent e = (NPCWitnessCrimeEvent)event;


//TODO: pass criminal to the AI manager, so state will be reset only if no known criminal is in fov //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); knowCriminals.add((EntityActor) e.criminal);
} }
if (event instanceof SuspiciousSoundEvent){ if (event instanceof SuspiciousSoundEvent){

/* /*
Trace vector. If wee see target, we should not report police, Trace vector. If wee see target, we should not report police,
since we probably see criminal already since we probably see criminal already
*/ */
if (!RLMath.pointInLOS(
//disregard that

/*if (!RLMath.pointInLOS(
owner.origin, owner.origin,
((SuspiciousSoundEvent) event).getOrigin(), ((SuspiciousSoundEvent) event).getOrigin(),
((RLCombat)owner.get_combat()).getFovRadius()) ((RLCombat)owner.get_combat()).getFovRadius())
Expand All @@ -298,6 +305,24 @@ public void e_on_event(Event event) {
//TODO: report police //TODO: report police
NPCReportCrimeEvent reportEvent = new NPCReportCrimeEvent(((SuspiciousSoundEvent) event).getOrigin()); NPCReportCrimeEvent reportEvent = new NPCReportCrimeEvent(((SuspiciousSoundEvent) event).getOrigin());
reportEvent.post(); 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);
}
//}
}
} }
} }
} }
Expand All @@ -313,3 +338,4 @@ public void e_on_obstacle(int x, int y) {
} }
} }
} }

Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
import com.nuclearunicorn.libroguelike.game.ent.EntityActor; import com.nuclearunicorn.libroguelike.game.ent.EntityActor;
import com.nuclearunicorn.libroguelike.game.ent.controller.NpcController; import com.nuclearunicorn.libroguelike.game.ent.controller.NpcController;
import com.nuclearunicorn.libroguelike.game.player.Player; 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.controllers.RLController;
import com.nuclearunicorn.serialkiller.game.events.NPCReportCrimeEvent; 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.social.SocialController;
import com.nuclearunicorn.serialkiller.game.world.RLTile; 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 com.nuclearunicorn.serialkiller.utils.RLMath;
import org.lwjgl.util.Point; import org.lwjgl.util.Point;
import org.newdawn.slick.Color;


import java.util.List; import java.util.List;


Expand All @@ -39,8 +44,30 @@ private void actionInvestigate(NpcController npcController) {
List<Point> crimeplaces = SocialController.getCrimeplaces(); List<Point> crimeplaces = SocialController.getCrimeplaces();
Point nearestCrimeplace = RLMath.getNearestPoint(crimeplaces, owner.origin); 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(); 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 @Override
Expand Down Expand Up @@ -99,12 +126,19 @@ public void e_on_obstacle(int x, int y) {


@Override @Override
public void e_on_event(Event event) { 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){ if (event instanceof NPCReportCrimeEvent){
System.out.println("Police AI: started investigation"); System.out.println("Police AI: started investigation");


state = AI_STATE_INVESTIGATING; state = AI_STATE_INVESTIGATING;
return;
} }

if (event instanceof SuspiciousSoundEvent){
return;
}

super.e_on_event(event);
} }
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -153,8 +153,11 @@ public void attack(Entity ent) {
CriminalActionEvent event = new CriminalActionEvent(ent.origin, (EntityActor)owner); CriminalActionEvent event = new CriminalActionEvent(ent.origin, (EntityActor)owner);
event.post(); event.post();


SuspiciousSoundEvent soundEvent = new SuspiciousSoundEvent(ent.origin, 10); //TODO: differend sound modifiers //TODO: temporary hack for player ent. TODO: rewrite for support of multiple criminals in town
soundEvent.post(); if (owner.isPlayerEnt()){
SuspiciousSoundEvent soundEvent = new SuspiciousSoundEvent(ent.origin, 10); //TODO: differend sound modifiers
soundEvent.post();
}
} }


public NPCStats getStats() { public NPCStats getStats() {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public void calculateAdaptivePath(Point source, Point target) {
*/ */


tmpPath = this.getAstarPath(prevNode.point, node.point); tmpPath = this.getAstarPath(prevNode.point, node.point);
if (tmpPath == null){ //safe switch lol
return;
}
tmpPath.remove(0); tmpPath.remove(0);
} }
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -198,6 +198,21 @@ public IUserInterface get_ui(){
public void e_on_event(Event event) { public void e_on_event(Event event) {
boolean isNextTurn = false; 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){ if (Player.get_ent() != null){
Combat combat = Player.get_ent().get_combat(); Combat combat = Player.get_ent().get_combat();
if (combat != null && !combat.is_alive()){ if (combat != null && !combat.is_alive()){
Expand Down Expand Up @@ -230,18 +245,6 @@ public void e_on_event(Event event) {
case Keyboard.KEY_SPACE: case Keyboard.KEY_SPACE:
isNextTurn = true; isNextTurn = true;
break; 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;
} }
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void e_on_event(Event event) {
if (crimeplaces.contains(((NPCReportCrimeEvent) event).getOrigin())){ if (crimeplaces.contains(((NPCReportCrimeEvent) event).getOrigin())){
return; return;
} }
System.out.println(">>> added crimeplace <<<");
addCrimeplace(((NPCReportCrimeEvent) event).getOrigin()); addCrimeplace(((NPCReportCrimeEvent) event).getOrigin());
} }
if (event instanceof SuspiciousSoundEvent){ if (event instanceof SuspiciousSoundEvent){
Expand All @@ -51,4 +52,9 @@ public void e_on_event(Event event) {
public void addCrimeplace(Point crimeplace){ public void addCrimeplace(Point crimeplace){
crimeplaces.add(crimeplace); crimeplaces.add(crimeplace);
} }


public static boolean hasCrimeplace(Point origin) {
return crimeplaces.contains(origin);
}
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.nuclearunicorn.libroguelike.render.overlay.DebugOverlay; import com.nuclearunicorn.libroguelike.render.overlay.DebugOverlay;
import com.nuclearunicorn.libroguelike.render.overlay.OverlaySystem; import com.nuclearunicorn.libroguelike.render.overlay.OverlaySystem;
import com.nuclearunicorn.libroguelike.utils.NLTimer; import com.nuclearunicorn.libroguelike.utils.NLTimer;
import com.nuclearunicorn.serialkiller.game.social.SocialController;
import com.nuclearunicorn.serialkiller.game.world.RLTile; import com.nuclearunicorn.serialkiller.game.world.RLTile;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
Expand Down Expand Up @@ -84,6 +85,11 @@ public void render_tile(WorldTile tile, int tile_x, int tile_y) {
drawChar(tile_x, tile_y, ".", Color.red); 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){ if (!rltile.getTileModel().isEmpty() && rltile.getTileModelColor() != null){
drawChar(tile_x, tile_y, rltile.getTileModel(), rltile.getTileModelColor()); drawChar(tile_x, tile_y, rltile.getTileModel(), rltile.getTileModelColor());
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static Point getNearestPoint(List<Point> list, Point anchor){
double min_disst = Double.MAX_VALUE; double min_disst = Double.MAX_VALUE;
Point nearestPoint = null; Point nearestPoint = null;
for (Point node : list){ 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); Double disst = Math.pow(anchor.getX()-node.getX(),2) + Math.pow(anchor.getY()-node.getY(),2);
if (disst < min_disst){ if (disst < min_disst){
min_disst = disst; min_disst = disst;
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nuclearunicorn.serialkiller.vgui; package com.nuclearunicorn.serialkiller.vgui;


import com.nuclearunicorn.libroguelike.core.Input;
import com.nuclearunicorn.libroguelike.game.ent.Entity; import com.nuclearunicorn.libroguelike.game.ent.Entity;
import com.nuclearunicorn.libroguelike.vgui.NE_GUI_FrameModern; import com.nuclearunicorn.libroguelike.vgui.NE_GUI_FrameModern;
import com.nuclearunicorn.libroguelike.vgui.NE_GUI_Text; import com.nuclearunicorn.libroguelike.vgui.NE_GUI_Text;
Expand Down Expand Up @@ -73,23 +74,27 @@ private void updateInfo() {
} }
info.add_line(""); info.add_line("");
if (ent.getAI() != null){ if (ent.getAI() != null){
//info.add_line("AI state is '" + ent.getAI().getState()+"'");
if (ent.getAI().getState() == PedestrianAI.AI_STATE_TIRED){ if (ent.getAI().getState() == PedestrianAI.AI_STATE_TIRED){
info.add_line(prefix + " looks tired"); info.add_line(prefix + " looks tired");
} }
if (ent.getAI().getState() == PedestrianAI.AI_STATE_SLEEPING){ if (ent.getAI().getState() == PedestrianAI.AI_STATE_SLEEPING){
info.add_line(prefix + " is sleeping with a happy smile on a face"); //todo: implement mood 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){ if (ent.getApartment() == null){
info.add_line(prefix + " is homeless"); info.add_line(prefix + " is homeless");
}else{ }else{
//Entity bed = ent.getApartment().beds.get((int) Math.random() * ent.getApartment().beds.size()); //Entity bed = ent.getApartment().beds.get((int) Math.random() * ent.getApartment().beds.size());
if (ent.getSex() == EntityRLHuman.Sex.FEMALE){ 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" ); 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" );
} }
} }


Expand Down

0 comments on commit a5430b6

Please sign in to comment.