Permalink
Browse files

Sound based events in progress (buggy)

  • Loading branch information...
1 parent 09989cd commit 3a0892f0cdd3ccc1600a4cb4be7d9fb1f954a4d4 @bloodrizer committed Mar 27, 2012
@@ -8,8 +8,11 @@
import com.nuclearunicorn.libroguelike.game.ent.controller.NpcController;
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.world.RLTile;
import com.nuclearunicorn.serialkiller.game.world.RLWorldChunk;
import com.nuclearunicorn.serialkiller.game.world.entities.EntBed;
@@ -18,6 +21,7 @@
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;
@@ -278,6 +282,24 @@ public void e_on_event(Event 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(
+ owner.origin,
+ ((SuspiciousSoundEvent) event).getOrigin(),
+ ((RLCombat)owner.get_combat()).getFovRadius())
+ ){
+
+ RLMessages.message(owner.getName() +" has reported to police of suspicious sounds", Color.orange);
+
+ //TODO: report police
+ NPCReportCrimeEvent reportEvent = new NPCReportCrimeEvent(((SuspiciousSoundEvent) event).getOrigin());
+ reportEvent.post();
+ }
+ }
}
@Override
@@ -7,6 +7,7 @@
import com.nuclearunicorn.libroguelike.game.items.BaseItem;
import com.nuclearunicorn.libroguelike.game.world.WorldTimer;
import com.nuclearunicorn.serialkiller.game.events.CriminalActionEvent;
+import com.nuclearunicorn.serialkiller.game.events.SuspiciousSoundEvent;
import com.nuclearunicorn.serialkiller.game.world.entities.EntityRLHuman;
import com.nuclearunicorn.serialkiller.render.RLMessages;
import org.newdawn.slick.Color;
@@ -43,6 +44,10 @@ public int getFovRadius(){
return fov;
}
+
+ public int getHearRadius(){
+ return (int)(5 + 1.5*stats.per); //slightly better than LOS, and date of time does not affect our senses
+ }
@Override
public Damage.DamageType getDamageType() {
@@ -147,6 +152,9 @@ 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();
}
public NPCStats getStats() {
@@ -41,7 +41,9 @@ public void e_on_event(Event event) {
if (event instanceof SuspiciousSoundEvent){
List<Entity> ents = RLMath.getEntitiesInRadius(((SuspiciousSoundEvent) event).getOrigin(), ((SuspiciousSoundEvent) event).radius);
for (Entity ent: ents){
- ((EntRLActor)ent).e_on_event(event);
+ if (ent instanceof EntRLActor){
+ ((EntRLActor)ent).e_on_event(event);
+ }
}
}
}
@@ -3,6 +3,8 @@
import com.nuclearunicorn.libroguelike.core.client.ClientGameEnvironment;
import com.nuclearunicorn.libroguelike.game.ent.Entity;
import com.nuclearunicorn.libroguelike.game.player.Player;
+import com.nuclearunicorn.libroguelike.game.world.layers.WorldLayer;
+import com.nuclearunicorn.serialkiller.utils.pathfinder.adaptive.BresinhamLine;
import org.lwjgl.util.Point;
import java.util.ArrayList;
@@ -27,16 +29,37 @@ public static Point getNearestPoint(List<Point> list, Point anchor){
return nearestPoint;
}
+ public static boolean isPointInRadius(Point center, Point target, int radius){
+ double squareDisst = Math.pow(center.getX() - target.getX(), 2) + Math.pow(center.getY() - target.getY(), 2);
+ return (squareDisst <= Math.pow(radius, 2));
+ }
+
public static List<Entity> getEntitiesInRadius(Point center, int radius){
List<Entity> entities = new ArrayList<Entity> ();
for (Entity ent: ClientGameEnvironment.getEnvironment().getEntityManager().getEntities(Player.get_zindex())){
- double squareDisst = Math.pow(center.getX() - ent.origin.getX(), 2) + Math.pow(center.getY() - ent.origin.getY(), 2);
- if (squareDisst <= Math.pow(radius, 2)){
+ if (isPointInRadius(center, ent.origin, radius)){
entities.add(ent);
}
}
return entities;
}
+
+ //Trace bresinham vector and return false, if collision in LOS or outside of visibility radius
+ public static boolean pointInLOS(Point origin, Point target, int radius) {
+ if (!isPointInRadius(origin, target, radius)){
+ return false;
+ }
+
+ WorldLayer layer = ClientGameEnvironment.getEnvironment().getWorldLayer(Player.get_zindex());
+ List<Point> line = BresinhamLine.line(origin.getX(), origin.getY(), target.getX(), target.getY());
+ for (Point tile: line){
+ if (layer.get_tile(tile).isBlocked()){
+ return false;
+ }
+ }
+
+ return true;
+ }
}

0 comments on commit 3a0892f

Please sign in to comment.