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]
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)
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)
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){
// 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);
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
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); },
/**
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;
},