Crash and stress damage system: Difference between revisions

Jump to navigation Jump to search
m
Line 20: Line 20:
#
#
#
#
# Version 0.11
# Version 0.12
#
#
# License:
# License:
Line 51: Line 51:
m.wingLoadLimitLower = nil;
m.wingLoadLimitLower = nil;
m._looptimer = maketimer(0, m, m._loop);
m._looptimer = maketimer(0, m, m._loop);
m.repairTimer = maketimer(10.0, m, CrashAndStress._finishRepair);
m.repairTimer.singleShot = 1;
m.soundWaterTimer = maketimer(3, m, CrashAndStress._impactSoundWaterEnd);
m.soundWaterTimer.singleShot = 1;
m.soundTimer = maketimer(3, m, CrashAndStress._impactSoundEnd);
m.soundTimer.singleShot = 1;
m.explodeTimer = maketimer(3, m, CrashAndStress._explodeEnd);
m.explodeTimer.singleShot = 1;
m.stressTimer = maketimer(3, m, CrashAndStress._stressDamageEnd);
m.stressTimer.singleShot = 1;


m.input = {
m.input = {
Line 113: Line 128:
isStarted: func () {
isStarted: func () {
return me.inService;
return me.inService;
},
# repair the aircaft
repair: func () {
var failure_modes = FailureMgr._failmgr.failure_modes;
var mode_list = keys(failure_modes);
foreach(var failure_mode_id; mode_list) {
FailureMgr.set_failure_level(failure_mode_id, 0);
}
me.wingsAttached = TRUE;
me.exploded = FALSE;
me.lastMessageTime = 0;
me.repairing = TRUE;
var timer = maketimer(10, me, me._finishRepair);
timer.start();
},
},
# accepts a vector with failure mode IDs, they will fail when wings break off.
# accepts a vector with failure mode IDs, they will fail when wings break off.
Line 192: Line 192:
me._looptimer.stop();
me._looptimer.stop();
}
}
},
# repair the aircaft
repair: func () {
var failure_modes = FailureMgr._failmgr.failure_modes;
var mode_list = keys(failure_modes);
foreach(var failure_mode_id; mode_list) {
FailureMgr.set_failure_level(failure_mode_id, 0);
}
me.wingsAttached = TRUE;
me.exploded = FALSE;
me.lastMessageTime = 0;
me.repairing = TRUE;
me.repairTimer.restart(10.0);
},
_finishRepair: func () {
me.repairing = FALSE;
},
},
_identifyGears: func (gears) {
_identifyGears: func (gears) {
Line 207: Line 225:
}
}
},
},
_finishRepair: func () {
me.repairing = FALSE;
},
_isStructureInContact: func () {
_isStructureInContact: func () {
foreach(var structure; me.wowStructure) {
foreach(var structure; me.wowStructure) {
Line 261: Line 276:
var lon = me.input.lon.getValue();
var lon = me.input.lon.getValue();
var info = geodinfo(lat, lon);
var info = geodinfo(lat, lon);
var solid = info[1] == nil?TRUE:info[1].solid;
var solid = info == nil?TRUE:(info[1] == nil?TRUE:info[1].solid);
var speed = me._calcGroundSpeed();
var speed = me._calcGroundSpeed();


Line 288: Line 303:
}
}
if(solid == TRUE) {
if(solid == TRUE) {
#print("solid");
me._impactSoundBegin(speed);
me._impactSoundBegin(speed);
} else {
} else {
#print("water");
me._impactSoundWaterBegin(speed);
me._impactSoundWaterBegin(speed);
}
}
Line 298: Line 311:
if (speed > 5) {#check if sound already running?
if (speed > 5) {#check if sound already running?
me.input.wCrashOn.setValue(1);
me.input.wCrashOn.setValue(1);
var timer = maketimer(3, me, me._impactSoundWaterEnd);
me.soundWaterTimer.restart(3);
timer.start();
}
}
},
},
Line 308: Line 320:
if (speed > 5) {
if (speed > 5) {
me.input.crashOn.setValue(1);
me.input.crashOn.setValue(1);
var timer = maketimer(3, me, me._impactSoundEnd);
me.soundTimer.restart(3);
timer.start();
}
}
},
},
Line 326: Line 337:


    me._output("Aircraft exploded.", TRUE);
    me._output("Aircraft exploded.", TRUE);
 
var timer = maketimer(3, me, me._explodeEnd);
me.explodeTimer.restart(3);
timer.start();
},
},
_explodeEnd: func () {
_explodeEnd: func () {
Line 340: Line 350:


me.wingsAttached = FALSE;
me.wingsAttached = FALSE;
var timer = maketimer(3, me, me._stressDamageEnd);
 
timer.start();
me.stressTimer.restart(3);
},
},
_stressDamageEnd: func () {
_stressDamageEnd: func () {
Line 375: Line 385:
var wingload = gForce * weight;
var wingload = gForce * weight;


#print("wingload: "~wingload~" max: "~me.wingLoadLimitUpper);
var broken = FALSE;
var broken = FALSE;


Line 523: Line 532:


# use:
# use:
var crashCode = CrashAndStress.new([0,1,2], {"weightLbs":30000, "maxG": 12}, ["controls/gear1", "controls/gear2", "controls/flight/aileron", "controls/flight/elevator", "consumables/fuel/wing-tanks"]);
var crashCode = CrashAndStress.new([0,1,2], {"weightLbs":30000, "maxG": 12}, ["controls/flight/aileron", "controls/flight/elevator"]);
crashCode.start();
crashCode.start();


574

edits

Navigation menu