[Discussion] Generic X3TC S&M questions II

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

$Damage = $Damage / ($Range * $Range)

I like this formula, it sets the max.range off the max.damage, though you do need to watch out for too large of ranges and zeros.
you could do this:

Code: Select all

$max.range = 20000
skip if $range < 20000
  continue
if $range = 0
 destruct
 continue
end
$Damage = $Damage / ($Range * $Range) 
If you want to set a max range and have it be linear across the range, then use this formula:

Code: Select all

$max.damage = 100000
$max.range = 10000
$damagePerRange = $max.Damage / $max.range
$damage = $max-damage - ($range*$damagePerRange)
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

Hmm, problem with the first is that I've still got a 'Damage' in there; I have to set a value for it at some point, and whenever I do that it seems not enough and too much - Capital ships right next to the explosion take a tiny percent, fighters a reasonable way away get almost vapourised...

Any way for me to factor in some ship size or whatever in there...?

Now the second is good, I think I'd use that...

Hmm, how about bigger ships take more hits? Calculated by class, or by hull amount? What does Object Size do?
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

Any way for me to factor in some ship size or whatever in there...?
Yes, ship size would be a good factor. If your script should only work IS, then you can simply use the "get ship size" command, otherwise I'd recommend a library of Gazz', which also works for ships OOS.

And then you can simply say:
$factor = 150
$damage = $shipSize * $factor / ($range * $range)

The ideal value for $factor has to be found experimentally of course. But it would be the same for every ship, so no messing around with if-else-constructs to take into account all ship classes.

The good thing with a non-linear apporach (like the above) is that the distance has a very big influence on the amount of damage. Additionally, it is more believable, since that's how explosions and such behave in reality.

Greetings,
ScRaT
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

Yeah, it's be nice to have a small zone of slaughter then a large damage area around. How exactly does that command work? Physical size? Class?
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

You mentioned lots of damage to a certain range, then less out to a greater range:
Something like this would to that.

Code: Select all

$total.damage = 100000
$high.damage.per.m = 20
$high.max.range = 4000
$low.max.range = 10000

* calculation to determine remaining damage after high damage range
$damage.remaining = $max.damage - ($high.max.range * $high.damage.per.m )
* = 20000

* calculation to determine low damage per meter
$low.damage.per.m = $damage.remaining / ( $low.max.range - $high.max.range )
* = 3

* if inside high damage radius
if $range < $high.max.range
  $damage = $max.damage - ($high.damage.per.m * range)

* else if inside low damage radius, create the new zero distance where 
* full remaining damage is applied by subtracting high.max.range from 
* range
else if $range < $low.max.range
  $range = $range - $high.max.range
  $damage = $damage.remaining - ($low.damage.per.m * $range)
end

The following is based on intuition, not experience:
When you set the damage to subtract shielding and hull.. do not set either to 0. Drop shields down to 1 then start subtracting hull down to 1.
Set a conditional that if the ship's hull equals 1 hp, then destruct it. Never let it go to zero or negative.


Since there are only a few classes, M1, M2, M7 that I think you'll use, I'd just make an array with the damages you want.
$dmg[0] = 200000 *M1 (sizable reactors and lots of missiles/secondary ships going boom)
$dmg[1] = 150000 *M2 (big reactors going boom)
$dmg[3] = 75000 *M7 (sizable reactors going boom)
$dmg[4] = 100000 *M7M (moderate reactors plus missiles going boom)

Tweak them as necessary. The initial damage is important, however I believe the true impact on the player lies in the kill radius'.
Last edited by h2o.Ava on Sun, 28. Nov 10, 10:30, edited 2 times in total.
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

Why not 0? Works fine...

EDIT: Also, not 2 actual different damage zones, it'll just decrease exponentially. So you end up with a very small area of mass damage, and a large area of ever decreasing damage, then some sort of cut off point.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

ah, yeah that formula creates two different linear zones.
you want an exponential curve..
I'll have to pass on that one, at least for now.
Brain and body are getting sleepy.
if you want to play with numbers and such,
try
http://www.wolframalpha.com/
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

I did create a curve yesterday and try to work out how to implement it... but I was in the same position as you. Tired. :P


Also: Can't find ship size command, I know where object size is but that's it, is that what you meant?
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

Also: Can't find ship size command, I know where object size is but that's it, is that what you meant?
Yes, I guess. I never used it.
How exactly does that command work? Physical size? Class?
Afaik it returns the radius of the bounding sphere (or something similar) of the object. So it is not very accurate, but in your case it would get the job done.

Greetings,
ScRaT
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

Yeah, set it up, the problem is the damage returned is minscule.

Take a Disco 500m away, (size 12), multiply by a factor of 1,000,000 to get 12,000,000, the divide by 500^2...


You get 12M / 250k...

Or... 48 damage.

Dada! :roll: -.-

A factor much higher and I'll start breaking the maths.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

Take a Disco 500m away, (size 12)
Why do you take the size of the victim into account? If a disco explodes 500 m away, I don't expect much more than 48 damage. :D

Anyways, you can simply calculate the factor, by rearranging the formula:

damage = (size * factor) / distance²
<=> factor = damage * distance² / size

Like this, you could calculate what a sensible value for factor is, based on your expectations for the damage done by an object with size size at a given distance.


What size does a M1 or M2 have?

Greetings,
ScRaT
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

A Titan has 1091.
A Colossus has 1022.

But now we're back to the same problem of setting a reasonable max damage. :P
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

try changing it to km after 500m^2 (toying with math but it might work for you)

"Take a Disco 500m away, (size 12), multiply by a factor of 1,000,000 to get 12,000,000, the divide by 500^2... then divide the bottom by 1000.


12M / (250k / 1000)

48000

using the size of the victim simulates the Disco could "ride the wave" if it is far enough away, otherwise it goes pop

edit: as MIT's physics professor says, 500m/1000m to convert to km, then squaring the result: 0.5km^2 and 500m^2 then converting to km 250k/1000m are both correct answers" ..wait wait.. that was my calc 2 professor and the boiling water volume in the cauldron problem.. depending on when you convert, the cauldron will be skinny or huge, both are correct answers, however you must know when to convert to apply it correctly.
I'd say the above formula could work well.
Last edited by h2o.Ava on Sun, 28. Nov 10, 12:19, edited 2 times in total.
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

I am using the size of the victim. It only makes sense that a larger ship is gonna have more bits of K reactor thrust through it... :P It just has a higher chance of surviving it than a Disco. :D

Theoretical damage appears to be reasonable. The problem I have now is it's stopped doing hull damage again and is just wiping everyone's shields...


:wall:
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

But now we're back to the same problem of setting a reasonable max damage.
Yes, but you do not need to try random factors, but you can simply think of a scenario and get a factor.

Example:

A Titan explodes 500 m away from your Buster without shields, but complete hull. I'd expect the Buster to explode, which means that the damage should be at least 3500. Using these values, the factor becomes:

factor = 3500 * 500² / 1091 = 802016

So when your buster is instead at a distance of 750 m your damage would be:

damage = (1091 * 802016) / 750² = 1555

Seems to be a reasonable value to me.

1091 * 802016 doesn't even produce an overflow. But to be sure you could divide the factor by 100 and multiply the damage by 100 again.
I am using the size of the victim.
I wouldn't use it. Maybe at a later stage for adjusting the resulting damage (which is actually a damage / m²) to the size of the ship, because a big ship will be hit by a larger portion of the wave than a small ship.

Greetings,
ScRaT
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

So you want the Ship Size to be the size of the asploding ship? :P

As for the scenario, yes, looks about right, but considering the explosions are several Km outwards that 250m makes a very big difference, halving it... so I say the buster would explode a lot more than it did... Put it this way, a buster with full shields at 200m would explode?
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
User avatar
ScRaT_GER
Posts: 1962
Joined: Tue, 8. Jan 08, 18:19
x3tc

Post by ScRaT_GER »

Eventually you have to decide if you want a phyically rather correct model, where the intensity is proportional to the inverse of the square distance, or some other model, where you use another formula, which suits the game better. After all X is not a simulation, but a game.
So you want the Ship Size to be the size of the asploding ship?
Yes.
but considering the explosions are several Km outwards
Several kilometers would most likely result in almost no damage, which I find sensible aswell.

As you can see the curve converges to zero quite quickly. So close to the exploding ship the damage is really big, but it decreases very quickly.

Greetings,
ScRaT

Edit: Why won't it show the Wolfram|Alpha link?
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

though we are talking about extremely advanced tech that is extremely powerful, I'd think a M2 would be the equiv of a multi gigaton nuke, lets hope nobody ever makes one for real..
User avatar
EmperorJon
Posts: 9378
Joined: Mon, 29. Dec 08, 20:58
x3tc

Post by EmperorJon »

Yeah, the current problem is any M5 within 7-8km is toast. :P

EDIT: Except, once again, it's refusing to hit the hull directly.

Code: Select all

001   $Factor = 150000
002   $ShipSize = [THIS] -> get size of object
003   
004   $Checking = [THIS] -> get local variable: name='ej.military.bigship.blast'
005   $BlastPlaceholder = [THIS] -> get local variable: name='ej.wreck.explo'
006   if $Checking != [TRUE] AND $BlastPlaceholder == [FALSE]
007   |[THIS] -> set local variable: name='ej.military.bigship.blast' value=[TRUE]
008   |
009   |$Sector = [THIS] -> get sector
010   |$Att = [THIS] -> get attacker
011   |
012   |$ShipA = $Sector -> get ship array from sector/ship/station
013   |$StaA = $Sector -> get station array from sector
014   |
015   |$Count1 =  size of array $ShipA
016   |while $Count1
017   ||dec $Count1 = 
018   ||$Ship = $ShipA[$Count1]
019   ||$Hull = $Ship -> get hull
020   ||skip if not $Ship -> is invincible
021   |||continue
022   ||skip if not $Ship == [THIS]
023   |||continue
024   ||skip if $Ship != [THIS]
025   |||continue
026   ||$Range = get distance between [THIS] and $Ship
027   ||if $Range == 0
028   |||$Range = 1
029   ||end
030   ||$Damage = $ShipSize * $Factor / ( ( $Range * $Range ) / 1000 )
031   ||$HullPromtp =  convert number $Damage to string
032   ||write to player logbook $HullPromtp
033   ||
034   ||$Shield = $Ship -> get current shield strength
035   ||$ShieldAfter = $Shield - $Damage
036   ||$Ship -> set current shield strength to $ShieldAfter
037   ||
038   ||if $ShieldAfter <= 0 OR $Shield <= 0
039   |||$Debt = $Damage - $Shield
040   |||skip if $Debt >= 0
041   ||||continue
042   |||send incoming message 'Continued' to player: display it=[TRUE]
043   |||$HullAfter = $Hull - $Debt
044   |||$Ship -> set hull to $HullAfter
045   |||$FinalHull = $Ship -> get hull
046   |||$HullPromtp =  convert number $FinalHull to string
047   |||if $FinalHull <= 0
048   ||||$Ship -> destroy object: killer=[THIS], show no explosion=[FALSE]
049   ||||
050   |||end
051   ||end
052   |end
053   |(Continues for stations...)
[/size]
It's triggering the 'Continued' bit, even though the damage owed to the hull should be greater than 0.

Wait, or is it...? Good point, it'll always trigger continued because of how skip only skips one line.

Hmm.

Well, the point is it's still not doing any hull damage to anything, infact the only thing it's killed so far has been my spacesuit, which is I believe because it has 0 hull technically... or does it? :S


EDIT: Still making adjustments, keep getting odd problems... sems to be killing some ships and not damaging the hull of the rest. Found a few bits of code and spruced them up... still must be problems somewhere.

The Debug continues!

Thanks all for help so far, I hate debugging the maths.
______
I'm Jon. I'm mostly not around any more. If you want to talk, please message me! It's cool.
______
h2o.Ava
Posts: 349
Joined: Sun, 12. Oct 08, 04:04
x4

Post by h2o.Ava »

Try this:

Code: Select all

$factor = 150000
* did you want the size of the victim or the exploding ship?
$size = [THIS] -> get size of object
$sector = [THIS] -> get sector
$attacker = [THIS] -> get attacker

$ships = $sector -> get ship array from sector/ship/station
$stations = $sector -> get station array from sector

**** new
$max.range =  'something to prevent overrun since you are checking every ship in the sector, perhaps change -get arrays- to -find ship/station-'


$i = size of array $ships
while $i
dec $i =
$ship = $ships[$i]

skip if not $ship == [THIS]
  continue
skip if $ship != [THIS]
  continue
****begin new
skip if $ship->exists
  continue
$hull = $ship->get hull
skip if $hull > 0
  continue
****end new
skip if not $ship->is invincible 
  continue


$shield = $ship -> get current shield strength

$range = get distance between [THIS and $ship
skip if $range < $max.range
  continue
skip if $range > 0
  $range = 1

$damage = $size * $factor / ( ( $range * $range ) / 1000 )

**** begin changed
$damageRemaining = $damage - $shield
$shieldDamage = $damage - $damageRemaining

if $damageRemaining > 0
  $hullDamage = $hull - $damageRemaining
  if $hullDamage < 1
    $text = sprintf: fmt='(Destroyed)Ship: %s    Initial Stats: Shield: %s    Hull: %s    Size: %s    Range: %s', $ship, $shield, $hull, $size, $range
    write to player logbook $text
    $ship -> destroy object: killer=[THIS], show no explosion=[FALSE]
    continue
  end
  $ship -> set hull to $hullDamage
end
$ship -> set current shield strength to $shieldDamage
$text = sprintf: fmt='(Damaged)Ship: %s    Initial Stats: Shield: %s    Hull: %s    Size: %s    Range: %s', $ship, $shield, $hull, $size, $range
$text.str = sprintf: fmt'%s        After: Shield: %s    Hull: %s', $text, $shieldDamage, $hullDamage, null, null
write to player logbook $text.str
**** end changed

return null

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”