Ticket #633: repair-v4.diff
File repair-v4.diff, 19.3 KB (added by , 9 years ago) |
---|
-
binaries/data/mods/public/gui/session/selection_details.js
201 201 else 202 202 Engine.GetGUIObjectByName("resourceCarryingIcon").tooltip = translate("Number of builders."); 203 203 } 204 else if (entState.repairable && entState.repairable.numBuilders > 0 && entState.visibility == "visible") 205 { 206 Engine.GetGUIObjectByName("resourceCarryingIcon").hidden = false; 207 Engine.GetGUIObjectByName("resourceCarryingText").hidden = false; 208 Engine.GetGUIObjectByName("resourceCarryingIcon").sprite = "stretched:session/icons/repair.png"; 209 Engine.GetGUIObjectByName("resourceCarryingText").caption = entState.repairable.numBuilders + " "; 210 Engine.GetGUIObjectByName("resourceCarryingIcon").tooltip = translate("Number of builders."); 211 } 204 212 else if (entState.resourceSupply && (!entState.resourceSupply.killBeforeGather || !entState.hitpoints) && entState.visibility == "visible") 205 213 { 206 214 Engine.GetGUIObjectByName("resourceCarryingIcon").hidden = false; -
binaries/data/mods/public/simulation/components/Builder.js
64 64 */ 65 65 Builder.prototype.PerformBuilding = function(target) 66 66 { 67 varrate = ApplyValueModificationsToEntity("Builder/Rate", +this.template.Rate, this.entity);67 let rate = ApplyValueModificationsToEntity("Builder/Rate", +this.template.Rate, this.entity); 68 68 69 69 // If it's a foundation, then build it 70 varcmpFoundation = Engine.QueryInterface(target, IID_Foundation);70 let cmpFoundation = Engine.QueryInterface(target, IID_Foundation); 71 71 if (cmpFoundation) 72 72 { 73 73 cmpFoundation.Build(this.entity, rate); … … 75 75 } 76 76 77 77 // Otherwise try to repair it 78 var cmpHealth = Engine.QueryInterface(target, IID_Health);79 if (cmp Health)78 let cmpRepairable = Engine.QueryInterface(target, IID_Repairable); 79 if (cmpRepairable) 80 80 { 81 cmp Health.Repair(this.entity, rate);81 cmpRepairable.Repair(this.entity, rate); 82 82 return; 83 83 } 84 84 }; -
binaries/data/mods/public/simulation/components/Foundation.js
142 142 */ 143 143 Foundation.prototype.SetBuildMultiplier = function() 144 144 { 145 varnumBuilders = this.builders.length;146 if (numBuilders == 0)145 let numBuilders = this.builders.length; 146 if (numBuilders < 2) 147 147 this.buildMultiplier = 1; 148 148 else 149 149 this.buildMultiplier = Math.pow(numBuilders, 0.7) / numBuilders; -
binaries/data/mods/public/simulation/components/GuiInterface.js
333 333 }; 334 334 } 335 335 336 var cmpRepairable = QueryMiragedInterface(ent, IID_Repairable); 337 if (cmpRepairable) 338 { 339 ret.repairable = { 340 "numBuilders": cmpRepairable.GetNumBuilders() 341 }; 342 } 343 336 344 var cmpOwnership = Engine.QueryInterface(ent, IID_Ownership); 337 345 if (cmpOwnership) 338 346 { -
binaries/data/mods/public/simulation/components/Health.js
32 32 "</element>" + 33 33 "<element name='Unhealable' a:help='Indicates that the entity can not be healed by healer units'>" + 34 34 "<data type='boolean'/>" + 35 "</element>" +36 "<element name='Repairable' a:help='Indicates that the entity can be repaired by builder units'>" +37 "<data type='boolean'/>" +38 35 "</element>"; 39 36 40 37 Health.prototype.Init = function() … … 92 89 93 90 Health.prototype.IsRepairable = function() 94 91 { 95 return ( this.template.Repairable == "true");92 return (Engine.QueryInterface(this.entity, IID_Repairable) != null); 96 93 }; 97 94 98 95 Health.prototype.IsUnhealable = function() … … 315 312 return spawnedEntity; 316 313 }; 317 314 318 Health.prototype.Repair = function(builderEnt, work)319 {320 var damage = this.GetMaxHitpoints() - this.GetHitpoints();321 322 // Do nothing if we're already at full hitpoints323 if (damage <= 0)324 return;325 326 // Calculate the amount of hitpoints that will be added327 // TODO: what computation should we use?328 // TODO: should we do some diminishing returns thing? (see Foundation.Build)329 var amount = Math.min(damage, work);330 331 // TODO: resource costs?332 333 // Add hitpoints334 this.Increase(amount);335 336 // If we repaired all the damage, send a message to entities337 // to stop repairing this building338 if (amount >= damage)339 {340 Engine.PostMessage(this.entity, MT_ConstructionFinished,341 { "entity": this.entity, "newentity": this.entity });342 }343 };344 345 315 Health.prototype.OnValueModification = function(msg) 346 316 { 347 317 if (msg.component != "Health") -
binaries/data/mods/public/simulation/components/Repairable.js
1 function Repairable() {} 2 3 Repairable.prototype.Schema = 4 "<a:help>Deals with repairable structures and units.</a:help>" + 5 "<a:example>" + 6 "<RepairTimeRatio>2.0</RepairTimeRatio>" + 7 "</a:example>" + 8 "<element name='RepairTimeRatio' a:help='repair time ratio relative to building (or production) time.'>" + 9 "<ref name='positiveDecimal'/>" + 10 "</element>"; 11 12 Repairable.prototype.Init = function() 13 { 14 this.builders = []; // builder entities 15 this.buildMultiplier = 1; // Multiplier for the amount of work builders do. 16 this.repairTimeRatio = +this.template.RepairTimeRatio; 17 }; 18 19 Repairable.prototype.GetNumBuilders = function() 20 { 21 return this.builders.length; 22 }; 23 24 Repairable.prototype.AddBuilder = function(builderEnt) 25 { 26 if (this.builders.indexOf(builderEnt) !== -1) 27 return; 28 this.builders.push(builderEnt); 29 this.SetBuildMultiplier(); 30 }; 31 32 Repairable.prototype.RemoveBuilder = function(builderEnt) 33 { 34 if (this.builders.indexOf(builderEnt) === -1) 35 return; 36 this.builders.splice(this.builders.indexOf(builderEnt), 1); 37 this.SetBuildMultiplier(); 38 }; 39 40 /** 41 * Sets the build rate multiplier, which is applied to all builders. 42 * Yields a total rate of construction equal to numBuilders^0.7 43 */ 44 Repairable.prototype.SetBuildMultiplier = function() 45 { 46 let numBuilders = this.builders.length; 47 if (numBuilders < 2) 48 this.buildMultiplier = 1; 49 else 50 this.buildMultiplier = Math.pow(numBuilders, 0.7) / numBuilders; 51 }; 52 53 // TODO: should we have resource costs? 54 Repairable.prototype.Repair = function(builderEnt, rate) 55 { 56 let cmpHealth = Engine.QueryInterface(this.entity, IID_Health); 57 let cmpCost = Engine.QueryInterface(this.entity, IID_Cost); 58 if (!cmpHealth || !cmpCost) 59 return; 60 let damage = cmpHealth.GetMaxHitpoints() - cmpHealth.GetHitpoints(); 61 if (damage <= 0) 62 return; 63 64 // Calculate the amount of hitpoints that will be added (using diminushing rate when several builders) 65 let repairTime = this.repairTimeRatio * cmpCost.GetBuildTime(); 66 let work = repairTime ? rate * this.buildMultiplier * cmpHealth.GetMaxHitpoints() / repairTime : rate * this.buildMultiplier; 67 let amount = Math.min(damage, work); 68 cmpHealth.Increase(amount); 69 70 // If we repaired all the damage, send a message to entities to stop repairing this building 71 if (amount >= damage) 72 Engine.PostMessage(this.entity, MT_ConstructionFinished, { "entity": this.entity, "newentity": this.entity }); 73 }; 74 75 Engine.RegisterComponentType(IID_Repairable, "Repairable", Repairable); -
binaries/data/mods/public/simulation/components/UnitAI.js
2615 2615 return true; 2616 2616 } 2617 2617 2618 var cmpFoundation = Engine.QueryInterface(this.repairTarget, IID_Foundation);2619 if (cmp Foundation)2620 cmp Foundation.AddBuilder(this.entity);2618 let cmpBuilderList = QueryBuilderListInterface(this.repairTarget); 2619 if (cmpBuilderList) 2620 cmpBuilderList.AddBuilder(this.entity); 2621 2621 2622 2622 this.SelectAnimation("build", false, 1.0, "build"); 2623 2623 this.StartTimer(1000, 1000); … … 2625 2625 }, 2626 2626 2627 2627 "leave": function() { 2628 var cmpFoundation = Engine.QueryInterface(this.repairTarget, IID_Foundation);2629 if (cmp Foundation)2630 cmp Foundation.RemoveBuilder(this.entity);2628 let cmpBuilderList = QueryBuilderListInterface(this.repairTarget); 2629 if (cmpBuilderList) 2630 cmpBuilderList.RemoveBuilder(this.entity); 2631 2631 delete this.repairTarget; 2632 2632 this.StopTimer(); 2633 2633 }, -
binaries/data/mods/public/simulation/components/interfaces/Repairable.js
1 Engine.RegisterInterface("Repairable"); -
binaries/data/mods/public/simulation/helpers/Player.js
243 243 } 244 244 245 245 /** 246 * Similar to Engine.QueryInterface, but checks for all interfaces 247 * implementing a builder list (currently Foundation and Repairable) 248 */ 249 function QueryBuilderListInterface(ent) 250 { 251 return Engine.QueryInterface(ent, IID_Foundation) || Engine.QueryInterface(ent, IID_Repairable); 252 } 253 254 /** 246 255 * Returns true if the entity 'target' is owned by an ally of 247 256 * the owner of 'entity'. 248 257 */ … … 400 409 Engine.RegisterGlobal("QueryOwnerInterface", QueryOwnerInterface); 401 410 Engine.RegisterGlobal("QueryPlayerIDInterface", QueryPlayerIDInterface); 402 411 Engine.RegisterGlobal("QueryMiragedInterface", QueryMiragedInterface); 412 Engine.RegisterGlobal("QueryBuilderListInterface", QueryBuilderListInterface); 403 413 Engine.RegisterGlobal("IsOwnedByAllyOfEntity", IsOwnedByAllyOfEntity); 404 414 Engine.RegisterGlobal("IsOwnedByMutualAllyOfEntity", IsOwnedByMutualAllyOfEntity); 405 415 Engine.RegisterGlobal("IsOwnedByPlayer", IsOwnedByPlayer); -
binaries/data/mods/public/simulation/templates/gaia/fauna_shark.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_unit_fauna_wild_passive"> 3 <Footprint replace=""> 4 <Square width="5" depth="8"/> 5 <Height>7.5</Height> 6 </Footprint> 7 <Health> 8 <Max>150</Max> 9 <Unhealable>true</Unhealable> 10 <Repairable>false</Repairable> 11 </Health> 12 <Identity> 13 <Civ>gaia</Civ> 14 <SpecificName>Great White</SpecificName> 15 <GenericName>Shark</GenericName> 16 <Classes datatype="tokens">SeaCreature</Classes> 17 <Icon>gaia/fauna_fish.png</Icon> 18 </Identity> 19 <Minimap disable=""/> 20 <Position> 21 <Altitude>-1</Altitude> 22 <Floating>true</Floating> 23 <TurnRate>5.0</TurnRate> 24 </Position> 25 <Selectable> 26 <Overlay> 27 <Texture> 28 <MainTexture>circle/128x128.png</MainTexture> 29 <MainTextureMask>circle/128x128_mask.png</MainTextureMask> 30 </Texture> 31 </Overlay> 32 </Selectable> 33 <Visibility> 34 <RetainInFog>false</RetainInFog> 35 </Visibility> 36 <Vision> 37 <Range>100</Range> 38 </Vision> 39 <VisualActor> 40 <Actor>fauna/shark.xml</Actor> 41 </VisualActor> 42 <UnitAI> 43 <NaturalBehaviour>passive</NaturalBehaviour> 44 <RoamDistance>100.0</RoamDistance> 45 <FleeDistance>60.0</FleeDistance> 46 <RoamTimeMin>100000</RoamTimeMin> 47 <RoamTimeMax>300000</RoamTimeMax> 48 <FeedTimeMin>1</FeedTimeMin> 49 <FeedTimeMax>2</FeedTimeMax> 50 </UnitAI> 51 <UnitMotion> 52 <PassabilityClass>ship-small</PassabilityClass> 53 <WalkSpeed>4.0</WalkSpeed> 54 <Run> 55 <Speed>35.0</Speed> 56 </Run> 57 </UnitMotion> 3 <Footprint replace=""> 4 <Square width="5" depth="8"/> 5 <Height>7.5</Height> 6 </Footprint> 7 <Health> 8 <Max>150</Max> 9 <Unhealable>true</Unhealable> 10 </Health> 11 <Identity> 12 <Civ>gaia</Civ> 13 <SpecificName>Great White</SpecificName> 14 <GenericName>Shark</GenericName> 15 <Classes datatype="tokens">SeaCreature</Classes> 16 <Icon>gaia/fauna_fish.png</Icon> 17 </Identity> 18 <Minimap disable=""/> 19 <Position> 20 <Altitude>-1</Altitude> 21 <Floating>true</Floating> 22 <TurnRate>5.0</TurnRate> 23 </Position> 24 <Selectable> 25 <Overlay> 26 <Texture> 27 <MainTexture>circle/128x128.png</MainTexture> 28 <MainTextureMask>circle/128x128_mask.png</MainTextureMask> 29 </Texture> 30 </Overlay> 31 </Selectable> 32 <Visibility> 33 <RetainInFog>false</RetainInFog> 34 </Visibility> 35 <Vision> 36 <Range>100</Range> 37 </Vision> 38 <VisualActor> 39 <Actor>fauna/shark.xml</Actor> 40 </VisualActor> 41 <UnitAI> 42 <NaturalBehaviour>passive</NaturalBehaviour> 43 <RoamDistance>100.0</RoamDistance> 44 <FleeDistance>60.0</FleeDistance> 45 <RoamTimeMin>100000</RoamTimeMin> 46 <RoamTimeMax>300000</RoamTimeMax> 47 <FeedTimeMin>1</FeedTimeMin> 48 <FeedTimeMax>2</FeedTimeMax> 49 </UnitAI> 50 <UnitMotion> 51 <PassabilityClass>ship-small</PassabilityClass> 52 <WalkSpeed>4.0</WalkSpeed> 53 <Run> 54 <Speed>35.0</Speed> 55 </Run> 56 </UnitMotion> 58 57 </Entity> -
binaries/data/mods/public/simulation/templates/other/plane.xml
41 41 <Formations datatype="tokens" replace=""/> 42 42 </Identity> 43 43 <Health> 44 44 <Max>100</Max> 45 45 <Unhealable>true</Unhealable> 46 <Repairable>true</Repairable>47 46 </Health> 47 <Repairable> 48 <RepairTimeRatio>3.0</RepairTimeRatio> 49 </Repairable> 48 50 <Obstruction disable=""/> 49 51 <Position> 50 52 <TurnRate>1.0</TurnRate> -
binaries/data/mods/public/simulation/templates/structures/rome_army_camp.xml
51 51 </GarrisonHolder> 52 52 <Health> 53 53 <Max>2500</Max> 54 <Repairable>true</Repairable>55 54 <SpawnEntityOnDeath>rubble/rubble_rome_sb</SpawnEntityOnDeath> 56 55 </Health> 57 56 <Identity> … … 59 58 <GenericName>Entrenched Army Camp</GenericName> 60 59 <SpecificName>Castrum Vallum</SpecificName> 61 60 <Classes datatype="tokens"> 62 63 61 ArmyCamp 62 </Classes> 64 63 <Icon>structures/roman_camp.png</Icon> 65 64 <Tooltip>Build anywhere on the map, even in enemy territory. Construct siege weapons and train citizen-soldiers. Heal garrisoned units slowly.</Tooltip> 66 65 <History>Sometimes it was a temporary camp built facing the route by which the army is to march, other times a defensive or offensive (for sieges) structure. Within this gate the tents of the first centuries or cohorts are pitched, and the dragons (ensigns of cohorts) and other ensigns planted. The Decumane gate is directly opposite to the Praetorian in the rear of the camp, and through this the soldiers are conducted to the place appointed for punishment or execution.</History> -
binaries/data/mods/public/simulation/templates/template_structure.xml
48 48 <DeathType>corpse</DeathType> 49 49 <RegenRate>0</RegenRate> 50 50 <Unhealable>true</Unhealable> 51 <Repairable>true</Repairable>52 51 </Health> 52 <Repairable> 53 <RepairTimeRatio>2.0</RepairTimeRatio> 54 </Repairable> 53 55 <Identity> 54 56 <GenericName>Structure</GenericName> 55 57 <Classes datatype="tokens">Structure ConquestCritical</Classes> -
binaries/data/mods/public/simulation/templates/template_unit.xml
32 32 <Max>100</Max> 33 33 <RegenRate>0</RegenRate> 34 34 <Unhealable>false</Unhealable> 35 <Repairable>false</Repairable>36 35 </Health> 37 36 <Identity> 38 37 <GenericName>Unit</GenericName> 39 38 <Classes datatype="tokens">Unit ConquestCritical</Classes> 40 41 42 39 <Formations datatype="tokens"> 40 formations/null 41 </Formations> 43 42 </Identity> 44 43 <Looter/> 45 44 <Minimap> -
binaries/data/mods/public/simulation/templates/template_unit_fauna_hunt_whale.xml
8 8 <Max>200</Max> 9 9 <DeathType>remain</DeathType> 10 10 <Unhealable>true</Unhealable> 11 <Repairable>false</Repairable>12 11 </Health> 13 12 <Identity> 14 13 <Classes datatype="tokens">SeaCreature</Classes> 15 14 <Civ>gaia</Civ> 16 15 <GenericName>Cetacean</GenericName> 17 16 <Tooltip>Kill, then collect food from this bountiful oceanic resource.</Tooltip> 18 17 <Icon>gaia/fauna_fish.png</Icon> 19 18 </Identity> 20 19 <Position> 21 20 <Floating>true</Floating> 22 21 </Position> 23 22 <ResourceSupply> 24 23 <KillBeforeGather>true</KillBeforeGather> 25 24 <Amount>2000</Amount> 26 25 <Type>food.fish</Type> 27 26 <MaxGatherers>5</MaxGatherers> 28 27 </ResourceSupply> 29 28 <Selectable> 30 29 <Overlay> -
binaries/data/mods/public/simulation/templates/template_unit_mechanical.xml
7 7 </Decay> 8 8 <Health> 9 9 <Unhealable>true</Unhealable> 10 <Repairable>true</Repairable>11 10 </Health> 11 <Repairable> 12 <RepairTimeRatio>4.0</RepairTimeRatio> 13 </Repairable> 12 14 <Identity> 13 15 <GenericName>Mechanical</GenericName> 14 16 <VisibleClasses datatype="tokens">Mechanical</VisibleClasses>