1
2
3
5{
8}
9
10void LongFrameStructuralChecks()
11{
12
13
14 for (auto sample : {std::pair<float,float>{1.432f,.415889f},{1.522f,.363998f},
15 {1.339f,.361211f},{2.767f,.385156f},{3.544f,.355792f},{1.108f,.363179f}})
19 {
24 view.
sumofforces=threshold*(sample.first/(60*sample.second));
27 "recorded long-frame loads reproduce the previous false-damage calculation");
31 "all six trace loads are harmless without a collision, on every possible dominant axis");
32 }
33 for (float dt : {1.f/144,1.f/60,1.f/30,.355792f,.385156f,.415889f,1.f,2.f})
34 {
42
43
50 "real impacts retain identical hull/glass damage even during a two-second stall");
53 game.bus->ProgramTime=2.1;view.
sumofforces=sustained;
56
60 }
77 std::cout<<"PASS: six trace regressions, long-frame steady loads, real impacts, sustained overload and simulator transitions\n";
78}
79
80void CrashTimingChecks()
81{
86 "fault severity retains every existing directional crash threshold");
87 for (unsigned severity=1;severity<=4;++severity)
89 "fault probability scales from 25 percent to 100 percent with impact severity");
90 unsigned triggered=0;
91 for(unsigned roll=0;roll<=32767;++roll)
92 {
96 Check((!mild || moderate) && severe,"stronger impacts cannot reduce fault chance");
97 triggered+=moderate?1:0;
98 }
99 Check(triggered==16384,"twice-threshold impact has exactly 50 percent fault chance");
101 "recorded C-2 impact guarantees an eligible control upset");
102 for (int windshield : {-1,0,33,127})
103 {
109 CrashImpulseSample(view,{0,1,0});
111 "occupant jolt can hit the stalk but cannot create a persistent horn fault");
113 "an occupant jolt alone cannot damage the frame or glass");
116 const auto events=game.net.events.size();
117 CrashImpulseSample(view,{0,1,0});
119 Check(!
playerships[0].rainProtectionEnabled && game.net.events.size()==events,
120 "turning wipers off survives the same jolt and a latched horn");
121 game.bus->ProgramTime=.51;
122 CrashImpulseSample(view,{0,1,0});
123 Check(
playerships[0].rainProtectionEnabled,
"a separate occupant jolt can hit the stalk again");
124 }
125 for (unsigned seed=0;seed<64;++seed)
126 {
131 CrashImpulseSample(view,{0,1,-127});
133 "glass follows actual frame loss rather than an independent random damage roll");
135 "frame and glass damage alone do not hit the wiper stalk");
137 "structural damage can only emit a horn fault, not a wiper command");
138 }
139 for (int hull : {-1,0})
140 {
144 view.
sumofforces={0,1,0};CrashImpulseSample(view,{0,1,-127});
146 }
147 for (int guard=0;guard<3;++guard)
148 {
154 game.gui.player[0].frame=guard==2?1:0;
155 CrashImpulseSample(view,{0,1,0});
156 Check(
playerships[0].rainProtectionEnabled==(guard==1),
157 "stalk upset needs fitted wipers and an occupant at the controls");
158 Check(!
playerships[0].crashHornFault,
"occupant-only jolts never latch the horn");
159 }
160 unsigned outcomes=0;
161 for(unsigned seed=0;seed<128;++seed)
162 {
166 CrashImpulseSample(view,{0,1,0});
168 outcomes|=1u<<outcome;
169 }
170 Check(outcomes==3,"moderate occupant-only jolts can hit or miss the stalk, never latch the horn");
171 outcomes=0;
172 for(unsigned seed=0;seed<256;++seed)
173 {
180 outcomes|=1u<<outcome;
181 }
182 Check(outcomes==15,"combined occupant and structural loads allow wipers only, horn only, both or neither");
183 for (unsigned fps : {30u,60u,144u})
184 {
190 srand(37);
195 for (unsigned frame=1;frame<fps*2;++frame)
196 {
197 game.bus->ProgramTime=double(frame)/fps;
199 }
201 "continuing contact is charged once at every tested frame rate");
203 game.bus->ProgramTime+=.51;
206 }
210 for (unsigned seed=0;seed<64;++seed)
211 {
215 "severe jolt hits the stalk while alive but cannot short a horn without new hull damage");
216 }
218 const auto events=game.net.events.size();
220 Check(game.net.events.size()==events,"latched fault cannot resend or toggle the wipers off");
226 "simulator entry clears local and remote crash faults and contact memory");
229 ReceiveCrashFaultFixture(1,1.f);
230 Check(!
playerships[1].crashHornFault,
"received crash faults cannot latch while in simulator");
231 Check(!
playerships[0].crashHornFault && game.net.events.size()==events,
232 "simulator cannot emit a crash fault or wiper event");
238 "simulator baseline structural damage remains, without exterior fault activation");
241 "exit cannot replay a cached crash fault");
242 ReceiveCrashFaultFixture(1,1.f);
243 Check(
playerships[1].crashHornFault,
"new remote crash fault works outside simulator");
245 Check(!
playerships[1].crashHornFault,
"simulated remote vehicles cannot latch crash faults");
248 for (int guard=0;guard<3;++guard)
249 {
256 "death, spawn protection and interiors suppress occupant control upsets");
257 }
259 std::cout<<"PASS: occupant stalk activation and structural horn/glass damage, animation timing, contact grouping and simulator transitions\n";
260}
261
262void StructuralCrushChecks()
263{
264 for (unsigned fps : {30u,60u,144u})
265 for (unsigned seed=0;seed<64;++seed)
266 {
272 game.bus->ProgramTime=1;
274 const float dt=1.f/fps;
276 view.
sumofforces=load;srand(seed);game.bus->ProgramTime+=dt;
277 CrashImpulseSample(view,load,dt);
280 "60 km/h left-corner impulse gives identical hull/glass loss and lamp destruction at every FPS and RNG seed");
281 game.bus->ProgramTime+=dt;CrashImpulseSample(view,load,dt);
283 }
284 for (auto sample : {std::pair<float,float>{103.320786f,.0168485995f}, {103.346191f,.0165435001f}})
285 {
287 Check(loss>=85 && loss<=87,"both recorded C-2 crashes have comparable major structural damage");
288 }
289 int previous=0;
290 for (unsigned speed=0;speed<=100;++speed)
291 {
293 -(speed/3.6f)/(9.80665f/60),1.f/60));
294 Check(damage>=previous,"increasing speed cannot reduce deterministic structural damage");
295 previous=damage;
296 }
299 int hull=episode.
Apply(127,2);
300 Check(hull==103,"milder collision causes less structural damage");
301 episode.
Begin(1.05);hull=episode.
Apply(hull,4.6f);
302 Check(hull==41,"a stronger sample in the same crash charges only additional peak damage");
303 episode.
Begin(1.1);Check(episode.
Apply(hull,4.6f)==41,
"peak damage is not charged twice");
304 episode.
Begin(2);Check(episode.
Apply(hull,2)==17,
"a separate collision causes new structural damage");
305 Check(episode.
Apply(-1,5)==-1 && episode.
Apply(0,5)==0,
"absent and destroyed hull remain unchanged");
306 for(float dt : {0.f,-1.f,std::numeric_limits<float>::quiet_NaN()})
310 "recorded front crush can short the horn but does not guarantee a closed circuit");
311 for (int loss=1;loss<=127;++loss)
312 {
316 "horn fault chance grows with frontal severity and fresh structural damage");
317 }
320 for (unsigned seed=0;seed<64;++seed)
321 {
325 CrashImpulseSample(view,load);
327 "rear, side and vertical structural loads cannot create a front-circuit fault");
328 }
329 for (int guard=0;guard<4;++guard)
330 for (unsigned seed=0;seed<32;++seed)
331 {
335 game.gui.player[0].frame=guard==1?1:0;
337 srand(seed);CrashImpulseSample(view,{0,1,-127});
339 "structural horn faults require a ground vehicle, controlled vessel and fresh hull loss");
340 }
341 bool reproduced=false;
342 for (unsigned seed=0;seed<256;++seed)
343 {
349 ship.matrixBase=pitch*yaw;
354 LampGameFixture game;LampWeatherFixture
weather;LampMaterialFixture material;
355 game.graphics->g_pEffect=&material;
357 game.bus->ProgramTime=10;
360 game.bus->ProgramTime+=.085;
361 view.
sumofforces={0,1.1492306f,-103.320786f};srand(seed);
363 Check(
ourcockpit.
vdat.
landing[0]==127,
"front-left crush never transfers damage to the uncontacted right lamp");
367 {
368 reproduced=true;
370 "recorded 127-to-41 hull loss destroys the struck left lamp");
374 "trace replay removes the crushed left beam and leaves the right beam at full brightness");
376 }
377 }
378 Check(reproduced,"production crash replay includes the recorded hull damage outcome");
379 for (int guard=0;guard<6;++guard)
380 {
385 game.bus->ProgramTime=10;
388 if (guard==1) game.bus->ProgramTime+=.501;
389 if (guard==2) game.bus->ProgramTime=9;
391 if (guard==4) game.gui.player[0].frame=1;
395 "no contact, expired contact, clock reset, pending snapshot, occupant exit and simulator cannot inherit crush");
396 }
398 int health=contact.
Apply(127,0,8.34f,0);
400 Check(health==63,"moderate frame damage adds only loss beyond the initial strike");
401 for (unsigned frame=6;frame<30;++frame)
403 Check(health==63,"repeated structural reports do not multiply lamp damage");
405 "absent and destroyed lamps remain unchanged");
406 Check(contact.
ApplyFrameDamage(health,86,std::numeric_limits<double>::quiet_NaN())==health,
407 "nonfinite timestamps cannot link contacts to frame damage");
408 std::cout<<"PASS: recorded C-2 corner crush, surviving opposite lamp, beam removal, damage correlation guards and structural horn fault chances\n";
409}
410
411void CollisionCheck(const char* name, bool overlay, float yawAngle)
412{
413 for (unsigned vehicleId : {1u,2u,460u,1000u})
414 for (int side : {-1,0,1})
415 for (float heading : {0.f,.9f})
416 for (unsigned fps : {30u,60u,144u})
417 {
420 ship.
vehicleId=
static_cast<unsigned short>(vehicleId);
431 for(unsigned i=0;i<2;++i)
433
434
435 const auto projection=ForwardProjectionFixture();
438 const unsigned left=projected[0].x<projected[1].x?0:1;
439 if (std::string(name)=="Meshes/C-2 Dasher.daw")
440 Check(left==1,"C-2 trace lamp 1 is the driver's left headlight");
443 "diagnostic sides match the driver's projected view");
444 const float z=(std::min)(mounts[0].z,mounts[1].z)-.0003f;
445 const float extent=(std::max)(std::abs(mounts[0].x),std::abs(mounts[1].x))*3;
446 const float minX=side<0?0.f:-extent,maxX=side>0?0.f:extent;
447 const float y=(mounts[0].y+mounts[1].y)*.5f;
448 LampBufferFixture buffer;
452 {
454 buffer.vertices.push_back({p.x,p.y,p.z});
455 }
456 LampZoneFixture zone;zone.VB=&buffer;zone.drawBatches.push_back({0,0,2,0,0,{}});
457 for (const auto& p:buffer.vertices) {zone.bounds.Include(p);zone.drawBatches[0].bounds.Include(p);}
458
459 zone.terpos={1000,2000,1000};ship.precisionx=-1000;ship.precisiony=-2000;ship.precisionz=-1000;
464 for(unsigned frame=0;frame<fps/10;++frame)
465 {
466 game.bus->ProgramTime=double(frame)/fps;
468 ship.precisionx+=double(networkVelocity.x)/fps;
469 ship.precisiony+=double(networkVelocity.y)/fps;
470 ship.precisionz+=double(networkVelocity.z)/fps;
471 }
472 ship.precisionx=-1000;ship.precisiony=-2000;ship.precisionz=-1000;
473 Check(
ourcockpit.
vdat.
landing[left]==(side>0?127:0),
"left lamp follows left-front geometry, independent of vehicle ID and animation phase");
474 Check(
ourcockpit.
vdat.
landing[1-left]==(side<0?127:0),
"right lamp follows right-front geometry; centered crash can break both");
481 ship.isSimulator=false;
482
483
487 "left-front vehicle contact damages only the contacted lamp");
495 }
496 std::cout<<"PASS: finite building and vehicle contacts, actual left/right mounts, IDs, heading and simulator guards: "<<name<<'\n';
497}
498
499void ContactGeometryChecks()
500{
509
520 "slow contact dims both equally without the vehicle-ID resilience rule");
524 "moderate contact retains the established flicker damage stage");
535}
void DamageLandingLight(unsigned lamp, float clearanceKm, float closingMps, const char *cause)
void ApplyCollisionImpulse(const RiseMath::Vector3 &impulseKms)
void DamageLandingLightsAgainstSphere(const RiseMath::Vector3 ¢erBody, float radiusKm, const RiseMath::Vector3 &velocityBody, float seconds)
void SetRainProtection(bool enabled)
std::unique_ptr< weather > ptrWeather
void SetCrashHornFault(bool enabled)
void UpdateCrashDamage(const RiseMath::Vector3 &frameForces, float seconds)
void DamageLandingLights(const RiseMath::Vector3 &surfaceNormalBody, float planeDistanceKm, const RiseMath::Vector3 &impactVelocityBody, const char *cause)
RiseMath::Vector3 sumofforces
CollisionDamage::StructuralEpisode crashDamageEpisode
void UpdateLandingLights(double seconds)
CollisionDamage::Episode controlJoltEpisode
void ClearCollisionEffects()
RiseMath::Vector3 structuralImpactImpulse
void DamageLandingLightContacts(const RiseMath::Vector3 &velocity, float seconds) const
std::vector< BUILDZONE > buildzones
s_network_objects playerships[MAX_SCAN]
#define oneOvergForceKmssC
float Severity(float x, float y, float z)
int HullDamage(float severity)
float FaultProbability(float severity)
bool TriggersFault(float severity, unsigned roll, unsigned maxRoll)
float HornFaultProbability(float frontalSeverity, int hullBefore, int hullAfter)
float ImpactSeverity(float x, float y, float z, float seconds)
unsigned FromModel(const Effects &effects, std::array< Light, MaxLights > &lights)
const char * BodySide(float x)
float Vec3Length(const Vector3 *a)
Vector3 * Vec3TransformCoord(Vector3 *out, const Vector3 *a, const Matrix *m)
Matrix * MatrixRotationX(Matrix *out, float value)
Matrix * MatrixRotationQuaternion(Matrix *out, const Quaternion *q)
Quaternion * QuaternionRotationYawPitchRoll(Quaternion *out, float yaw, float pitch, float roll)
Vector3 * Vec3TransformNormal(Vector3 *out, const Vector3 *a, const Matrix *m)
Matrix * MatrixRotationY(Matrix *out, float value)
Matrix * MatrixInverse(Matrix *out, float *determinant, const Matrix *a)
Matrix * MatrixIdentity(Matrix *out)
bool Begin(double seconds)
int Apply(int health, float severity)
int Apply(int health, float clearanceKm, float closingMps, double seconds)
int ApplyFrameDamage(int health, int hullLoss, double seconds)
float Triangle(const RiseMath::Vector3 &a, const RiseMath::Vector3 &b, const RiseMath::Vector3 &c) const
int landingDamageVehicleId
std::array< float, LandingLights::MaxLights > landingLightBrightness
std::array< LandingLights::Light, LandingLights::MaxLights > landingLights
unsigned landingLightCount
bool rainProtectionEnabled