|
Post by Sa8Gecko on Oct 28, 2004 14:20:46 GMT -5
I'll start with the ones in '/PSY_MCAR_scripts' main subdir and will then proceed with the AT and AA subdir ones, in alphabetical order. It would take me some time, so be patient.
I won't comment here init.sqs: you just need to know it contains the initialization for functions and scripts (what before was in the init eventhandler inside config.cpp). Thanks to Hawk for the idea.
I also won't comment scripts that are present in the various subdir, but are actually not used or related to MP coding, that's still in alpha stage.
Also, excuse if they're not clearly visible on screen, this is mostly due to the forum software, but maybe it's your browser. In any case, don't worry as probably they'll be released in a .DOC or HTML form later.
PSY_MCAR_repair.sqs
; this script is executed at mission start. ; Since when the vehicle gets damaged so that it can no longer move all ; the crew (gamelogics included) are expelled from the vehicle, we got ; to take care of the case the player would re-entry the vehicle to use ; the missile launcher. The AI will never do that, even if ordered to. ; This script is used to make the vehicle still usable by the AI once ; the player has repaired it (the AI won't do that)
_vehicle = vehicle (_this select 0)
; next four lines are executed once every two seconds until the vehicle ; gets damaged so that it can't move #check ? !(canMove _vehicle): goto "check2" ~2 goto "check"
; then the script wait till the vehicle gets repaired: the three lines ; below are there to cover the case the vehicle can move again even if ; before it couldn't (strange, it shouldn't happen, but it happened during ; our tests) #check2 ~2.5 ? canMove _vehicle : goto "check"
; next lines wait until the vehicle can move again: if so, control is ; passed to the #reload section #check3 ? canMove _vehicle : goto "reload"
; but if the vehicle is destroyed, nobody will use it again, so the script exits ? damage _vehicle >= 1: exit ~2 goto "check3"
#reload
; an advise is displayed on screen saying the vehicle is repaired and the ; eventual crew present is ejected from it. This is necessary to populate ; the gamelogics places the right way (the player could be sat on the ; passenger seat and this will spoil it all) hint "vehicle repaired" {_x action ["eject",_vehicle]} forEach crew _vehicle ~.5
; the following line is necessary, otherwise the AI won't re-enter the vehicle ; anyway _vehicle setDamage 0
; these lines call the appropriate 'populating' functions (for the humvees or the Gaskin) ? ((typeOf _vehicle) == "psy_mcar_gaskin"): [_vehicle] call PSY_MCAR_createProxyAA ? ((typeOf _vehicle) == "psy_mcar_hmmwv_tow2a" || (typeOf _vehicle) == "psy_mcar_hmmwv_tow2aReal" || (typeOf _vehicle) == "psy_mcar_hmmwv_tow2b" || (typeOf _vehicle) == "psy_mcar_hmmwv_tow2bReal"): [_vehicle] call PSY_MCAR_createProxyAT
; then the script is started again: maybe the vehicle will get damaged another time. goto "check"
|
|
|
Post by Sa8Gecko on Oct 28, 2004 14:21:09 GMT -5
PSY_MCAR_fired_2.sqs
; this script is used by the 'regular' tow2a and tow2b (not 'real'). ; It manages the missile from the moment it's launched to when a target is ; found, or if the search was unfruitful. In both cases thecontrol is then ; passed to the proper guidance code.
_shooter = _this Select 0 _ammovel = _this Select 1 _vS = vehicle _shooter
; we need the firing direction _velmod = _ammovel call PSY_MCAR_vNorm
; components of the firing direction, for an easy implementation later _ivel= _velmod select 0 _jvel= _velmod select 1 _kvel= _velmod select 2
; as default the missile type to be launched is the tow2b, but otherwise ; it is changed accordingly _misType = "psy_mcar_tow2b" ? (typeOf _shooter == "PSY_MCAR_hmmwv_tow2a"):_misType = "psy_mcar_tow2a"
; this is the missile creation position: to evitate tragedies it should ; be better to set the missile creation position directly in launchmissile.sqf... ; (the tragedy being the script is interrupted in this point by OFP, while ; the humvee was going high speed and the gunner fired forward: next time the ; script is resumed maybe the gunner is in the _MCOP position...) _MCOP = _this select 2
; special effects [_MCOP,_ammovel] call PSY_MCAR_smokerAT
; this function takes care of launching the missile: this is done here ; because the search for a target can take a long time _realmissile = [_shooter,_MCOP,_velmod,_misType] call PSY_MCAR_launchAT
; next comes the targeting routine ; we need absolute height above sea level to make our calculations right _zshooter= - (_shooter call PSY_MCAR_calcH)
; for semplicity, the position of the launcher is stored in separate variables _shootpsx = position (_shooter) select 0 _shootpsy = position (_shooter) select 1
; the search will start 100 meters from the shooter _iter = 100 _change = 0
; this array will contain the targets, if found _Tararray = [] _cpos = 0
; the search will be conducted by steps of 6 meters _step = 6 _dummy = "EmptyDetector" createVehicle [0,0,0]
#loop
; the search position is updated (next 2 lines) _xnextpos = _shootpsx + (_iter * _ivel) _ynextpos = _shootpsy + (_iter * _jvel)
; if the distance from shooter is more than 1300 meters, only air targets will be searched ; by step of 50 meters ? _iter == 1300: _step = 60 ? _iter > 1300: goto "targetAirOnly"
; the target is searched 3 meters above ground because otherwise nearestObject ; would return unuseful information (roads, bushes and so on) _target = nearestObject [_xnextpos,_ynextpos,3] ? (("LandVehicle" countType [_target] > 0 || "Air" countType [_target] > 0) && damage _target < .99): goto "ENDloop"
; search for air target only. In this case the search is conducted at the proper ; z altitude, not 3 meters above ground #targetAirOnly
; next line limits the search for air targets only 1 out of ten times (for the first 1300 meters) ? (((_iter -100)/60) mod ((_iter -100)/60)) != 0: goto "restart" _dummy setpos [_xnextpos,_ynextpos,0] _zrelative = - (_dummy call PSY_MCAR_calcH) _znextpos =(_iter * _kvel) + _zshooter - _zrelative
_target = nearestObject [_xnextpos,_ynextpos,_znextpos] ? (("LandVehicle" countType [_target] > 0 || "Air" countType [_target] > 0) && damage _target < .99): goto "ENDloop1"
; next line should provide in case the missile is falling to the ground ; (being unguided during the search) _realmissile call PSY_MCAR_stayAfloat
; if the missile reaches 60 meters from the shooter, the deadly version substitutes ; the almost dummy one (simulating the fact the warhead is not armed) launched by ; launchmissile.sqf (PSY_MCAR_launchAT) ? (_change == 0 && (_realmissile distance _shooter) > 60):_realmissile = [_realmissile,_misType] call PSY_MCAR_subs; _change = 1
#Restart ; the distance from the shooter at which to make the next search is updated _iter=_iter + _step
; if the search position is less than 1800 meters from the shooter AND ; less than five targets have been found so far, the search continues ? _iter < 1800 && _cpos < 15: goto "loop"
deletevehicle _dummy
; if only a target has been found, there's no need to sort out (go to #fire1), otherwise ; otherwise one among all the found ones must be chosen ? (Count _Tararray == 3):goto "fire1" ? Count _Tararray > 0: goto "sortOut"
; if a target has not been found, we must provide the guidance code ; with a a fake one for it to work #TargetNotFound _target = "EmptyDetector" createvehicle [_xnextpos,_ynextpos,_znextpos] goto "FireMissile"
; this routine really doesn't end the loop: it only interrupts it to store ; the target found in an array #ENDloop ? _cpos == 0: goto "Next"
; this checks if the target is already present in the array (look at search2.sqf for ; a better routine) or if the target is the same side as the shooter's ?(_Target == _Tararray select (_cpos -3)) || (side _Target) == (side _shooter):goto "targetAirOnly"
; if not, the target along with its height above sea level and its distance ; from the shooter are stored in _Tararray, then control is sent back to the ; #Loop routine #Next _Tararray set [_cpos,_target] _Tararray set [_cpos +1,-(_target call PSY_MCAR_calcH)] _Tararray set [_cpos +2,_target distance _shooter] _cpos = _cpos +3 goto "targetAirOnly"
; next routine really doesn't fire the missile. It only passes it ; along with the target to the proper guidance code #FireMissile
; the default guidance code is the one for the tow2b. But if the missile ; is a tow2a or the target flies, guidMis_3 is chosen _stringGuidCode = "\psy_mcar_scripts\at\PSY_MCAR_guidMis_4.sqs" ? _misType == "psy_mcar_tow2a":_stringGuidCode = "\psy_mcar_scripts\at\PSY_MCAR_guidMis_3.sqs" ? "Air" countType [_Target] >0:_stringGuidCode = "\psy_mcar_scripts\at\PSY_MCAR_guidMis_3.sqs" [_target,_realmissile,_shooter,_vS] exec _stringGuidCode exit
; next routine chooses the target among the ones found. ; the targets are examined from the last found one, backward #sortOut _target = _Tararray select _cpos _anglediffold = 90 _loopcounter = _cpos -3
#check _targetc = _Tararray select (_loopcounter) _theight = _Tararray select (_loopcounter +1) _tdist = _Tararray select (_loopcounter+2)
; next two lines calculates the difference between the angle under ; which the shooter would see the target looking horizontally, ; and the elevation of the tow launcher. The less this difference, ; the less the target is 'away' from the firing direction. The ; real target should lie on the firing direction line originating ; from the shooter _angle = asin ((_zshooter - _theight +1)/_tdist) _anglediff = abs(asin(_kvel) + _angle)
; if this difference is less than the previously stored one, then ; the target is set as the one now checked and _anglediffold is ; substituted with _anglediff, so that if the next _anglediff is lower ; than _anglediffold but higher than the current _anglediff, it won't ; trigger the substitution for the target (see #fire2) ? (_anglediff < _anglediffold): goto "fire2" #check2 _loopcounter = _loopcounter -3 ? _loopcounter >= 0: goto "check" goto "FireMissile"
#fire2 _target = _targetc _anglediffold = _anglediff goto "check2"
; next routine (#ENDLoop1) does the same #ENDLoop does, but since it's ; executed from a different part of the script, it must return the ; control to the #Loop routine at the right point (#Restart instead ; of #targetAirOnly) #ENDloop1 ? _cpos == 0: goto "Next" ?(_Target == _Tararray select (_cpos -3)) || (side _Target) == (side _shooter):goto "Restart" #Next _Tararray set [_cpos,_target] _Tararray set [_cpos +1,-(_target call PSY_MCAR_calcH)] _Tararray set [_cpos +2,_target distance _shooter] _cpos = _cpos +3 goto "Restart"
; this i #fire1 _target = _Tararray select 0 goto "FireMissile"
|
|
|
Post by Sa8Gecko on Oct 29, 2004 7:16:55 GMT -5
PSY_MCAR_fired_3.sqs
; This script is actually easier to understand than fired_2.sqs
_shooter = _this Select 0 _ammovel = _this Select 1 _vS = vehicle _shooter
; next lines calculates firing direction _velmod = _ammovel call PSY_MCAR_vNorm _ivel= _velmod select 0 _jvel= _velmod select 1 _kvel= _velmod select 2
; the '...Fake' means that this missile has low hitting power, it's ; used to simulate the facts that the warhead of the tow isn't armed ; immediately after launch _misType = "psy_mcar_tow2aFake" ? typeOf _vS == "psy_mcar_hmmwv_tow2bReal": _misType = "psy_mcar_tow2bFake"
; same as in fired_2.sqs _MCOP = _this select 2 [_MCOP,_ammovel] call PSY_MCAR_smokerAT _realmissile = [_shooter,_MCOP,_velmod,_misType] call PSY_MCAR_launchAT
; time it's used to calculate missile speed in the first 60 meters _misTime = _time
; the components of the velocity the shooting vehicle has _vx = (velocity _shooter select 0) _vy = (velocity _shooter select 1) _vz = (velocity _shooter select 2)
; #loop guides the missile for the first 60 meters, as said above #loop
; the missile decelerates in the first 60 meters (simulating the fact ; the rocket engine is fired up later) _realmissile setvelocity [(70 - (_time -_misTime)*20)*(_velmod select 0) + _vx,(70- (_time -_misTime)*20 )*(_velmod select 1) + _vy,(70 *(_velmod select 2)) + _vz] ~.02 ? !(alive _realmissile): exit ?(_realmissile distance _shooter) <60: goto "loop"
; then, after the first 60 meters, the missile gets substituted with ; the lethal one _misType = "psy_mcar_tow2a" ? typeOf _vS == "psy_mcar_hmmwv_tow2bReal": _misType = "psy_mcar_tow2b"
_realmissile = [_realmissile,_misType] call PSY_MCAR_subs
; next a fake target is positioned 1800 meters from the shooting vehicle, ; along the firing direction _zshooter= - (_shooter call PSY_MCAR_calcH) _shootpsx = position (_shooter) select 0 _shootpsy = position (_shooter) select 1
_dummy = "EmptyDetector" createVehicle [0,0,0]
_xnextpos = _shootpsx + (1800 * (_velmod select 0)) _ynextpos = _shootpsy + (1800 * (_velmod select 1))
_dummy setpos [_xnextpos,_ynextpos,0] _zrelative = - (_dummy call PSY_MCAR_calcH) _znextpos =(1800 * (_velmod select 2)) + _zshooter - _zrelative deletevehicle _dummy
_target = "EmptyDetector" createvehicle [_xnextpos,_ynextpos,_znextpos]
; then the control is passed to the guidance code (there's only one , for the real humvees, as now) #FireMissile _stringGuidCode = "\psy_mcar_scripts\at\PSY_MCAR_guidMis_7.sqs" [_target,_realmissile,_shooter,_vS,_misType] exec _stringGuidCode exit
PSY_MCAR_firedummy.sqs
; this script 'fires' the killing bullet which will (hopefully) ; hit the target and register the kill ; It can't be done by a function (tried unsuccesfully) so it has ; to be a script
_shooter = _this select 0 _weapon = _this select 1
; since the weapon used to score the kill is not the same as the one used ; to fire the missile, it's not in the humvee standard dotation. So we have ; to add it to the humvee. The magazine is already present, though. This ; is doneto evitate the AI or player use this weapon instead of the standard ; one _shooter addWeapon _weapon
; we don't need any target, the bullet is moved at the same moment it's fired ; by the 'fired' EH _shooter fire _weapon
; a little pause is necessary after having fired the weapon ~.02
; another magazine (single shot) is added to the humvee to replace the ; spent one, and the weapon is removed _shooter addMagazine _weapon _shooter removeWeapon _weapon
; then the standard weapon is re-selected, so the player doesn't realize anything ?((typeOf vehicle _shooter) == "psy_mcar_hmmwv_tow2b"): _shooter selectWeapon "psy_mcar_tow2bLauncher" ?((typeOf vehicle _shooter) == "psy_mcar_hmmwv_tow2bReal"): _shooter selectWeapon "psy_mcar_tow2bLauncherReal" ?((typeOf vehicle _shooter) == "psy_mcar_hmmwv_tow2aReal"): _shooter selectWeapon "psy_mcar_tow2aLauncherReal"
exit
|
|
|
Post by Sa8Gecko on Oct 29, 2004 7:22:07 GMT -5
PSY_MCAR_getAmmo_2.sqs
; this script is executed by the fired EH. It passes the firing ; direction to fired2.sqs
_shooter = _this select 0 _ammoType = _this select 1
; MP stuff: cannot say a word about this ? !(local MCAR_server): exit
; if the humvee cannot move, another function is used to retrieve ; gamelogics position and firing direction ? !(canMove _shooter): goto "fireAnyway"
; this retrieve the firing position and direction if the humvee can move _ammo = [_shooter] call PSY_MCAR_getLaunch #continue _ammopos = _ammo select 0 _ammovel = _ammo select 1 ~.003
; the parameters are passed to fired_2.sqs #Exit [_shooter,_ammovel,_ammopos] exec "\psy_mcar_scripts\at\PSY_MCAR_fired_2.sqs" exit
#fireAnyway _ammo = [_shooter] call PSY_MCAR_noCrewInHumvee goto "continue"
PSY_MCAR_getAmmo_3.sqs
; this is the same as getAmmo_2.sqs: the only differences are that ; a pause of 1,5 seconds is added to simulate the fact the real tow ; exits the tube after 1,5 sec since the trigger was pulled for its ; gyro stabilizator system to init, and that control is passed to ; fired_3.sqs (real humvees)
_shooter = _this select 0 _ammoType = _this select 1 ? !(local MCAR_server): exit ~1.5
? !(canMove _shooter): goto "fireAnyway"
_ammo = [_shooter] call PSY_MCAR_getLaunch #continue _ammopos = _ammo select 0 _ammovel = _ammo select 1 ~.003
#Exit [_shooter,_ammovel,_ammopos] exec "\psy_mcar_scripts\at\PSY_MCAR_fired_3.sqs" exit
#fireAnyway _ammo = [_shooter] call PSY_MCAR_noCrewInHumvee goto "continue"
PSY_MCAR_guidMis_3.sqs
; lead-pursuit guidance code ; by Sa8Gecko _Target = _this Select 0 _Missile = _this Select 1 _shooter = _this select 2 _vehShooter = _this select 3
; this variable is used in case the target is sitted on top of a building _heightT = 0
; this is used not to show the additional missile trail, if the player ; is firing the missile, because otherwise he wouldn't see much _aiFiring = false ?((gunner _shooter) != player): _aiFiring = true
; this is used to generate the fake target in case none has been found previously _distancemax = 1700 _loops = 0
;initial missile speed _speed = 50
; time variables needed to calculate speed and max turning angle _misTime = _time _misT2 = _time _cond = 0
; main routine #Loop _dist = _Missile distance _Target
; _alt sets the height above the target at which to aim (higher for planes) _alt = 1.0 ? "Air" countType [_Target] >0 && _dist > 15: _alt = 6
; heights above sea level (of the ground on which the missile and the ; target are) _zmiss = - ( _Missile call PSY_MCAR_calcH ) _ztarg = - ( _Target call PSY_MCAR_calcH ) ? typeOf (_Target) != "EmptyDetector": _heightT = _Target call PSY_MCAR_hShooter
; difference in height between missile and target _DZ = - _zmiss + _ztarg + _alt - (position (_Missile) select 2) +(position (_Target) select 2) + _heightT
; direction of the velocity of the missile _vnorm = velocity _Missile call PSY_MCAR_vNorm
; speed is set using a prefixed and realistic speed curve _speed = _misTime call PSY_MCAR_towSpeed
_dirmis = direction _Missile
; the aiming position is shifted lightly in front of the missile _targetposx=(position _Target select 0)+((velocity (_Target) select 0)*.15) _targetposy=(position _Target select 1)+((velocity (_Target) select 1)*.15)
; angle to the aiming position as respect to the missile position ( zero = North, OFP cohords) _newdir = (_targetposx - (position _Missile select 0)) atan2 (_targetposy - (position _Missile select 1)) ? _newdir< 0: _newdir = _newdir +360
; these two lines make _newdir and _dirmis consistent with each other, ; to evitate the case _newdir is little lower than zero and _dirmis a little ; more and their difference would give an angle between the two more than 180 degrees ? abs(_newdir - _dirmis) > 180 && _newdir < _dirmis: _newdir = _newdir + 360 ? abs(_newdir - _dirmis) > 180 && _newdir > _dirmis: _dirmis = _dirmis + 360
; if missile direction is more than 90 degrees off the one it should have to hit ; the target, the missile is considered to have lost lock on target ? abs(_newdir - _dirmis) > 90: goto "Lost1"
; in case the turning angle exceed the max admitted value (30 deg/sec) it is ; set to the appropriate value ? abs (_newdir - _dirmis) > (30 * (_time - _misT2)): _newdir = _dirmis + (((_newdir - _dirmis)/abs(_newdir- _dirmis))*(30 * (_time - _misT2)))
; this variable is update for the next time it's required _misT2 = _time
; angle to steer the missile _ax = _dirmis - _newdir
; new direction the missile should have to hit the target _Missile setdir (direction _missile -_ax)
; vertical speed is set _vz = _DZ/(_dist/_speed)
; next line calculates the percentage of _speed available to the x,y components ; of the velocity vector _vxypercent = (1- (_vnorm select 2))
; x,y components of the velocity vector _vX = (_speed * _vxypercent) * ((_vnorm select 0) * cos (_ax) + (_vnorm select 1) * sin (_ax)) _vY = (_speed * _vxypercent) * (- (_vnorm select 0) * sin (_ax) + (_vnorm select 1) * cos (_ax))
; the missile is given its velocity vector _Missile setvelocity [_vX,_vY,_vz] ?(_aiFiring): _missile call PSY_MCAR_trail
; next line is used to substitute the missile if it reaches a certain ; lifetime in seconds (in fact the tow can travel till 3600 meters, but ; since it takes about 20 sec to reach that distance, it would be destroyed ; automatically by OFP engine just after about 10 seconds _info = [_missile,_misTime,_cond,"psy_mcar_tow2a"] call PSY_MCAR_xchange _missile = _info select 0 _cond = _info select 1
~.01
; next line check if it's the case to launch a search for a target, if ; the missile is less than _distancemax distant from the fake ('emptydetector') ; target ? (_missile distance _Target < _distancemax) && (typeOf _target == "EmptyDetector"): goto "Search"
; if the missile is dead the script exits ? alive _Missile: goto "Loop" exit #Lost1 exit
; search routine #Search ; the target is deleted if it was the 'emptydetector' deletevehicle _Target
#SearchAnother _alt = 1 _loops = _loops +1
; the search routine is executed max 17 times or until the missile ; has reached 3600 meters from the shooter ? _loops > 17 || (_missile distance _shooter > 3600): goto "Lost1"
_ivel = _vnorm select 0 _jvel = _vnorm select 1
; the target is searched by a function along the missile current direction _target = [_ivel,_jvel, position _Missile,_shooter] call PSY_MCAR_search ?(_aiFiring): _missile call PSY_MCAR_trail
; if the returned target is equal to the shooter then it means no target has ; been found ? _target != _shooter: goto "ENDloop"
; if the unit is damaged beyond a certain level or destroyed, where to place ; the next fake target is decided by the velocity vector of the missile instead ; of the orientation of the launch tube (the crossair) ? (damage _vehShooter) >.95 || !(alive _shooter): goto "setNTP"
; if the unit can or cannot move, _newTargetPos must be calculated differently ? (canMove _shooter):_newTargetPos = ([_shooter] call PSY_MCAR_getLaunch) select 1 ? !(canMove _shooter):_newtargetPos = ([_shooter] call PSY_MCAR_noCrewInHumvee) select 1 _nTPXY =_newTargetPos call PSY_MCAR_vNorm
; this part of the routine places the fake target 300 meters from missile current ; position, in a direction that's set by the aim if the unit is still alive, ; by missile velocity if not #continue _zshooter= - (_shooter call PSY_MCAR_calcH) _dummy = "EmptyDetector" createVehicle [0,0,0] _misDistShoot = _missile distance _shooter _dummy setpos [(position _shooter select 0)+(_misDistShoot+300)*(_nTPXY select 0),(position _shooter select 1)+(_misDistShoot +300)*(_nTPXY select 1),0] _zrelative = - (_dummy call PSY_MCAR_calcH) _znextpos =((_misDistShoot +300) * (_nTPXY select 2)) + _zshooter - _zrelative
_Target = "EmptyDetector" createvehicle [(position _shooter select 0)+(_misDistShoot+300)*(_nTPXY select 0),(position _shooter select 1)+(_misDistShoot +300)*(_nTPXY select 1),_znextpos + 1]
; _distancemax is set to 100m: it means that when the missile will be less than 100 m ; from the fake target, the search will be executed again _distancemax = 100 deletevehicle _dummy goto "Loop"
; this is executed in case a proper target has been found #ENDloop
; the shooting vehicle crew is informed what type of target has been acquired ; (useful for human crew only) _shooter vehiclechat format ["%1",typeOf _Target] _dir = ((position _Target select 0) - (position _Missile select 0)) atan2 ((position _Target select 1) - (position _Missile select 1)) goto "Loop"
#outOfRange deletevehicle _Target goto "Lost1"
; this sets the direction along which to place the fake target if the unit is dead #setNTP _nTPXY = velocity _missile call PSY_MCAR_vNorm goto "continue"
|
|
|
Post by Sa8Gecko on Oct 30, 2004 6:50:08 GMT -5
PSY_MCAR_guidMis_4.sqs
; this is the tow2b (standard) terrain following guidance code. ; For missing explanations of variables and pieces of code refer ; to guidmis_3.sqs
_Target = _this Select 0 _Missile = _this Select 1 _shooter = _this select 2 _vehShooter = _this select 3
_aiFiring = false ?((gunner _shooter) != player): _aiFiring = true
; this object below is used to calculate the slope of the ground ; in front of the missile (climbing-descending-horizontal) _Tracker = "EmptyDetector" createvehicle [0, 0, 0]
_speed = 50
; the missile flies 15meters above the ground _alt = 15 _loops = 0 _more = 0 _misTime = _time _misT2 = _time _cond = 0;
_distancemax = 1700 ? typeof _target == "EmptyDetector": goto "CalculateTrajectory2"
; this piece of code is used if the target has been acquired #CalculateTrajectory
_altmis = - (_Missile call PSY_MCAR_calcH)
_velnormis = velocity _Missile call PSY_MCAR_vNorm
; the object used to calculate the slope is placed 12 meters in front of the missile _Tracker setpos [(position _Missile select 0) + 12*(_velnormis select 0),(position _Missile select 1) + 12*(_velnormis select 1), 0] _nexth = - (_Tracker call PSY_MCAR_calcH)
; if thex,y distance of the missile from the target is less than 10 meters ; the missile 'detonates' ? ([_Missile,_Target] call PSY_MCAR_distXY < 10): goto "Explos"
; difference between missile current position and the one 12 meters in front of it _zdiff = _alt - (position _Missile select 2) + _nexth - _altmis
; the angle of steering is calculated by this function _angle = [_Missile,_Target] call PSY_MCAR_dir ? (_angle select 1)==1:goto "Lost1"
_vxypercent = (1- (_velnormis select 2)) _velx = (_speed * _vxypercent) * ((_velnormis select 0) * cos (_angle select 0) + (_velnormis select 1) * sin (_angle select 0)) _vely = (_speed * _vxypercent) * (- (_velnormis select 0) * sin (_angle select 0) + (_velnormis select 1) * cos (_angle select 0)) ; the z component of the velocity vector is set this way because 12 is the distance ; in meters in front of the missile at which is taken _nexth _velz = _zdiff * _speed / 12
; if _velz is higher than a certain value, it's set back tothe proper one. ; This is useful when the missile is launched so it doesn't climb to cruise ; height almost istantaneously ? abs(_velz) > (_speed*((_speed-40)/160)) && _speed < 150: _velz = (_speed*((_speed-40)/160))* ((abs(_velz))/_velz)
_missile setvelocity[_velx,_vely,_velz] ? !(alive _missile) :goto "lost"
; setting missile direction in a different way ... _missile setdir (_velx atan2 _vely)
; the speed of the missile is not realistic, but it's calculated with this ; formula. Anyway acceleration should be equal on all systems cause it's ; regulated by time _speed = 50 + (60* (_time - _misTime)) ? _speed > 200: _speed = 200
_info = [_missile,_misTime,_cond,"psy_mcar_tow2b"] call PSY_MCAR_xchange _missile = _info select 0 _cond = _info select 1
~0.01 ? !(alive _Target): goto "SearchAnother" Goto "CalculateTrajectory"
#Lost
deletevehicle _Tracker exit
; this piece of code is almost equal to the one above,but it's used ; if no target has been found #CalculateTrajectory2
_MissilePos = position _Missile
_altmis = - (_Missile call PSY_MCAR_calcH)
_velnormis = velocity _Missile call PSY_MCAR_vNorm
_Tracker setpos [(_Missilepos select 0) + 12*(_velnormis select 0),(_Missilepos select 1) + 12*(_velnormis select 1), 0] _nexth = - (_Tracker call PSY_MCAR_calcH)
_zdiff = _alt - (_Missilepos select 2) + _nexth - _altmis
_angle = [_Missile,_Target] call PSY_MCAR_dir ? (_angle select 1)==1:goto "Lost1"
_vxypercent = (1- (_velnormis select 2)) _velx = (_speed * _vxypercent) * ((_velnormis select 0) * cos (_angle select 0) + (_velnormis select 1) * sin (_angle select 0)) _vely = (_speed * _vxypercent) * (- (_velnormis select 0) * sin (_angle select 0) + (_velnormis select 1) * cos (_angle select 0)) _velz = _zdiff * _speed / 12
? abs(_velz) > (_speed*((_speed-40)/160)) && _speed < 150: _velz = (_speed*((_speed-40)/160))* ((abs(_velz))/_velz)
_missile setvelocity[_velx,_vely,_velz] ? !(alive _missile) :goto "lost2" _missile setdir (_velx atan2 _vely) ?(_aiFiring): _missile call PSY_MCAR_trail
_speed = 50 + (60* (_time - _misTime)) ? _speed > 200: _speed = 200 _info = [_missile,_misTime,_cond,"psy_mcar_tow2b"] call PSY_MCAR_xchange _missile = _info select 0 _cond = _info select 1
~0.01
; if the missile is less than _distancemax meters from the fake target, ; a new search is conducted ? (_missile distance _Target) < _distancemax : goto "Search" Goto "CalculateTrajectory2"
deletevehicle _Target deletevehicle _Tracker exit
; this search routine is similar to the one in guidMis_3.sqs, so refer to it ; for most of the explanations #Search
; _more is added to the distance at which the fake target is placed ? (_missile distance _Target) < 251: _more = _more + 250 deletevehicle _Target
#SearchAnother _alt = 15 _loops = _loops +1
? _loops > 11: goto "Lost" _ivel = _velnormis select 0 _jvel = _velnormis select 1 _target = [_ivel,_jvel, position _Missile,_shooter] call PSY_MCAR_search ?(_aiFiring): _missile call PSY_MCAR_trail
? _target != _shooter: goto "ENDloop" ? (damage _vehShooter) >.95 || !(alive _shooter): goto "setNTP"
? (canMove _shooter):_newTargetPos = ([_shooter] call PSY_MCAR_getLaunch) select 1 ? !(canMove _shooter):_newtargetPos = ([_shooter] call PSY_MCAR_noCrewInHumvee) select 1 _nTPXY =[_newTargetPos select 0,_newTargetPos select 1,0] call PSY_MCAR_vNorm #continue
; the target is placed in a (very) little different way than guidMis_3.sqs, ; here it's not calculate the distance between missile and target, but a standard (1200) ; one is used _Target = "EmptyDetector" createvehicle [(position _shooter select 0)+(1200+_more)*(_nTPXY select 0),(position _shooter select 1)+(1200+_more)*(_nTPXY select 1),2] _distancemax = (_missile distance _Target) - 250
; this should never happen anyway ? _distancemax < 0: goto "outOfRange" goto "CalculateTrajectory2"
#ENDloop _shooter vehiclechat format ["%1",_Target] _dir = ((position _Target select 0) - (position _Missile select 0)) atan2 ((position _Target select 1) - (position _Missile select 1)) goto "CalculateTrajectory"
; if the missile gets lost then _Tracker is deleted #Lost1 deletevehicle _Tracker exit
#lost2 deletevehicle _Target deletevehicle _Tracker exit
; here the missile is exploded calling slug.sqf, simulating the ; warhead projecting the jet below #Explos deletevehicle _Tracker
[_Missile,_Target] call PSY_MCAR_slug exit
#outOfRange deletevehicle _Target goto "Lost"
#setNTP _nTPXY = velocity _missile call PSY_MCAR_vNorm goto "continue"
|
|
|
Post by Sa8Gecko on Oct 30, 2004 6:51:34 GMT -5
PSY_MCAR_guidMis_7.sqs
; This scripts guides the real tow2a and tow2b.
_Target = _this Select 0 _Missile = _this Select 1 _shooter = _this select 2 _vehShooter = _this select 3 _misType = _this select 4
; this is used to fire the killing bullet once _chkslug = 0
; this is used to activate the substitution of the missile with the killing ; bullet (and to know it's been done) _reveal = 0 _heightT = 0
; 'old' values to be passed to the functions _nTPXYold = velocity _missile call PSY_MCAR_vNorm _vzOld = velocity _missile select 2 _meters = [_missile distance _shooter,position _missile]
_aiFiring = false ?((gunner _shooter) != player): _aiFiring = true
; this is used to start the search the first time the main loop is executed _start = 0
; this will evitate a 'zero divisor' error _misTime = _time - 0.001 _mis2Time = _time _angle = [0,_time]
; this is used to substitute the missile for a longer life _cond = 0 _searchTime = _misTime _timetext = _time
; as in the other scripts, _alt is the height above target at which to aim (since ; target z position is many times returned as about 0, this is even necessary not ; to make the missile impact ground prematurely) _alt = 0.5
; the various '_invweapon...' are the killing bullet 'providers' _weapon = "psy_mcar_invWeapon2"
; _alt is set to 5 meters for the tow2b ? typeOf _vehShooter == "psy_mcar_hmmwv_tow2bReal": _alt = 5; _weapon = "psy_mcar_invWeapon"
; main loop #Loop
; next line fires the killing bullet if the target is less than 50 meters from the missile ? (([_missile,_target] call PSY_MCAR_distXY) < 50) && (_chkslug == 0) && (typeOf _Target != "EmptyDetector"): _chkslug = 1; [_shooter,_weapon] exec "\psy_mcar_scripts\at\PSY_MCAR_firedummy.sqs"
; next two lines put to good use the killing bullet (tow2b and tow2a respectively) ? (typeOf _missile == "psy_mcar_tow2b") && (([_missile,_target] call PSY_MCAR_distXY) < 8) && (typeOf _Target != "EmptyDetector"): _reveal = 1; [_missile,_target] call PSY_MCAR_slug; goto "Lost1" ? (typeOf _missile == "psy_mcar_tow2a") && ((_missile distance _target ) < 15) && (typeOf _Target != "EmptyDetector") && (_reveal ==0): _reveal = 1; _missile = call PSY_MCAR_jet
; next lines calculate the difference between the height of the target and the ; height of the missile _dist = _Missile distance _Target _zmiss = - ( _Missile call PSY_MCAR_calcH ) _ztarg = - ( _Target call PSY_MCAR_calcH ) ? typeOf (_Target) != "EmptyDetector": _heightT = _Target call PSY_MCAR_hShooter _DZ = - _zmiss + _ztarg + _alt- (position (_Missile) select 2) +(position (_Target) select 2) + _heightT
_vnorm = velocity _Missile call PSY_MCAR_vNorm
; missile speed is set by a function approximating a realistic speed vs distance ; curve _speed = _misTime call PSY_MCAR_towSpeed
; the angle of steering is calculated via function _angle = [_Missile,_Target,_angle select 1] call PSY_MCAR_targetPos
; maybe the missile overshot its target, and so another one is searched ? ((_missile distance _shooter) > (_target distance _shooter) + 20) : _shooter vehicleChat "Target Lost"; goto "SearchAnother"
; same as above if the target gets destroyed ? (damage _target > .99 && typeOf _Target != "EmptyDetector"): goto "SearchAnother"
; setting missile direction _Missile setdir (direction _missile +(_angle select 0))
; calculating missile velocity vector. The z component cannot accelerate more than 10m/s^2 _vz = _DZ/(_dist/_speed) ? (abs(_vz - _vzOld)> 10/(_time - _mis2Time)): _vz = _vzOld + 10/(_time - _mis2Time)*((abs(_vz - _vzOld))/(_vz - _vzOld)) _mis2Time = _time ; percentage of _speed to be devoted to the x,y components of the vel. vector _vxypercent = (1- (_vnorm select 2)) _vX = (_speed * _vxypercent) * ((_vnorm select 0) * cos (_angle select 0) + (_vnorm select 1) * sin (_angle select 0)) _vY = (_speed * _vxypercent) * (- (_vnorm select 0) * sin (_angle select 0) + (_vnorm select 1) * cos (_angle select 0))
_Missile setvelocity [_vX,_vY,_vz] _vzOld = _vz ?(_aiFiring): _missile call PSY_MCAR_trail2
; next function checks if the missile must be substituted _info = [_missile,_misTime,_cond,_misType] call PSY_MCAR_xchange _missile = _info select 0 _cond = _info select 1
; next two lines show the distance travelled by the missile and the time elapsed ; since it exited the tube, in case the gunner is the player _meters = [_meters,_missile] call PSY_MCAR_meters ? gunner _shooter == player && (_time - _timeText) > .2: titleText[ format ["meters: %1, time %2",_meters select 0,_time - _misTime],"PLAIN DoWN",0.2]; _timeText = _time ~.01
; every fifth of a second the search routine is executed ? ((_time - _searchTime) > 0.20 || _start == 0) && (typeOf _target == "EmptyDetector"): goto "Search"
; the max distance the missile can travel is 3600 meters ? (!(alive _missile) || (_meters select 0) > 3600): goto "Lost1" goto "Loop"
#Lost1 ~.2 #deleteTarget ? typeOf _target == "EmptyDetector": deleteVehicle _target exit
; search routine: this is analogue to the other search routines in the other ; scripts, so I remand to these ones for an explanation #Search deletevehicle _Target #SearchAnother _searchTime = _time _start = 1
? (_meters select 0) > 3600 || !(alive _missile): goto "Lost1" ? (damage _vehShooter) >.95 || !(alive _shooter): goto "setNTP"
_targetAndPos = [_Missile,_shooter] call PSY_MCAR_search2 _target = _targetAndPos select 0 _nTPXY = _targetAndPos select 1
?(_aiFiring): _missile call PSY_MCAR_trail2
? _target != _shooter: goto "ENDloop"
; this variable is use to make the missile steer tighter if the aim point ; was moved, so the missile will return faster to crossair centre _displ = [_nTPXYold,_nTPXY,_missile] call PSY_MCAR_deflection _nTPXYold = _nTPXY #continue _zshooter= - (_shooter call PSY_MCAR_calcH) _dummy = "EmptyDetector" createVehicle [0,0,0] _misDistShoot = _missile distance _shooter _dummy setpos [(position _shooter select 0)+(_misDistShoot+_displ)*(_nTPXY select 0),(position _shooter select 1)+(_misDistShoot +_displ)*(_nTPXY select 1),0] _zrelative = - (_dummy call PSY_MCAR_calcH) _znextpos =((_misDistShoot +_displ) * (_nTPXY select 2)) + _zshooter - _zrelative
_Target = "EmptyDetector" createvehicle [(position _shooter select 0)+(_misDistShoot+_displ)*(_nTPXY select 0),(position _shooter select 1)+(_misDistShoot +_displ)*(_nTPXY select 1),_znextpos + 1.2]
deletevehicle _dummy goto "Loop"
#ENDloop _shooter vehiclechat format ["%1",typeOf _Target] _alt = 1 ? typeOF _missile == "psy_mcar_tow2b": _alt = 5 goto "Loop"
#setNTP _nTPXY = velocity _missile call PSY_MCAR_vNorm goto "continue"
PSY_MCAR_mags.sqs
; this script takes care of re-filling (!) the tube with textures after the ; a certain amount of time, depending from versions, has passed since the ; missile has been fired ; This has nothing to do with MCAR, but it's an eye candy feature
_shooter = (_this select 0) _VS = vehicle _shooter
; the following is the script initialization. Each relevant unit info is stored ; in variables so that the script can be used for all humvee variants ? (typeOf _VS == "psy_mcar_hmmwv_tow2a") || (typeOf _VS == "psy_mcar_hmmwv_tow2b"): _ammo1 = "psy_mcar_tow2aLauncher" ;_ammo2 = "psy_mcar_tow2bLauncher"; _wait =8 ? (typeOf _VS == "psy_mcar_hmmwv_tow2aReal") || (typeOf _VS == "psy_mcar_hmmwv_tow2bReal"): _ammo1 = "psy_mcar_tow2aLauncherReal" ;_ammo2 = "psy_mcar_tow2bLauncherReal"; _wait =27
; this variable will be used subsequently if the mission gets re-loaded ; after having been saved _timecheck = 0
; start of the main routine: this is always in execution, at least until ; the unit is not destroyed #start
; counting ammo left _prevAmmo1 = _shooter ammo _ammo1 _prevAmmo2 = _shooter ammo _ammo2
; zero ammo left or the humvee started with zero ammo ? Then no need to ; refill the tube ? (_shooter ammo _ammo1 == 0) && (_shooter ammo _ammo2 == 0): goto "check"
; filling the tube _VS setObjectTexture [0,"\psy_mcar_hmmwv\mishead.paa"] _VS setObjectTexture [1,"\psy_mcar_hmmwv\misback.paa"]
; this part of the script is executed every two seconds if nothing ; happens (that is: no ammo is expended or the unit reload at an ; ammo truck) #check
; savegame and reload check line: 'time' is the time since mission ; started and it's reset when a mission is reloaded; '_time' is the ; time since the script started and it's never reset; _timecheck is ; set this way in case the user uses the savegame cheat (multiple ; saving) ? time < _time + _timecheck : _timecheck = time - _time; goto "start"
; pause of two seconds to evitate to overload the CPU ~ 2
; if the unit is destroyed the script exits ? !(alive _shooter) || !(alive _VS):exit
; various cases: the ammo left is zero, the trigger was pulled during the ; two secs pause and so the ammo is less than before, the unit has reloaded ; at an ammo truck and so the ammo is more than before ? (_shooter ammo _ammo1 == 0) && (_shooter ammo _ammo2 == 0): goto "check" ? (_shooter ammo _ammo1 < _prevAmmo1) || (_shooter ammo _ammo2 < _prevAmmo2): goto "wait" ? (_shooter ammo _ammo1 > _prevAmmo1) || (_shooter ammo _ammo2 > _prevAmmo2): goto "start" goto "check"
; this waits the set amount of seconds before refilling the tube #wait ~ _wait goto "start"
|
|