Home   Help Search Login Register  

Author Topic: Problem with this calculation. Please help.  (Read 1284 times)

0 Members and 1 Guest are viewing this topic.

klavan

  • Guest
Problem with this calculation. Please help.
« on: 27 Jan 2005, 13:10:37 »
Here is it:

Code: [Select]
;The amount of time in seconds the Torpedo need to cover the distance between itself and the target
;I've decided to set the speed of the Torpedo at 30 knots (about 72 km/h if I'm not wrong, so 20 mt/s)
~2
_speedtorp = 20
;This is the speed in mt/s of the sub. 0.27 is the result of 1000 / 3600 (1 km/h and the amount of seconds in a hour)
_speedsub = speed sub * 0.27
_timeleft = (_torp distance sub) / (_speedtorp - _speedsub); hint format ["Time remaining %1", _timeleft]

;Torpedo is deleted before hitting the ground
@(getpos _torp select 2) <= 2
deletevehicle _torp

;If the speed of the target is higher than the Torpedo's one, It will never reach It's target
? _speedsub >= _speedtorp : ap sidechat "Target speed too high. Engagement lost."; exit

The result of the hint is something like this: "Time ramaining X,XXXXXe.XXXX"
X: are numbers
e: is not a typo
In addiction the script stops it's run, as the torpedo (a LGB bomb) is not deleted as I can hear the sound of explosion.
I've tried this calculation with a calculator and all seem OK....
Thanks.
« Last Edit: 27 Jan 2005, 13:11:21 by klavan »

Offline ACF

  • Members
  • *
  • Llama?? Ain't that French for tanks?
Re:Problem with this calculation. Please help.
« Reply #1 on: 27 Jan 2005, 13:32:28 »
Hint _speedtorp and _speedsub as well - my guess is they're almost identical values, the speed diffential is small so time left becomes very large.

But it's a guess . . .

Also, the calculation is using linear speed, not vector velocity, so it's going to be almost meaningless if the torpedo isn't trailing the target: _speedsub > _speedtorp isn't a problem if the sub is steaming towards the torpedo.


Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Problem with this calculation. Please help.
« Reply #2 on: 27 Jan 2005, 13:54:56 »
I was just about to say that:
Quote
_speedtorp - _speedsub
looks like it might be close to zero and then I saw ACF's post.  In otherwords I agree with him.

Bye the way:
Quote
XeY
Is a form of number notation.  What it means is:
X * 10^Y

So if Y is positive you have a large number, if it is negative you have a small number.

So the calculation seems to be returning a very large value.  Consistent with the above theory that
 _speedtorp - _speedsub is close to zero

You might wish to check to see if _torp and sub are correctly defined and exist at this point in the script.

I also agree with ACF that the distance you are measuring is not necessarily  related to the  direction either of the objects are travelleing in.  You need to do a bit of vector algebra for this one I am afraid.
« Last Edit: 27 Jan 2005, 14:09:28 by THobson »

klavan

  • Guest
Re:Problem with this calculation. Please help.
« Reply #3 on: 27 Jan 2005, 18:42:32 »
It's strange, because the sub (an existing PBR) doesn't move.....
So if _torpspeed = 20 and _speedsub = 0 and the distance between the objects is, let's say, 1000 meters the result should be 1000 / 20 = 50 seconds....
However my knowledge about math and related is very close to 0...
Conlclusion: probably I'm quite stupid... :)

For the rest: I'm not interested if the sub direction lead directly toward the torpedo. If I'm not wrong a torpedo is immediately detected by the sub when it enters the water, so the sub begin immediately evasive maneuvers.
This calculation serves me mainly to determine the amount of decoys the sub will launch ,attempting a disengagement, during this amount of seconds.
Neither the position of this line is definitive in the script structure.
« Last Edit: 27 Jan 2005, 19:14:59 by klavan »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Problem with this calculation. Please help.
« Reply #4 on: 27 Jan 2005, 19:43:32 »
Quote
_torpspeed = 20 and _speedsub = 0
In which case I suspect that some of the variables have not been defined.  Have you done a:
hint format["%1,%2",_torpspeed ,_speedsub]
?
« Last Edit: 27 Jan 2005, 19:43:43 by THobson »

klavan

  • Guest
Re:Problem with this calculation. Please help.
« Reply #5 on: 27 Jan 2005, 20:06:43 »
Done.
The result is 20,0.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Problem with this calculation. Please help.
« Reply #6 on: 27 Jan 2005, 22:05:45 »
And what is:

hint format["%1",_torp distance sub]
?

And does it all improve if you have:
Code: [Select]
_timeleft = (_torp distance sub) / (_speedtorp - _speedsub)
hint format ["Time remaining %1", _timeleft]
« Last Edit: 27 Jan 2005, 22:07:40 by THobson »

klavan

  • Guest
Re:Problem with this calculation. Please help.
« Reply #7 on: 28 Jan 2005, 12:45:06 »
Nothing!
The result is 5e+008

I've tried this solution too:

Code: [Select]
~2
_speedtorp = 20
_speedsub = speed sub / 3.6
_dist = (_torp distance sub)
_timeleft = _dist / (_speedtorp - _speedsub)
hint format ["%1", _timeleft]

And the result is similar....
I wonder if the distance command is the right one for these lines. Maybe another type of calculation is required....
But It would be very strange..... ???

Code: [Select]
_speedsub = speed sub / 3.6
I've changed this line after I found the right value for this type of calculation in an old math book.
« Last Edit: 28 Jan 2005, 12:47:09 by klavan »

Offline ACF

  • Members
  • *
  • Llama?? Ain't that French for tanks?
Re:Problem with this calculation. Please help.
« Reply #8 on: 28 Jan 2005, 13:00:05 »
It looks like your torpedo isn't callled _torp or your submarine isn't called sub.  Or both.  My guess is _torp is wrong as it's a local variable from the script.

Any luck?


klavan

  • Guest
Re:Problem with this calculation. Please help.
« Reply #9 on: 28 Jan 2005, 13:14:09 »
EDIT: this is the complete script.
Sorry for the amount of ";" lines

Code: [Select]
;Chek if the chopper is above the minimum launch altitude
? (getPos heli select 2) <20 : hint "The chooper must be at least 20 meters above the ground!"; exit

player removeaction siluro

;Check if there's a Torpedo still available
?NumSil == 0 : player sidechat "All Torpedoes fired" && exit

;Set and check the number of Torpedoes remaining
NumSil = NumSil -1
_torprem = NumSil

;Check if the player already fired a Torpedo. This select from wich side of the chopper the Torpedo will be created
? NumSil == 1 : goto "RightSide"

;Left-mounted Torpedo generated, fired and attached to a parachute
player sidechat format ["Torpedo away! %1 remains.", _torprem]
_torp = "LaserGuidedBomb" createVehicle [(getPos heli select 0)-3,(getPos heli select 1),(getPos heli select 2)-1]
_torp setDir (getDir heli)
_torp setVelocity [(velocity heli select 0)*0.2,(velocity heli select 1)*0.2,(velocity heli select 2)*0.2]
_chute = "parachute" createVehicle [(getPos _torp select 0),(getPos _torp select 1)-3,(getPos _torp select 2)-0.5]
goto "LoopChute"

;Right-mounted Torpedo generated, fired and attached to a parachute
#RightSide
player sidechat format ["Torpedo away! %1 remains.", _torprem]
_torp = "LaserGuidedBomb" createVehicle [(getPos heli select 0)+3,(getPos heli select 1),(getPos heli select 2)-1]
_torp setDir (getDir heli)
_torp setVelocity [(velocity heli select 0)*0.2,(velocity heli select 1)*0.2,(velocity heli select 2)*0.2]
_chute = "parachute" createVehicle [(getPos _torp select 0),(getPos _torp select 1)-2,(getPos _torp select 2)-0.5]

#LoopChute
_chute setpos [(getPos _torp select 0),(getPos _torp select 1)-2,(getPos _torp select 2)-0.5]  
?(getpos _torp select 2) <= 3 : goto "Continue"  
~0.1
goto "LoopChute"

#Continue
;The initial (and rough) probability of hitting the target, given by the distance between the Torpedo and the target....
?(_torp distance sub) >1000 : _DistPerc = 1
?(_torp distance sub) <1000 : _DistPerc = 2
?(_torp distance sub) <800 : _DistPerc = 4
?(_torp distance sub) <600 : _DistPerc = 8
?(_torp distance sub) <400 : _DistPerc = 16
?(_torp distance sub) <200 : _DistPerc = 32

;....by the position of the target to the angle of acquisition of the Torpedo's targeting system wich I set to 120 degrees....
_source = _torp
_target = sub
_sourcedir = getdir _torp
_degree = ((getpos _target select 0) - (getpos _source select 0)) atan2 ((getpos _target select 1) - (getpos _source select 1))
?_degree < 0:_degree = _degree + 360

;The better the alignement of the Torpedo respect the target the higher the chance to hit
;This simulate the time spended by the Torpedo in maneuvering for a proper alignement
_degree = _degree - _sourcedir
?_degree >= 61 : _Angleperc = 16 ; hint format ["più %1, risulta %2, atteso 16", _degree, _Angleperc]
?_degree <= 40 : _Angleperc = 18 ; hint format ["più %1, risulta %2, atteso 18", _degree, _Angleperc]
?_degree <= 20 : _Angleperc = 20 ; hint format ["più %1, risulta %2, atteso 20", _degree, _Angleperc]

;The amount of time in seconds the Torpedo need to cover the distance between itself and the target
;I've decided to set the speed of the Torpedo at 30 knots (about 72 km/h if I'm not wrong, so 20 mt/s)
~2
_speedtorp = 20
_speedsub = speed sub / 3.6
_dist = (_torp distance sub)
_timeleft = _dist / (_speedtorp - _speedsub)
hint format ["%1", _timeleft]

;Torpedo is deleted before hitting the ground
@(getpos _torp select 2) <= 2
deletevehicle _torp
deletevehicle _chute


;Set the amount of decoys the sub will launch after the Torpedo is detected.
;Every decoy launched decrease the chance to hit the target by 1%
;Decreasing _factor value, increase the "number" of decoys launched
;_subskill = skill sub
;_factor = 10
;_DecoyFactor = _subskill * (_timeleft / _factor)

;The final overall chance to hit
;_HitPerc = ToHit + ((_DistPerc + _Angleperc) - _DecoyFactor)
_HitPerc = ToHit + (_DistPerc + _Angleperc)

;The awaiting....
;player sidechat format ["%1 seconds before impact. Chances to hit: %2/100. %3 decoys launched." _timeleft, _HitPerc, _DecoyFactor]
player sidechat format ["Chances to hit: %1/100.", _HitPerc]

_count = 15

#Timer
~1
_count = _count - 1
? (_count == 0) : goto "AlmostEnd"
TitleText [format ["%1", _count], "Plain Down"]
goto "Timer"



;The final result
#AlmostEnd
;If the speed of the target is higher than the Torpedo's one, It will never reach It's target
? _speedsub >= _speedtorp : player sidechat "Target speed too high. Engagement lost."; exit
titletext [" ","Plain Down"]
_number = random 100
? _number <= _HitPerc : goto "Destroyed"

;Bad end
player sidechat format ["Target missed! %1 Torpedoes remains.", _torprem]
goto "End"

;Good End
#Destroyed
sub setdammage 1
flare = "Pipebomb" camCreate (getPos sub)
flare = "SmokeShell" camCreate (getPos sub)
~1.5
player sidechat "Impact! Target hit!"

;Now the player can try another launch
#End
siluro = player addaction ["Launch Torpedo","Torpedo.sqs"]

;script end
exit
« Last Edit: 28 Jan 2005, 13:22:26 by klavan »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Problem with this calculation. Please help.
« Reply #10 on: 28 Jan 2005, 13:47:20 »
distance is fine for two objects.

Have you checked that the line:
Code: [Select]
_torp = "LaserGuidedBomb" createVehicle [(getPos heli select 0)+3,(getPos heli select 1),(getPos heli select 2)-1]acually creates something?

try:
hint format["%1",_torp]

and see what you get.  I bet you get something about Scalar.... which means the _torp is not defined.

klavan

  • Guest
Re:Problem with this calculation. Please help.
« Reply #11 on: 28 Jan 2005, 13:54:14 »
Stupid Klavan, silly Klavan, idiot Klavan!!!!

Before:
Code: [Select]
;Torpedo is deleted before hitting the ground
@(getpos _torp select 2) <= 2
deletevehicle _torp
deletevehicle _chute

After:
Code: [Select]
;Torpedo is deleted before hitting the ground
deletevehicle _torp
deletevehicle _chute

Wow! Probably the calculation haven't enough time for getting the results, because:

Code: [Select]
#LoopChute
_chute setpos [(getPos _torp select 0),(getPos _torp select 1)-2,(getPos _torp select 2)-0.5]  
?(getpos _torp select 2) <= 3 : goto "Continue"  
~0.1
goto "LoopChute"

All runs OK, now!!!! :) ;D
Now I can go to work more happy!!!!