Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 |
//============================================================================= // Dead Reckoning. //============================================================================= class DeadReckoning extends Object config(USARBotAPI); //----------------------------------------------------------------------------- // Structurs. struct DRMovement { var float DR_T; var vector DR_P; var vector DR_V; var vector DR_A; var rotator DR_RP; var rotator DR_RV; var rotator DR_RA; }; struct Inf { var rotator RotationRate; var bool bRotateToDesired; var bool bRollToDesired; //var bool bCarriedItem; var float NetPriority; }; //----------------------------------------------------------------------------- // Variables. var DRMovement start; var DRMovement current; var DRMovement cache; var float deltatime; var Inf oldInf; var bool bRunning; var bool bLFilter; var bool bRFilter; var Pawn owner; var config int PreK; var config int MaxErr; var bool bNewBase; var bool bLocked; var bool bAutoTurn; //----------------------------------------------------------------------------- // Functions. function Save(Pawn owner) { oldInf.RotationRate = owner.RotationRate; oldInf.bRotateToDesired = owner.bRotateToDesired; oldInf.bRollToDesired = owner.bRollToDesired; //oldInf.bCarriedItem = owner.bCarriedItem; oldInf.NetPriority = owner.NetPriority; } function Restore(Pawn owner) { owner.RotationRate = oldInf.RotationRate; owner.bRotateToDesired = oldInf.bRotateToDesired; owner.bRollToDesired = oldInf.bRollToDesired; //owner.bCarriedItem = oldInf.bCarriedItem; owner.NetPriority = oldInf.NetPriority; } function SetT(float time) { CurL(time); CurR(time); current.DR_P = owner.Location; start.DR_P = current.DR_P; start.DR_V = current.DR_V; start.DR_A = current.DR_A; current.DR_RP = owner.Rotation; start.DR_RP = current.DR_RP; start.DR_RV = current.DR_RV; start.DR_RA = current.DR_RA; start.DR_T = time; bNewBase=true; bLocked=false; if (current.DR_RV.Pitch==0 && current.DR_RV.Yaw==0 && current.DR_RV.Roll==0 && current.DR_RA.Pitch==0 && current.DR_RA.Yaw==0 && current.DR_RA.Roll==0) bAutoTurn=true; //if(oldInf.NetPriority>0) owner.NetPriority = oldInf.NetPriority; } function SetDT(float dt) { deltatime = dt; //current.DR_V = current.DR_V + current.DR_A * dt * 0.5; // init //current.DR_RV = current.DR_RV + current.DR_RA * dt * 0.5; // init } function SetLP(vector p) { start.DR_P = p; current.DR_P = p; bLFilter = true; } function SetLV(vector v) { start.DR_V = v; current.DR_V = v; } function SetLA(vector a) { start.DR_A = a; current.DR_A = a; } function SetRP(rotator p) { start.DR_RP = p; current.DR_RP = p; bRFilter = false; bAutoTurn=false; //bRFilter = true; } function SetRV(rotator v) { start.DR_RV = v; current.DR_RV = v; bAutoTurn=false; } function SetRA(rotator a) { start.DR_RA = a; current.DR_RA = a; bAutoTurn=false; } function SetL(vector p, vector v, vector a) { start.DR_P = p; start.DR_V = v; start.DR_A = a; current.DR_P = p; current.DR_V = v; current.DR_A = a; } function SetR(rotator p, rotator v, rotator a) { start.DR_RP = p; start.DR_RV = v; start.DR_RA = a; current.DR_RP = p; current.DR_RV = v; current.DR_RA = a; } function bool setCache() { if (!bLocked) { cache.DR_P = current.DR_P; cache.DR_V = current.DR_V; cache.DR_A = current.DR_A; return true; } return false; } function bool Recover() { if (!bLocked) { current.DR_V = cache.DR_V; current.DR_A = cache.DR_A; return true; } return false; } function Locked() { bLocked=true; } function UnLocked() { bLocked=false; } function bool isLocked() { return bLocked; } function NewBase(bool b) { bNewBase=b; } function bool isNewBase() { return bNewBase; } function CurL(float t) { local float dt,tmp; dt = t - start.DR_T; tmp = dt*dt*0.5; current.DR_P = start.DR_P + start.DR_V * dt + start.DR_A * tmp; current.DR_V = start.DR_V + start.DR_A * dt; } function CurR(float t) { local float dt,tmp; dt = t - start.DR_T; tmp = dt*dt*0.5; current.DR_RP = start.DR_RP + start.DR_RV * dt + start.DR_RA * tmp; current.DR_RV = start.DR_RV + start.DR_RA * dt; } function vector PreLP(float t) { local float dt,tmp; dt = t - start.DR_T; tmp = dt*dt*0.5; return (start.DR_P + start.DR_V * dt + start.DR_A * tmp); } function rotator PreRP(float t) { local float dt,tmp; dt = t - start.DR_T; tmp = dt*dt*0.5; return (start.DR_RP + start.DR_RV * dt + start.DR_RA * tmp); } function GetL( ) { current.DR_V = current.DR_V + current.DR_A * deltatime; current.DR_P = current.DR_P + current.DR_V * deltatime; } function GetR( ) { current.DR_RV = current.DR_RV + current.DR_RA * deltatime; current.DR_RP = current.DR_RP + current.DR_RV * deltatime; } function vector FGetL( ) { local int i; local vector v,p; if (current.DR_V.x==0 && current.DR_V.y==0 && current.DR_V.z==0 && current.DR_A.x==0 && current.DR_A.y==0 && current.DR_A.z==0 ) // This means we need to forcely relocate a bot return current.DR_P; GetL(); v = current.DR_V; p = current.DR_P; for (i=1;i<PreK;i++) { v += current.DR_A * deltatime; p += v * deltatime; } return (p-owner.Location)/PreK+owner.Location; } function rotator FGetR( ) { local int i; local rotator rv,rp; if (current.DR_RV.pitch==0 && current.DR_RV.yaw==0 && current.DR_RV.roll==0 && current.DR_RA.pitch==0 && current.DR_RA.yaw==0 && current.DR_RA.roll==0 ) // This means we need to forcely relocate a bot return current.DR_RP; GetR(); rv = current.DR_RV; rp = current.DR_RP; for (i=1;i<PreK;i++) { rv += current.DR_RA * deltatime; rp += rv * deltatime; } return (rp-owner.Rotation)/PreK+owner.Rotation; } function bool Step(float dt) { log("Step()"); if (bRunning) { deltatime = dt; GetR(); owner.RotationRate=rot(0,0,0); owner.DesiredRotation = current.DR_RP; owner.SetRotation(current.DR_RP); GetL(); return owner.SetLocation(current.DR_P); } } function bool IsRunning() { // log("DeadReckoning running:"$bRunning$" rp("$current.DR_RP$") rv("$current.DR_RV$") ra("$current.DR_RA$") p("$current.DR_P$") v("$current.DR_V$") a("$current.DR_A$")"); return bRunning; } function init(Pawn act) { owner = act; SetL(act.Location,act.Velocity,act.Acceleration); SetRP(act.Rotation); } function Stop() { bRunning = false; bLFilter = false; bRFilter = false; // Reset all the args. SetL(owner.Location,vect(0,0,0),vect(0,0,0)); SetR(owner.Rotation,rot(0,0,0),rot(0,0,0)); Restore(owner); } function Begin() { bRunning = true; bAutoTurn=true; Save(owner); owner.RotationRate=rot(0,0,0); owner.bRotateToDesired=true; owner.bRollToDesired=true; //owner.NetPriority=2.0; // Because we can control remotebot from client, we set the NetPriority lower. owner.bCollideWorld=true; // Should I set this? // Hack 10JAN03 //owner.bCarriedItem = true; // Disable replicate Location and Rotation between S/C /* Region.Zone.ZoneGravity.z=0; Region.Zone.ZoneGroundFriction=0; Region.Zone.ZoneFluidFriction=0; AirControl = 0; */ } function bool Correct(float time) { local rotator dr; CurR(time); dr = owner.Rotation-current.DR_RP; if (bRFilter&& (dr.pitch*dr.pitch+dr.yaw*dr.yaw+dr.roll*dr.roll)<MaxErr*MaxErr*10000) { bRFilter=false; owner.RotationRate=rot(0,0,0); owner.DesiredRotation = current.DR_RP; owner.SetRotation(current.DR_RP); } CurL(time); if (bLFilter&&VSize(owner.Location-current.DR_P)<MaxErr) { bLFilter=false; owner.SetLocation(current.DR_P); } if (VSize(owner.Location-current.DR_P)>1) return false; //bRunning=true; return true; } defaultproperties { PreK=15 MaxErr=20 } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |