From 975028c21baa6feae00669768c1dc9dc1d348ea5 Mon Sep 17 00:00:00 2001 From: dsc Date: Thu, 31 Mar 2011 03:11:23 -0700 Subject: [PATCH] Renames active to isActive; movePerMs no longer a getter. --- src/tanks/item/item.cjs | 6 +++--- src/tanks/map/wall.cjs | 2 +- src/tanks/thing/bullet.cjs | 2 +- src/tanks/thing/component.cjs | 2 +- src/tanks/thing/shield.cjs | 6 +++--- src/tanks/thing/tank.cjs | 5 +++-- src/tanks/thing/thing.cjs | 33 ++++++++++++++++++++------------- 7 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/tanks/item/item.cjs b/src/tanks/item/item.cjs index b967801..1dd7844 100644 --- a/src/tanks/item/item.cjs +++ b/src/tanks/item/item.cjs @@ -35,7 +35,7 @@ Thing.subclass('Item', { dealDamage : op.nop, // inactive in the event loop - active : false, + isActive : false, /// Instance Properties /// name : 'Dummy', // {String} Display name @@ -103,7 +103,7 @@ Thing.subclass('Item', { /** * Equips this item to owner or given unit. Does not manipulate inventory, but does remove from map if newly acquired. - * @param {Tank} [unit=this.owner] Unit to equip. If omitted, uses this.owner; if unowned, does nothing. + * @param {Tank} [unit=this.owner] Unit to equip. If omitted, uses this.owner; if omitted and unowned, does nothing. * @return {this} */ equip : function equip(unit){ @@ -111,7 +111,7 @@ Thing.subclass('Item', { var evt = unit; unit = evt.data.unit; } - if (unit && unit.isUnit) { + if (unit && unit.isThing) { this.owner = unit; this.removeFromMap(); } diff --git a/src/tanks/map/wall.cjs b/src/tanks/map/wall.cjs index fc35e99..dc94900 100644 --- a/src/tanks/map/wall.cjs +++ b/src/tanks/map/wall.cjs @@ -36,7 +36,7 @@ Thing.subclass('Wall', { // inactive - active : false, + isActive : false, createCooldowns : op.nop, tick : op.nop, diff --git a/src/tanks/thing/bullet.cjs b/src/tanks/thing/bullet.cjs index ed2cd84..3f1a565 100644 --- a/src/tanks/thing/bullet.cjs +++ b/src/tanks/thing/bullet.cjs @@ -63,7 +63,7 @@ Thing.subclass('Bullet', { Thing.init.call(this, owner.align); this.position(x1,y1); - this.trajectory = new LinearTrajectory(this, x1,y1, x2,y2, this.movePerMs); + this.trajectory = new LinearTrajectory(this, x1,y1, x2,y2, this.movePerMs()); this.on('collide', this.onCollide); }, diff --git a/src/tanks/thing/component.cjs b/src/tanks/thing/component.cjs index c9779db..18bbb48 100644 --- a/src/tanks/thing/component.cjs +++ b/src/tanks/thing/component.cjs @@ -17,7 +17,7 @@ Thing.subclass('Component', { isComponent : true, - active : false, // Owner will notify us to ensure we go at the right time + isActive : false, // Owner will notify us to ensure we go at the right time isRenderable : true, // Agent will present itself for rendering when ready // FIXME: stupid hack isReflective : false, // Projectiles bounce off agent rather than explode? hasInventory : false, // Agent can acquire items? diff --git a/src/tanks/thing/shield.cjs b/src/tanks/thing/shield.cjs index 7d3ed53..b2a00b9 100644 --- a/src/tanks/thing/shield.cjs +++ b/src/tanks/thing/shield.cjs @@ -20,10 +20,10 @@ Component.subclass('Shield', { // Instance blocking : BoundsType.IRREGULAR, // Need to allow shields etc to passthrough like-aligned units - isComponent : true, - isShield : true, + isComponent : true, + isShield : true, - active : false, // Owner will notify us to ensure we go at the right time + isActive : false, // Owner will notify us to ensure we go at the right time isRenderable : true, // Agent will present itself for rendering when ready // FIXME: stupid hack isReflective : false, // Projectiles bounce off agent rather than explode? hasInventory : false, // Agent can acquire items? diff --git a/src/tanks/thing/tank.cjs b/src/tanks/thing/tank.cjs index a30cf84..1cdca54 100644 --- a/src/tanks/thing/tank.cjs +++ b/src/tanks/thing/tank.cjs @@ -28,8 +28,9 @@ exports['Tank'] = Thing.subclass('Tank', function(Tank){ Y.core.descriptors(this, { + isUnit : true, isCombatant : true, - lootTable : '', + lootTable : '', colors : { body : '#83BB32', @@ -218,7 +219,7 @@ Thing.subclass('Tank', function(Tank){ if (x instanceof Array) { y=x[_Y]; x=x[_X]; } var loc = this.loc; - this.trajectory = new LinearTrajectory(this, loc.x,loc.y, x,y, this.movePerMs); + this.trajectory = new LinearTrajectory(this, loc.x,loc.y, x,y, this.movePerMs()); var tvsl = new Traversal(this) , to = tvsl.traverse(this.elapsed, x,y) ; diff --git a/src/tanks/thing/thing.cjs b/src/tanks/thing/thing.cjs index abd4000..9a04e02 100644 --- a/src/tanks/thing/thing.cjs +++ b/src/tanks/thing/thing.cjs @@ -18,7 +18,9 @@ var Y = require('Y').Y , - +/** + * A Thing is any object that can be added to the Map. + */ Thing = exports['Thing'] = new evt.Class('Thing', { @@ -30,13 +32,13 @@ new evt.Class('Thing', { // Attributes stats: { - hp : 1, // health - move : 1.0, // move speed (squares/sec) - power : 1, // attack power - speed : 0.5, // attack cool (sec) - shots : 5, // max projectiles in the air at once - sight : 5, // distance this unit can see (squares) - accuracy : 1.0 + hp : Infinity, // health + move : 0, // move speed (squares/sec) + power : 0, // attack power + speed : 0, // attack cool (sec) + shots : 0, // max projectiles in the air at once + sight : 0, // distance this unit can see (squares) + accuracy : 0 // targeting accuracy (into formula of orthogonal drift from trajectory after 10 squares?) }, cooldowns : { @@ -59,14 +61,15 @@ new evt.Class('Thing', { blocking : BoundsType.BLOCKING, density : DensityType.DENSE, - isUnit : true, + isThing : true, + isUnit : false, isCombatant : false, isWall : false, isProjectile : false, isAccessory : false, isComponent : false, - active : true, // Agent takes actions? + isActive : true, // Agent takes actions? isRenderable : false, // Agent will present itself for rendering when ready // FIXME: stupid hack isReflective : false, // Projectiles bounce off agent rather than explode? hasInventory : false, // Agent can acquire items? @@ -75,7 +78,6 @@ new evt.Class('Thing', { // Location loc : null, bbox : null, - ownBbox : null, // Rotation (rads) rotation : 0, @@ -90,14 +92,18 @@ new evt.Class('Thing', { 'set' : op.set.methodize(), 'attr' : op.attr.methodize(), - get movePerMs(){ + movePerMs : function movePerMs(){ var stat = this.stats.move; return (typeof stat === "number" ? stat : stat.val)*REF_SIZE/1000; }, - init : function init(align){ + /** + * @constructor + * @param {Number} align Team number of this unit; 0 is Neutral. + */ + init : function initThing(align){ this.align = align || this.align; this.components = new Y.YArray(); this.createBoundingBox(); @@ -205,6 +211,7 @@ new evt.Class('Thing', { }, draw : function draw(){ + // TODO: Test whether in viewport bounds? Or do it in Game? if (!this.dead) { if (this.dirty) { this.dirty = false; -- 1.7.0.4