- Timestamp:
- 08/11/11 01:57:54 (13 years ago)
- Location:
- ps/trunk/binaries/data/mods/public
- Files:
-
- 3 edited
-
gui/session/input.js (modified) (2 diffs)
-
simulation/components/BuildRestrictions.js (modified) (7 diffs)
-
simulation/components/GuiInterface.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/binaries/data/mods/public/gui/session/input.js
r9970 r9991 563 563 "z": placementPosition.z 564 564 }); 565 if (snapData .snapped)565 if (snapData) 566 566 placementAngle = snapData.angle; 567 567 … … 825 825 "z": placementPosition.z 826 826 }); 827 if (snapData .snapped)827 if (snapData) 828 828 placementAngle = snapData.angle; 829 829 -
ps/trunk/binaries/data/mods/public/simulation/components/BuildRestrictions.js
r9970 r9991 140 140 if (this.template.Category == "Dock") 141 141 { 142 // Dock must be oriented from land facing into water 142 // TODO: Probably should check unit passability classes here, to determine if: 143 // 1. ships can be spawned "nearby" 144 // 2. builders can pass the terrain where the dock is placed (don't worry about paths) 145 // so it's correct even if the criteria changes for these units 143 146 var cmpFootprint = Engine.QueryInterface(this.entity, IID_Footprint); 144 147 if (!cmpFootprint) … … 158 161 halfSize = shape.radius; 159 162 } 160 163 161 164 var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain); 162 165 var cmpWaterManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_WaterManager); … … 169 172 var sz = halfSize * Math.sin(ang); 170 173 var cz = halfSize * Math.cos(ang); 171 if ((cmp Terrain.GetGroundLevel(pos.x + sz, pos.y + cz) > cmpWaterManager.GetWaterLevel(pos.x + sz, pos.y + cz)) ||// front172 (cmpTerrain.GetGroundLevel(pos.x - sz, pos.y - cz) <= cmpWaterManager.GetWaterLevel(pos.x - sz, pos.y - cz))) // back174 if ((cmpWaterManager.GetWaterLevel(pos.x + sz, pos.y + cz) - cmpTerrain.GetGroundLevel(pos.x + sz, pos.y + cz)) < 1.0 // front 175 || (cmpWaterManager.GetWaterLevel(pos.x - sz, pos.y - cz) - cmpTerrain.GetGroundLevel(pos.x - sz, pos.y - cz)) > 2.0) // back 173 176 { 174 177 return false; // Fail … … 179 182 if (this.template.Distance) 180 183 { 181 var minDist = 65535; 182 var maxDist = 0; 184 var nearest = 65535; 183 185 var ents = Engine.GetEntitiesWithInterface(IID_BuildRestrictions); 184 186 for each (var ent in ents) … … 186 188 var cmpBuildRestrictions = Engine.QueryInterface(ent, IID_BuildRestrictions); 187 189 if (cmpBuildRestrictions.GetCategory() == this.template.Distance.FromCategory && IsOwnedByPlayer(player, ent)) 188 { 190 { // Find nearest building matching this category 189 191 var cmpEntPosition = Engine.QueryInterface(ent, IID_Position); 190 192 if (cmpEntPosition && cmpEntPosition.IsInWorld()) … … 192 194 var entPos = cmpEntPosition.GetPosition2D(); 193 195 var dist = Math.sqrt((pos.x-entPos.x)*(pos.x-entPos.x) + (pos.y-entPos.y)*(pos.y-entPos.y)); 194 if (dist < minDist)196 if (dist < nearest) 195 197 { 196 minDist = dist; 197 } 198 if (dist > maxDist) 199 { 200 maxDist = dist; 198 nearest = dist; 201 199 } 202 200 } … … 204 202 } 205 203 206 if ( this.template.Distance.MinDistance !== undefined && minDist < this.template.Distance.MinDistance207 || this.template.Distance.MaxDistance !== undefined && maxDist > this.template.Distance.MaxDistance)204 if ((this.template.Distance.MinDistance && nearest < this.template.Distance.MinDistance) 205 || (this.template.Distance.MaxDistance && nearest > this.template.Distance.MaxDistance)) 208 206 { 209 207 return false; // Fail -
ps/trunk/binaries/data/mods/public/simulation/components/GuiInterface.js
r9970 r9991 510 510 var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain); 511 511 var cmpWaterManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_WaterManager); 512 if (!cmpTerrain || !cmpWaterManager) 513 { 514 return false; 515 } 516 517 // Get footprint size 518 var halfSize = 0; 519 if (template.Footprint.Square) 520 { 521 halfSize = Math.max(template.Footprint.Square["@depth"], template.Footprint.Square["@width"])/2; 522 } 523 else if (template.Footprint.Circle) 524 { 525 halfSize = template.Footprint.Circle["@radius"]; 526 } 512 527 513 528 // Find direction of most open water, algorithm: … … 518 533 // 5. Calculate angle using average of sequence 519 534 const numPoints = 16; 520 const dist = 20.0;521 535 var waterPoints = []; 522 536 for (var i = 0; i < numPoints; ++i) 523 537 { 524 538 var angle = (i/numPoints)*2*Math.PI; 525 var nx = data.x - dist*Math.sin(angle);526 var nz = data.z + dist*Math.cos(angle);539 var nx = data.x - halfSize*Math.sin(angle); 540 var nz = data.z + halfSize*Math.cos(angle); 527 541 528 542 if (cmpTerrain.GetGroundLevel(nx, nz) < cmpWaterManager.GetWaterLevel(nx, nz)) … … 560 574 } 561 575 562 return { "snapped": true,"x": data.x, "z": data.z, "angle": -(((waterPoints[start] + consec[start]/2) % numPoints)/numPoints*2*Math.PI) };563 } 564 565 return {"snapped": false};576 return {"x": data.x, "z": data.z, "angle": -(((waterPoints[start] + consec[start]/2) % numPoints)/numPoints*2*Math.PI) }; 577 } 578 579 return false; 566 580 }; 567 581
Note:
See TracChangeset
for help on using the changeset viewer.
