Enemies now obey their sight range.
authordsc <david.schoonover@gmail.com>
Mon, 28 Feb 2011 05:56:38 +0000 (21:56 -0800)
committerdsc <david.schoonover@gmail.com>
Mon, 28 Feb 2011 05:56:38 +0000 (21:56 -0800)
data/types/levels.yaml
src/ezl/util/data/datafile.cjs
src/tanks/map/pathing/map-searching.cjs
src/tanks/thing/tank.cjs
src/tanks/ui/viewport.cjs

index df4be67..1a2b15d 100644 (file)
@@ -26,6 +26,10 @@ types:
             args: [300,350, 50,100]
           - type: wall
             args: [100,100, 50,50]
+          - type: wall
+            args: [450,0, 50,150]
+          - type: wall
+            args: [450,300, 50,200]
          
           - type: fence
             args: [360,210, 30,30]
index b074682..b7a9023 100644 (file)
@@ -38,7 +38,15 @@ new evt.Class('DataFile', {
             this.die('Specified types are not iterable! '+data.types);
         
         types.forEach(function(kv, id){
-            var props = Y.extend({}, deepcopy(data.defaults), kv)
+            var props = Y(kv).reduce(
+                function(props, v, k){
+                    var pv = props[k];
+                    if ( Y.isPlainObject(v) && Y.isPlainObject(pv) )
+                        props[k] = Y.extend(pv, v);
+                    else
+                        props[k] = v;
+                    return props;
+                }, deepcopy(data.defaults) )
             ,   symbol = props.symbol;
             
             if (!symbol)
index dab62e5..8be836a 100644 (file)
@@ -18,11 +18,10 @@ var Y = require('Y').Y
 
 Y.core.extend(Map.fn, {
     
-    findNearLike : function findNearLike(me, ticks, fn){
+    findNearLike : function findNearLike(me, within, fn){
         if (fn) fn = fn.toFunction();
         
-        var within = BULLET_MOVE_PER_FRAME*ticks
-        ,   bb = me.bbox
+        var bb = me.bbox
         ,   x1 = bb.x1 - within, y1 = bb.y1 - within
         ,   x2 = bb.x2 + within, y2 = bb.y2 + within
         ,   dudes = this.get(x1,y1, x2,y2)
@@ -33,16 +32,20 @@ Y.core.extend(Map.fn, {
             return dudes;
     },
     
+    findSoonLike : function findSoonLike(me, ticks, fn){
+        return this.findNearLike(me, BULLET_MOVE_PER_FRAME*ticks, fn);
+    },
+    
     findNearBullets : function findNearBullets(me, ticks){
-        return this.findNearLike(me, ticks, nearBulletFilter);
+        return this.findSoonLike(me, ticks, nearBulletFilter);
     },
     
-    findNearEnemies : function findNearEnemies(me, ticks){
-        return this.findNearLike(me, ticks, nearEnemyFilter);
+    findNearEnemies : function findNearEnemies(me, within){
+        return this.findNearLike(me, within || (me.stats.sight.val*REF_SIZE), nearEnemyFilter);
     },
     
-    findNearEnemiesInSight : function findNearEnemiesInSight(me, ticks){
-        return this.findNearLike(me, ticks, nearEnemyInSightFilter);
+    findNearEnemiesInSight : function findNearEnemiesInSight(me){
+        return this.findNearLike(me, me.stats.sight.val*REF_SIZE, nearEnemyInSightFilter);
     },
     
     closestOf : function closestOf(me, agents){
index d90dda4..c6dc5a7 100644 (file)
@@ -121,7 +121,7 @@ Thing.subclass('Tank', function(Tank){
         
         // Try to blow up nearby tanks
         if (ai.shootEnemy.ready && (this.stats.shots.val - this.nShots > 1)) {
-            var t = map.findNearEnemiesInSight(this, 71).shift();
+            var t = map.findNearEnemiesInSight(this).shift();
             // console.log('['+TICKS+':'+this.id, this, '] Shoot at enemies?', t);
             if (t) {
                 ai.shootEnemy.activate(now);
@@ -217,7 +217,7 @@ Thing.subclass('Tank', function(Tank){
     this['continueMove'] =
     function continueMove(){
         if ( (!this.currentMove || this.ai.path.ready) && this.game.pathsThisTick < 1 ){
-            var target = this.game.map.findNearEnemies(this, 10000).shift();
+            var target = this.game.map.findNearEnemies(this).shift();
             if (target)
                 this.calculatePath(target.loc);
             else
index 0399eff..c9b14ea 100644 (file)
@@ -24,7 +24,7 @@ HtmlLayer.subclass('Viewport', {
         this.spacer = $('<div class="spacer ezl layer" />').appendTo(this.layer);
     },
     
-    get contentWidth(){  return this.children.pluck('layerWidth').reduce(max,0); },
+    get contentWidth(){  return this.children.pluck('layerWidth').reduce(max,0);  },
     get contentHeight(){ return this.children.pluck('layerHeight').reduce(max,0); },
     
     /**
@@ -50,14 +50,16 @@ HtmlLayer.subclass('Viewport', {
         
         if (x instanceof Array) { y=x[1]; x=x[0]; }
         
-        if (x !== undefined) {
-            var v = (cw < w  ? (cw-w)/2 : clamp(x, minX, maxX));
-            el.scrollLeft( PAD_X + v );
-        }
-        if (y !== undefined) {
-            var v = (ch < h ? (ch-h)/2 : clamp(y, minY, maxY));
-            el.scrollTop(  PAD_Y + v );
-        }
+        if (cw < w)
+            x = (cw-w)/2;
+        if (x !== undefined)
+            el.scrollLeft( PAD_X + clamp(x, minX, maxX) );
+        
+        if (ch < h)
+            y = (ch-h)/2;
+        if (y !== undefined)
+            el.scrollTop(  PAD_Y + clamp(y, minY, maxY) );
+        
         
         return this;
     },