[Request] Cap ships use boost when DESTINATION is (insert range)

The place to discuss scripting and game modifications for X Rebirth.

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

Conbadicus
Posts: 217
Joined: Sat, 13. Feb 10, 09:31

[Request] Cap ships use boost when DESTINATION is (insert range)

Post by Conbadicus »

I know there is a mod that increases ship speed, and I know cap ships will boost to the target if they are coming from out of zone.

I think it would make sense if a cap ship would boost within a zone if the target is say, over 5k away. For example, ships that follow me into zone usually boost to the edge and then slow boat it for the next 40k as they engage a target or dock for trading.
If i order someone to refuel and theyre across the zone they slow boat it.
NPCs in zone pick up enemy invaders on radar then turn very slowly and move towards the target, by the time they get there tons of damage has been done - etc. I don;t see why they can't boost to within 15km (or what ever their desired range for their weapons is etc)
Last edited by Conbadicus on Tue, 31. Mar 15, 08:07, edited 1 time in total.
Conbadicus
Posts: 217
Joined: Sat, 13. Feb 10, 09:31

Post by Conbadicus »

Really??? Everyone is Hunky Dory with slow boating for zone edge???
Conbadicus
Posts: 217
Joined: Sat, 13. Feb 10, 09:31

Post by Conbadicus »

Ok, well then can someone point me in the right direction to learn how to do this myself? Or at least tell me its isn't possible so I don't waste my time?
bm01
Posts: 421
Joined: Wed, 22. Jul 09, 22:31
x4

Post by bm01 »

It seems to be somewhat complicated.

If you ask a ship to attack something in the same zone, it will run 'move.attack.object.capital'. On line 91 you could add something like that (not tested):

Code: Select all

<do_if value="this.ship.distanceto.{$target} gt (40km + this.ship.size)">
  <do_while value="this.ship.distanceto.{$target} gt (10km + this.ship.size)">
    <start_boost object="this.ship"/>
    <!--
      'x' and 'z' should be at about 'maxcombatrange' from the target and that point in space should ideally be the right angle of the right-angled triangle formed by the three positions.
      Except for Balors and Sucellus which should stop on the most direct path, their front side turned toward the target.
      Also Balors would want to stop sooner.
    -->
    <set_value name="$x" exact=" "/>
    <set_value name="$z" exact=" "/>
    <!-- 'move_to' has a lot of parameters, some of them might be needed -->
    <move_to destination="this.zone" object="this.ship" usehighways="false">
      <position x="$x" y="$target.pos.y" z="$z"/>
      <interrupt_after_time time="2s"/>
      <interrupt>
        <conditions>
          <event_object_destroyed object="$target"/>
        </conditions>
        <actions>
          <!-- might not work, need testing -->
          </break>
        <actions/>
      </interrupt>
    </move_to>
  </do_while>
  <stop_boost object="this.ship"/>
</do_if>
However this will make the ship follow an odd path if the target is moving fast, even worse if it's boosting. The 'interrupt_after_time' value is hard to guess but it probably shouldn't be higher with a 10km loop.

We probably can't use 'get_safe_pos' because that would make the path even more odd and occasionally make the ship bumping into its target (and because of X Rebirth physics that would make the target fly far away).

Also maybe you don't need the while loop. Boosting is fast, tell the ship to go at 10km from the target and wait until it arrives there. Much better performance wise but much less accurate and potentially bad for ships having damaged engines (rare case, I admit).

In my opinion it's pretty hard to get a good result. Also, that's only for attacking ships, you would have to modify a few other scripts to cover all cases.
w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans »

bm01 wrote:We probably can't use 'get_safe_pos' because that would make the path even more odd and occasionally make the ship bumping into its target (and because of X Rebirth physics that would make the target fly far away).
Is there a reason why get_safe_pos shouldn't work well in this case? I use it for my in-zone boosts, and it seems to work ok.

This is what I use for the approach target phase with irrelevant bits cut off:

Code: Select all

<do_if value="this.ship.macro.ismacro.{macro.units_size_xl_red_destroyer_macro} or this.ship.macro.ismacro.{macro.units_size_l_single_attack_ship_macro}">
<!--<do_if value="this.ship.maxcombatrange.primary ge 8000 or this.ship.maxcombatrange.secondary ge 8000">-->
	<set_value name="$MICT_MaxJumpDist" exact="this.ship.maxcombatrange.all * (2.0f - ((this.skill.navigation + this.skill.morale)f / 10.0f))"/>
	<set_value name="$MICT_MinJumpDist" exact="this.ship.maxcombatrange.all * (0.25f * (1.0f + (2.0f * ((this.skill.navigation + this.skill.morale)f / 10.0f))))"/>
</do_if>
<do_else>
	<set_value name="$MICT_MaxJumpDist" exact="this.ship.maxcombatrange.turrets * (2.0f - ((this.skill.navigation + this.skill.morale)f / 10.0f))"/>
	<set_value name="$MICT_MinJumpDist" exact="this.ship.maxcombatrange.turrets * (0.25f * (1.0f + (2.0f * ((this.skill.navigation + this.skill.morale)f / 10.0f))))"/>
</do_else>

...

<get_safe_pos result="$MICT_MovePos" zone="$target.zone" radius="this.ship.size" object="$target" min="$MICT_MinJumpDist" max="$MICT_MaxJumpDist" allowyaxis="true"/>

...

<start_boost object="this.ship"/>
<move_to object="this.ship" destination="$target.zone" forcesteering="false" forceposition="false" forcerotation="false" finishonapproach="true" sinceversion="2">
	<position value="$MICT_MovePos"/>
	<rotation value="$MICT_AimVector"/>
	<interrupt>
		<conditions>
			<check_any>
				<event_object_destroyed object="$target"/>
			</check_any>
			<check_value value="not $target?"/>
		</conditions>
	</interrupt>
	<!--<interrupt_after_time time="$MICT_update"/>-->
</move_to>
<stop_boost object="this.ship"/>
<stop_moving object="this.ship"/>
Seems to work ok.

@op, the thing with in-zone movement is that it's not all in one script. Which movement script is used depends mostly on why the ship is moving. Easy to change behavior when ships move between zones since they then, I think in all cases, reference move.generic (so just patch move.generic or move.nohighways which is referenced by move.generic for the inter-zone boost stuff). This is also the reason why movement mods are mostly purpose-specific: bm01's escape script, the various fighting scripts, oliverjanda's jump to Skunk script, etc. Not impossible, but unwieldy. One mod that changes ALL movement scripts is UFO, but the new movement stuff then only applies to UFO ships.
bm01
Posts: 421
Joined: Wed, 22. Jul 09, 22:31
x4

Post by bm01 »

w.evans wrote:
bm01 wrote:We probably can't use 'get_safe_pos' because that would make the path even more odd and occasionally make the ship bumping into its target (and because of X Rebirth physics that would make the target fly far away).
Is there a reason why get_safe_pos shouldn't work well in this case? I use it for my in-zone boosts, and it seems to work ok.
It would give a random position each time and I think that would affect the fly path in a weird way since it's actualized every two seconds (but again, actualizing the position that often might not be a good idea in the first place).
But mostly because it could give a position behind the target and our ship would bump into it.
w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans »

I didn't consider that, thanks! Oddly, I never noticed my ships doing that, but you're right: it is possible. Could be avoided by specifying a quadrant relative to the target ship (example: direction="quadrant.up" should keep the ship up relative to the target ship).

edit: just noticed interrupt time. I took that out because it seemed to make the ships stop boosting every time the interrupt is triggered, so they plot a position, boost to that position, and only then check again.
Last edited by w.evans on Wed, 1. Apr 15, 13:05, edited 1 time in total.

Return to “X Rebirth - Scripts and Modding”