From c322146e2e43cd8df4d95afa863c1534bce54c41 Mon Sep 17 00:00:00 2001 From: dsc Date: Sun, 27 Feb 2011 21:56:38 -0800 Subject: [PATCH] Enemies now obey their sight range. --- data/types/levels.yaml | 4 ++++ src/ezl/util/data/datafile.cjs | 10 +++++++++- src/tanks/map/pathing/map-searching.cjs | 19 +++++++++++-------- src/tanks/thing/tank.cjs | 4 ++-- src/tanks/ui/viewport.cjs | 20 +++++++++++--------- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/data/types/levels.yaml b/data/types/levels.yaml index df4be67..1a2b15d 100644 --- a/data/types/levels.yaml +++ b/data/types/levels.yaml @@ -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] diff --git a/src/ezl/util/data/datafile.cjs b/src/ezl/util/data/datafile.cjs index b074682..b7a9023 100644 --- a/src/ezl/util/data/datafile.cjs +++ b/src/ezl/util/data/datafile.cjs @@ -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) diff --git a/src/tanks/map/pathing/map-searching.cjs b/src/tanks/map/pathing/map-searching.cjs index dab62e5..8be836a 100644 --- a/src/tanks/map/pathing/map-searching.cjs +++ b/src/tanks/map/pathing/map-searching.cjs @@ -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){ diff --git a/src/tanks/thing/tank.cjs b/src/tanks/thing/tank.cjs index d90dda4..c6dc5a7 100644 --- a/src/tanks/thing/tank.cjs +++ b/src/tanks/thing/tank.cjs @@ -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 diff --git a/src/tanks/ui/viewport.cjs b/src/tanks/ui/viewport.cjs index 0399eff..c9b14ea 100644 --- a/src/tanks/ui/viewport.cjs +++ b/src/tanks/ui/viewport.cjs @@ -24,7 +24,7 @@ HtmlLayer.subclass('Viewport', { this.spacer = $('
').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; }, -- 1.7.0.4