Ticket #537: Repair.diff
File Repair.diff, 5.4 KB (added by , 14 years ago) |
---|
-
binaries/data/mods/public/gui/session_new/input.js
128 128 { 129 129 return {"type": "build", "cursor": "action-build", "target": targets[0]}; 130 130 } 131 else if (entState.buildEntities && targetState.needsRepair && playerOwned) 132 { 133 return {"type": "build", "cursor": "action-build", "target": targets[0]}; 134 } 131 135 else if (entState.attack && enemyOwned) 132 136 { 133 137 return {"type": "attack", "cursor": "action-attack", "target": targets[0]}; -
binaries/data/mods/public/simulation/components/Health.js
42 42 // Default to <Initial>, but use <Max> if it's undefined or zero 43 43 // (Allowing 0 initial HP would break our death detection code) 44 44 this.hitpoints = +(this.template.Initial || this.GetMaxHitpoints()); 45 this.repairProgress = this.hitpoints / this.GetMaxHitpoints(); 45 46 }; 46 47 47 48 //// Interface functions //// … … 65 66 this.hitpoints = Math.max(1, Math.min(this.GetMaxHitpoints(), value)); 66 67 }; 67 68 69 Health.prototype.IsRepairable = function() 70 { 71 if (this.template.Repairable) 72 return this.template.Repairable; 73 else 74 return false; 75 }; 76 68 77 Health.prototype.Kill = function() 69 78 { 70 79 this.Reduce(this.hitpoints); … … 132 141 cmpCorpseVisual.SelectAnimation("death", true, 1.0, ""); 133 142 }; 134 143 144 Health.prototype.Repair = function(builderEnt, work) 145 { 146 // Do nothing if we've already finished building 147 this.repairProgress = this.GetHitpoints() / this.GetMaxHitpoints(); 135 148 149 if (this.repairProgress == 1.0) 150 return; 151 152 // Calculate the amount of progress that will be added (where 1.0 = completion) 153 var cmpCost = Engine.QueryInterface(this.entity, IID_Cost); 154 var amount = work / cmpCost.GetBuildTime(); 155 156 // TODO: implement some kind of diminishing returns for multiple repairmen. 157 // e.g. record the set of entities that build this, then every ~2 seconds 158 // count them (and reset the list), and apply some function to the count to get 159 // a factor, and apply that factor here. 160 this.repairProgress += amount; 161 if (this.repairProgress > 1.0) 162 this.repairProgress = 1.0; 163 164 // Add an appropriate proportion of hitpoints 165 var targetHP = Math.max(0, Math.min(this.GetMaxHitpoints(), Math.floor(this.GetMaxHitpoints() * this.repairProgress))); 166 var deltaHP = targetHP - this.hitpoints; 167 if (deltaHP > 0) 168 { 169 var cmpHealth = Engine.QueryInterface(this.entity, IID_Health); 170 cmpHealth.Increase(deltaHP); 171 } 172 173 if (this.repairProgress >= 1.0) 174 { 175 Engine.PostMessage(this.entity, MT_ConstructionFinished, 176 { "entity": this.entity, "newentity": this.entity }); 177 } 178 }; 136 179 Engine.RegisterComponentType(IID_Health, "Health", Health); -
binaries/data/mods/public/simulation/components/GuiInterface.js
76 76 { 77 77 ret.hitpoints = cmpHealth.GetHitpoints(); 78 78 ret.maxHitpoints = cmpHealth.GetMaxHitpoints(); 79 ret.needsRepair = cmpHealth.IsRepairable() && (cmpHealth.GetHitpoints() < cmpHealth.GetMaxHitpoints()); 79 80 } 80 81 81 82 var cmpAttack = Engine.QueryInterface(ent, IID_Attack); -
binaries/data/mods/public/simulation/components/Player.js
10 10 this.civ = "gaia"; 11 11 this.colour = { "r": 0.0, "g": 0.0, "b": 0.0, "a": 1.0 }; 12 12 this.popCount = 0; 13 this.popLimit = 50; 13 this.popLimit = 0; 14 this.popReserve = 0; 14 15 this.resourceCount = { 15 16 "food": 2000, 16 17 "wood": 1500, … … 54 55 return this.colour; 55 56 }; 56 57 58 Player.prototype.ReservePopulationSlots = function(num) 59 { 60 this.popReserve += num; 61 }; 62 63 Player.prototype.UnReservePopulationSlots = function(num) 64 { 65 this.popReserve -= Math.min(num, this.popReserve); 66 } 67 57 68 Player.prototype.GetPopulationCount = function() 58 69 { 59 return this.popCount ;70 return this.popCount + this.popReserve; 60 71 }; 61 72 62 73 Player.prototype.GetPopulationLimit = function() -
binaries/data/mods/public/simulation/components/Builder.js
51 51 52 52 // If it's a foundation, then build it 53 53 var cmpFoundation = Engine.QueryInterface(target, IID_Foundation); 54 var cmpHealth = Engine.QueryInterface(target, IID_Health) 54 55 if (cmpFoundation) 55 56 { 56 57 cmpFoundation.Build(this.entity, rate); 57 58 return { "finished": false }; 58 59 } 59 else 60 else if (cmpHealth) 60 61 { 61 // TODO: do some kind of repairing 62 63 return { "finished": true }; 62 return { "finished": cmpHealth.Repair(this.entity, rate) }; 64 63 } 64 return { "finished": false }; 65 65 }; 66 66 67 67 Engine.RegisterComponentType(IID_Builder, "Builder", Builder);