Ticket #797: units_on_walls.diff
File units_on_walls.diff, 6.7 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/components/BuildingWalker.js
1 2 function BuildingWalker() {} 3 4 BuildingWalker.prototype.Schema = 5 "<element name='WalkingHeight'>" + 6 "<ref name='nonNegativeDecimal'/>" + 7 "</element>"; 8 9 BuildingWalker.prototype.Init = function() 10 { 11 warn("created"); 12 this.buildingEntities = []; 13 // TODO 14 }; 15 16 BuildingWalker.prototype.GetWalkingHeight = function() 17 { 18 var walkingHeight = +this.template.WalkingHeight; 19 return ApplyTechModificationsToEntity("BuildingWalker/WalkingHeight", walkingHeight, this.entity); 20 }; 21 22 BuildingWalker.prototype.AddEntity = function(entity) 23 { 24 this.buildingEntities.push(entity); 25 var cmpPosition = Engine.QueryInterface(entity, IID_Position); 26 var thisPosition = Engine.QueryInterface(this.entity, IID_Position); 27 cmpPosition.SetHeightFixed(this.GetWalkingHeight() + thisPosition.GetPosition().y); 28 } 29 30 BuildingWalker.prototype.RemoveEntity = function(entity) 31 { 32 var index = this.buildingEntities.indexOf(entity); 33 if (index == -1) 34 return; 35 this.buildingEntities.splice(index,1); 36 var cmpPosition = Engine.QueryInterface(entity, IID_Position); 37 cmpPosition.SetHeightOffset(0.0); 38 39 } 40 41 BuildingWalker.prototype.OnDestroy = function() 42 { 43 for (var i = 0; i < this.buildingEntities.length; i++) 44 { 45 this.RemoveEntity(this.buildingEntities[i]); 46 // TODO garison to neares tower, or unload next to gate 47 } 48 } 49 50 Engine.RegisterComponentType(IID_BuildingWalker, "BuildingWalker", BuildingWalker); -
binaries/data/mods/public/simulation/components/GarrisonHolder.js
197 197 198 198 var cmpNewPosition = Engine.QueryInterface(entity, IID_Position); 199 199 cmpNewPosition.JumpTo(pos.x, pos.z); 200 // TODO notify walls units are garisoning, instead of just redefining the offset 201 cmpNewPosition.SetHeightOffset(0.0); 200 202 // TODO: what direction should they face in? 201 203 202 204 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {}); … … 225 227 } 226 228 }; 227 229 230 GarrisonHolder.prototype.EjectToWall = function(entities, forced, targetID) 231 { 232 var buildingWalker = Engine.QueryInterface(targetID, IID_BuildingWalker); 233 var targetPos = Engine.QueryInterface(targetID, IID_Position).GetPosition(); 234 var thisPos = Engine.QueryInterface(this.entity, IID_Position).GetPosition2D(); 235 var dv = {x: targetPos.x-thisPos.x, y:targetPos.z-thisPos.y}; 236 var l = Math.sqrt(dv.x * dv.x + dv.y * dv.y); 237 238 for (var i = 0; i < entities.length; i++) 239 { 240 241 // TODO only allow ranged units, 242 // check if there is some space left, 243 // only ungarison if you're on the target wall, not next to it 244 // ... 245 246 var entityIndex = this.entities.indexOf(entities[i]); 247 248 this.spaceOccupied -= 1; 249 this.entities.splice(entityIndex, 1); 250 251 var cmpUnitAI = Engine.QueryInterface(entities[i], IID_UnitAI); 252 if (cmpUnitAI) 253 cmpUnitAI.Ungarrison(); 254 255 var cmpProductionQueue = Engine.QueryInterface(entities[i], IID_ProductionQueue); 256 if (cmpProductionQueue) 257 cmpProductionQueue.UnpauseProduction(); 258 259 var cmpPosition = Engine.QueryInterface(entities[i], IID_Position); 260 cmpPosition.JumpTo(thisPos.x + dv.x / l * (7+2*i), thisPos.y + dv.y / l * (7+2*i)); 261 buildingWalker.AddEntity(entities[i]); 262 263 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, {}); 264 265 } 266 267 this.UpdateGarrisonFlag(); 268 var success = true; 269 return success; 270 271 }; 272 228 273 /** 229 274 * Ejects units and orders them to move to the Rally Point. 230 275 * Returns true if successful, false if not … … 233 278 { 234 279 var ejectedEntities = []; 235 280 var success = true; 281 var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 282 var template = cmpTemplateManager.GetCurrentTemplateName(this.entity); 283 if (template.indexOf("wall_tower") != -1) 284 { 285 // this is a wall tower, is it ejecting to a wall? 286 var cmpRallyPoint = Engine.QueryInterface(this.entity, IID_RallyPoint); 287 var commands = GetRallyPointCommands(cmpRallyPoint, entities); 288 warn(cmpRallyPoint.GetPositions()[0].x+", "+cmpRallyPoint.GetPositions()[0].z); 289 290 // TODO only works when wall is repairable 291 // instead use the position query, and query for objectso n this position 292 if (commands.length > 0 && commands[0].target) 293 { 294 warn(commands[0].target.toString()); 295 var buildingWalker = Engine.QueryInterface(commands[0].target, IID_BuildingWalker); if (buildingWalker) 296 return this.EjectToWall(entities, forced, commands[0].target); 297 } 298 299 } 300 236 301 for each (var entity in entities) 237 302 { 238 303 if (this.Eject(entity, forced)) -
binaries/data/mods/public/simulation/templates/structures/iber_wall_long.xml
1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <Entity parent="template_structure_defense_wall_long"> 3 <BuildingWalker> 4 <WalkingHeight>8.5</WalkingHeight> 5 </BuildingWalker> 3 6 <Footprint> 4 <Square width="37" depth=" 9"/>7 <Square width="37" depth="11"/> 5 8 <Height>9.0</Height> 6 9 </Footprint> 7 10 <Identity> … … 11 14 <History>High and strongly built defensive stone walls were a common structure of the Iberian Peninsula during the period, and for long thereafter.</History> 12 15 </Identity> 13 16 <Obstruction> 14 <Static width="36.0" depth="8"/> 17 <Obstructions> 18 <Front width="36.0" depth="4.0" x="0.0" z="4.5"/> 19 <Back width="36.0" depth="4.0" x="0.0" z="-4.5"/> 20 <Left width="1.0" depth="10.0" x="-17.5" z="0.0"/> 21 <Right width="1.0" depth="10.0" x="17.5" z="0.0"/> 22 </Obstructions> 15 23 </Obstruction> 16 24 <VisualActor> 17 25 <Actor>structures/iberians/wall_long.xml</Actor> -
binaries/data/mods/public/simulation/templates/template_structure_defense_wall.xml
31 31 <stone>15</stone> 32 32 <metal>0</metal> 33 33 </Loot> 34 <Obstruction>35 <Static width="6.0" depth="6.0"/>36 </Obstruction>37 34 <RallyPoint disable=""/> 38 35 <Sound> 39 36 <SoundGroups>