Ticket #2062: watersink.2.patch
File watersink.2.patch, 7.5 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/components/UnitMotionFlying.js
1 1 // (A serious implementation of this might want to use C++ instead of JS 2 2 // for performance; this is just for fun.) 3 const shortFinal= 2.5;3 const SHORT_FINAL = 2.5; 4 4 function UnitMotionFlying() {} 5 5 6 6 UnitMotionFlying.prototype.Schema = … … 58 58 var cmpPosition = Engine.QueryInterface(this.entity, IID_Position); 59 59 var pos = cmpPosition.GetPosition(); 60 60 var angle = cmpPosition.GetRotation().y; 61 61 var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain); 62 var ground = cmpTerrain.GetGroundLevel(pos.x, pos.z); 63 var cmpWaterManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_WaterManager); 64 var ground = Math.max(cmpTerrain.GetGroundLevel(pos.x, pos.z), cmpWaterManager.GetWaterLevel(pos.x, pos.z)); 62 65 var canTurn = true; 63 66 64 if ( !this.landing)67 if (this.landing) 65 68 { 66 // If we haven't reached max speed yet then we're still on the ground;67 // otherwise we're taking off or flying68 // this.onGround in case of a go-around after landing (but not fully stopped)69 var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain);70 var ground = cmpTerrain.GetGroundLevel(pos.x, pos.z);71 if (this.speed < this.template.TakeoffSpeed && this.onGround)72 {73 // Accelerate forwards74 this.speed = Math.min(this.template.MaxSpeed, this.speed + turnLength * this.template.AccelRate);75 canTurn = false;76 // Clamp to ground if below it, or descend if above77 if (pos.y < ground)78 pos.y = ground;79 else if (pos.y > ground)80 pos.y = Math.max(ground, pos.y - turnLength * this.template.ClimbRate);81 }82 else83 {84 this.onGround = false;85 // Climb/sink to max height above ground86 this.speed = Math.min(this.template.MaxSpeed, this.speed + turnLength * this.template.AccelRate);87 var targetHeight = ground + (+this.template.FlyingHeight);88 if (pos.y < targetHeight)89 pos.y = Math.min(targetHeight, pos.y + turnLength * this.template.ClimbRate);90 else if (pos.y > targetHeight)91 pos.y = Math.max(targetHeight, pos.y - turnLength * this.template.ClimbRate);92 }93 cmpPosition.SetHeightFixed(pos.y);94 }95 else96 {97 69 if (this.speed > 0 && this.onGround) 98 70 { 99 71 // Deaccelerate forwards...at a very reduced pace. 100 72 this.speed = Math.max(0, this.speed - turnLength * this.template.BrakingRate); 101 73 canTurn = false; 102 // Clamp to ground if below it, or descend if above 103 var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain); 104 var ground = cmpTerrain.GetGroundLevel(pos.x, pos.z); 74 // Clamp to ground if below it, or descend if above 105 75 if (pos.y < ground) 106 76 pos.y = ground; 107 77 else if (pos.y > ground) 108 pos.y = Math.max(ground, pos.y - turnLength * this.template.ClimbRate); 109 cmpPosition.SetHeightFixed(pos.y); 78 pos.y = Math.max(ground, pos.y - turnLength * this.template.ClimbRate); 110 79 } 111 80 else if (this.speed == 0) 112 81 { … … 121 90 // We need to slow down to land! 122 91 this.speed = Math.max(this.template.LandingSpeed, this.speed - turnLength * this.template.SlowingRate); 123 92 canTurn = false; 124 var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain);125 var ground = cmpTerrain.GetGroundLevel(pos.x, pos.z);126 93 var targetHeight = ground; 127 94 // Steep, then gradual descent. 128 var descentRate = ((pos.y - targetHeight) / this.template.FlyingHeight * this.template.ClimbRate + shortFinal) * shortFinal;95 var descentRate = ((pos.y - targetHeight) / this.template.FlyingHeight * this.template.ClimbRate + SHORT_FINAL) * SHORT_FINAL; 129 96 if (pos.y < targetHeight) 130 97 pos.y = Math.max(targetHeight, pos.y + turnLength * descentRate); 131 98 else if (pos.y > targetHeight) 132 99 pos.y = Math.max(targetHeight, pos.y - turnLength * descentRate); 133 100 if (targetHeight == pos.y) 134 101 this.onGround = true; 135 cmpPosition.SetHeightFixed(pos.y);136 102 } 137 103 } 104 else 105 { 106 // If we haven't reached max speed yet then we're still on the ground; 107 // otherwise we're taking off or flying 108 // this.onGround in case of a go-around after landing (but not fully stopped) 109 if (this.speed < this.template.TakeoffSpeed && this.onGround) 110 { 111 // Accelerate forwards 112 this.speed = Math.min(this.template.MaxSpeed, this.speed + turnLength * this.template.AccelRate); 113 canTurn = false; 114 // Clamp to ground if below it, or descend if above 115 if (pos.y < ground) 116 pos.y = ground; 117 else if (pos.y > ground) 118 pos.y = Math.max(ground, pos.y - turnLength * this.template.ClimbRate); 119 } 120 else 121 { 122 this.onGround = false; 123 // Climb/sink to max height above ground 124 this.speed = Math.min(this.template.MaxSpeed, this.speed + turnLength * this.template.AccelRate); 125 var targetHeight = ground + (+this.template.FlyingHeight); 126 if (pos.y < targetHeight) 127 pos.y = Math.min(targetHeight, pos.y + turnLength * this.template.ClimbRate); 128 else if (pos.y > targetHeight) 129 pos.y = Math.max(targetHeight, pos.y - turnLength * this.template.ClimbRate); 130 } 131 } 138 132 139 133 // If we're in range of the target then tell people that we've reached it 140 134 // (TODO: quantisation breaks this) … … 144 138 this.reachedTarget = true; 145 139 Engine.PostMessage(this.entity, MT_MotionChanged, { "starting": false, "error": false }); 146 140 } 147 148 141 // If we're facing away from the target, and are still fairly close to it, 149 142 // then carry on going straight so we overshoot in a straight line 150 143 var isBehindTarget = ((this.targetX - pos.x) * Math.sin(angle) + (this.targetZ - pos.z) * Math.cos(angle) < 0); 151 144 // Overshoot the target: carry on straight 152 145 if (isBehindTarget && distFromTarget < this.template.MaxSpeed * this.template.OvershootTime) 153 146 canTurn = false; 154 155 147 if (canTurn) 156 148 { 157 149 // Turn towards the target … … 170 162 171 163 pos.x += this.speed * turnLength * Math.sin(angle); 172 164 pos.z += this.speed * turnLength * Math.cos(angle); 173 165 cmpPosition.SetHeightFixed(pos.y); 174 166 cmpPosition.TurnTo(angle); 175 167 cmpPosition.MoveTo(pos.x, pos.z); 176 168 }; -
binaries/data/mods/public/simulation/templates/other/plane.xml
13 13 <Spread>1.5</Spread> 14 14 </Ranged> 15 15 </Attack> 16 <BuildingAI> 17 <DefaultArrowCount>3</DefaultArrowCount> 18 <GarrisonArrowMultiplier>1</GarrisonArrowMultiplier> 19 <GarrisonArrowClasses>Infantry</GarrisonArrowClasses> 20 </BuildingAI> 21 <GarrisonHolder> 22 <Max>1</Max> 23 <EjectHealth>0</EjectHealth> 24 <List datatype="tokens">Support Infantry</List> 25 <BuffHeal>1</BuffHeal> 26 <LoadingRange>5</LoadingRange> 27 </GarrisonHolder> 16 28 <Identity> 17 29 <Civ>hele</Civ> 18 30 <SpecificName>P-51 Mustang</SpecificName> … … 21 33 <Icon>units/global_mustang.png</Icon> 22 34 <Formations datatype="tokens" replace=""/> 23 35 </Identity> 36 <Health> 37 <Max>100</Max> 38 <Unhealable>true</Unhealable> 39 <Repairable>true</Repairable> 40 </Health> 24 41 <Obstruction disable=""/> 25 42 <Position> 26 43 <TurnRate>1.0</TurnRate> … … 36 53 <TurnRate>1.0</TurnRate> 37 54 <OvershootTime>2.0</OvershootTime> 38 55 <FlyingHeight>50.0</FlyingHeight> 39 <ClimbRate> 5.0</ClimbRate>56 <ClimbRate>15.0</ClimbRate> 40 57 </UnitMotionFlying> 41 58 <Vision> 42 59 <Range>100</Range>