Ticket #633: repair.diff
File repair.diff, 5.1 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Builder.js
3 3 Builder.prototype.Schema = 4 4 "<a:help>Allows the unit to construct and repair buildings.</a:help>" + 5 5 "<a:example>" + 6 "< Rate>1.0</Rate>" +6 "<BuildRate>1.0</BuildRate>" + 7 7 "<Entities datatype='tokens'>" + 8 8 "\n structures/{civ}_barracks\n structures/{civ}_civil_centre\n structures/celt_sb1\n " + 9 9 "</Entities>" + … … 11 11 "<element name='Rate' a:help='Construction speed multiplier (1.0 is normal speed, higher values are faster)'>" + 12 12 "<ref name='positiveDecimal'/>" + 13 13 "</element>" + 14 "<optional>" + 15 "<element name='RepairRate' a:help='Repairing speed multiplier (1.0 is normal speed, higher values are faster), by default the same as the normal rate.'>" + 16 "<ref name='positiveDecimal'/>" + 17 "</element>" + 18 "</optional>" + 19 14 20 "<element name='Entities' a:help='Space-separated list of entity template names that this unit can build. The special string \"{civ}\" will be automatically replaced by the unit's four-character civ code. This element can also be empty, in which case no new foundations may be placed by the unit, but they can still repair existing buildings'>" + 15 21 "<attribute name='datatype'>" + 16 22 "<value>tokens</value>" + … … 56 62 */ 57 63 Builder.prototype.PerformBuilding = function(target) 58 64 { 59 var rate = ApplyValueModificationsToEntity("Builder/Rate", +this.template.Rate, this.entity);60 65 61 66 // If it's a foundation, then build it 62 67 var cmpFoundation = Engine.QueryInterface(target, IID_Foundation); 63 68 if (cmpFoundation) 64 69 { 70 var rate = ApplyValueModificationsToEntity("Builder/Rate", +this.template.Rate, this.entity); 65 71 cmpFoundation.Build(this.entity, rate); 66 72 return; 67 73 } … … 68 74 69 75 // Otherwise try to repair it 70 76 var cmpHealth = Engine.QueryInterface(target, IID_Health); 71 if (cmpHealth) 72 { 73 cmpHealth.Repair(this.entity, rate); 77 if (!cmpHealth) 74 78 return; 75 } 79 80 if (this.template.RepairRate) 81 var rate = ApplyValueModificationsToEntity("Builder/RepairRate", +this.template.RepairRate, this.entity); 82 else 83 var rate = ApplyValueModificationsToEntity("Builder/Rate", +this.template.Rate, this.entity); 84 85 cmpHealth.Repair(this.entity, rate); 76 86 }; 77 87 78 88 Engine.RegisterComponentType(IID_Builder, "Builder", Builder); -
binaries/data/mods/public/simulation/components/Cost.js
22 22 "<element name='BuildTime' a:help='Time taken to construct/train this unit (in seconds)'>" + 23 23 "<ref name='nonNegativeDecimal'/>" + 24 24 "</element>" + 25 "<optional>" + 26 "<element name='RepairTime' a:help='Time taken to repair this unit (in seconds). By default, the max health of an entity (so it repairs at 1 HP/s)'>" + 27 "<ref name='nonNegativeDecimal'/>" + 28 "</element>" + 29 "</optional>" + 25 30 "<element name='Resources' a:help='Resource costs to construct/train this unit'>" + 26 31 "<interleave>" + 27 32 "<element name='food'><data type='nonNegativeInteger'/></element>" + … … 48 53 49 54 Cost.prototype.GetBuildTime = function() 50 55 { 56 if (!this.template.RepairTime) 57 return null; 51 58 var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); 52 59 var buildTime = (+this.template.BuildTime) * cmpPlayer.cheatTimeMultiplier; 53 60 return ApplyValueModificationsToEntity("Cost/BuildTime", buildTime, this.entity); 54 61 } 55 62 63 Cost.prototype.GetRepairTime = function() 64 { 65 if (!this.template.RepairTime) 66 return null; 67 var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); 68 var repairTime = (+this.template.RepairTime) * cmpPlayer.cheatTimeMultiplier; 69 return ApplyValueModificationsToEntity("Cost/RepairTime", repairTime, this.entity); 70 } 71 56 72 Cost.prototype.GetResourceCosts = function() 57 73 { 58 74 var costs = {}; -
binaries/data/mods/public/simulation/components/Health.js
300 300 return spawnedEntity; 301 301 }; 302 302 303 Health.prototype.Repair = function(builderEnt, work)303 Health.prototype.Repair = function(builderEnt, rate) 304 304 { 305 305 var damage = this.GetMaxHitpoints() - this.GetHitpoints(); 306 306 … … 309 309 return; 310 310 311 311 // Calculate the amount of hitpoints that will be added 312 var repairTime = this.GetMaxHitpoints(); 313 var cmpCost = Engine.QueryInterface(this.entity, IID_Cost); 314 if (cmpCost && cmpCost.GetRepairTime()) 315 repairTime = cmpCost.GetRepairTime(); 316 317 var work = rate / repairTime * this.GetMaxHitpoints(); 318 312 319 // TODO: what computation should we use? 313 320 // TODO: should we do some diminishing returns thing? (see Foundation.Build) 314 321 var amount = Math.min(damage, work);