[SCR] Replication v1.0.0 (21-03-14)

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

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

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

[SCR] Replication v1.0.0 (21-03-14)

Post by Shimrod » Fri, 21. Mar 14, 23:34

Summary

This script adds a Replicator ware to a selection of docks. When equipped with replicator units a ship can produce missiles, energy cells, ammo, drones and satellites over time.

When a ship has one or more replicator units it gains an additional ship command "Replicate..." which opens a menu:
- Set the production limits for each ware
- Begin replication.
- View the status of the current replication cycle through dynamic menu updates

Note: The Replicator uses an EMP-X ware entry; please see the Dependencies section.

Applications
- Jump around with follower ships without micromanaging energy
- Retain a buffer of missile defence mosquitoes
- Drone carriers can absorb losses as long as your bank balance can support it.
- Live the ammo based weaponry dream. Missile boats with regenerating ammo
- Universe explorers with a ready supply of satellites

Dependencies
- This script requires the EMP-X which adds customizable ware entries.
- EMP-X is built into XRM
- X Plugin Manager applies the EMP-X when launching the game through it
- XTC only has EMP not EMP-X so script is incompatible.

Compatibility
- This has been tested on AP with XRM, and vanilla AP with X Plugin Manager.
- It doesn't work in XTC or XTC:AP as this does not have the EMP-X wares.

Format
- ZIP file containing T file and script files

Download

[ external image ]

Install/Uninstall
- To install, copy the script and t folder contents from the zip file to those folders of the same name either in the "x3 terran conflict" folder, or the "addon" subfolder if playing Albion Prelude.
- To uninstall, run the uninstall command from the replication menu, save the game, and remove the setup script before reloading. It may take a few seconds before replicator wares are removed from stations.

Stats
- Replicators do not require physical resources
- The cost of replicating a ware is equal to the maximum price of that ware.
- Each replicator unit contributes 60 credits toward ware production per second
- Add more replicator units to increase production
- A replication cycle lasts a minimum of 10 seconds
- Multiple cheap wares can be produced in a single 10 second cycle
- Expensive wares require lengthy cycles to produce single units
- Replicators are sold in various out of the way stations
- Replicators cost about 100k per unit and require a good reputation to buy.
- Replicators are 13 volume L class wares in vanilla and XL class in XRM.
- Replicators can be found at:
Spoiler
Show
Docks whose names include:
- Unknown (and docks in unknown sectors)
- Research
- Secret
- Communications
- Torus
- Installation
References
- Developed using X-Studio: http://forum.egosoft.com/viewtopic.php?t=301433

Script Resources

Code: Select all

Ship Additional Commands
  1233: COMMAND_TYPE_SHIP_33
Ware (EMP)
  62010: SS_WARE_SW_CUSTOM2_26
Text File, Task Id & Logfile ID
  9056



Edit [1st Dec 2015]: replaced outdated with working xdownloads link. X2-Illuminatus
Last edited by Shimrod on Wed, 8. Oct 14, 16:46, edited 23 times in total.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Fri, 21. Mar 14, 23:35

Change log

1.0.0
- Initial release

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Sun, 23. Mar 14, 21:29

Replicators are sold in various out of the way stations


Various and rare out of the way stations. ;) . Only two docks in my entire game were seeded with the ware. It took me a while to figure out whether the ware had installed properly.

However, it did work the first time for me (installed with PM).

This is a cool way to keep my ships supplied with Mosquito missiles for Missile Defense Mosquito. Nice.

  • Seems brave of you to use an EMP ware. :) I get a lot of trouble reports about them, so I go through some trouble to allow the script to "fall back" to a vanilla ware (or no ware) in case the EMP installation fails. Testing whether the ware has the correct name seems to be a reliable way to check whether the ware is properly installed.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Sun, 23. Mar 14, 22:24

One way to see where the ware is sold is to check the 9056 logifile either at first install, or about 10 sec after running the uninstall menu option. The restock tasks beginning or ending on the docks are traced regardless of logging setting.

It's my first foray into custom wares but no trouble so far, besides plugin manager clobbering the custom ware text. The original EMP seems to have been more friendly by naming its init script like a.a.a. to execute as early as possible in the startup chain.

So far I've been using it:
- On carriers to produce missiles that wing ships auto supply themselves with
- To minimize the amount of jump fuel required, since it regenerates, maximizing space for weapons
- To retain a good stock of drones while I had a small fleet (leading to a nice win in Astreus + 3xM6 vs Khaak advanced destroyer + 2 frigates - without strafing)
- To stock mosquitoes, swarms, heavy torpedoes on capships.

I thought it was a bug initially that mass driver ammo didn't appear in the list, but it turned out that XRM mass drivers don't require ammo.
Last edited by Shimrod on Sun, 23. Mar 14, 22:36, edited 2 times in total.

User avatar
DrBullwinkle
Posts: 5715
Joined: Sat, 17. Dec 11, 01:44
x3tc

Post by DrBullwinkle » Sun, 23. Mar 14, 22:31

Yeah, that is how I discovered where the ware was... by looking in the log. :)

No PM clobbering in my case; the ware got the correct name. But, then, my environment is EMP-friendly. My experience is that not all environments are so friendly.

Pierre'70
Posts: 124
Joined: Sat, 30. Apr 05, 12:19
x4

Post by Pierre'70 » Thu, 11. Sep 14, 11:53

I've been using this with XRM, and it works a treat, except that lots of missiles seem to be missing from the replication list. Is it possible to edit the t file to add in missiles added by XRM?

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Thu, 11. Sep 14, 12:01

It's filtered to the set of missiles that particular ship can use, in glen.replication.menu.xml by:

Code: Select all

$Unfiltered = $Ship -> get compatible missile array
Then filtered on

Code: Select all

$Ship -> can transport ware $Ware
This is aimed at making it easier to replicate the right kind of missiles for the ship, though I appreciate its not ideal for a carrier resupplying docked ships.

Pierre'70
Posts: 124
Joined: Sat, 30. Apr 05, 12:19
x4

Post by Pierre'70 » Thu, 11. Sep 14, 12:31

What should I edit to enable my ship to build all missile types? As you say, I'm trying to use it on a carrier. I like the idea of preventing replication of wares too large for the ship to hold - I don't want to remove this, only the restriction on missiles the ship can fire.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Thu, 11. Sep 14, 12:58

Try pasting the following subroutine to the end of glen.replication.menu.xml:

Code: Select all

Get.Missiles:
    $Missiles = array alloc: size = 0
    $idx = get number of subtypes of maintype 10
    while $idx
        dec $idx
        $Missile = get ware from maintype 10 and subtype $idx
        append $Missile to array $Missiles
    end
endsub
Then replace this:

Code: Select all

$Unfiltered = $Ship -> get compatible missile array
With this:

Code: Select all

gosub Get.Missiles:
$Unfiltered = $Missiles
Note to future self: add config checkbox for missile restriction

Pierre'70
Posts: 124
Joined: Sat, 30. Apr 05, 12:19
x4

Post by Pierre'70 » Thu, 11. Sep 14, 13:17

Sorry Shimrod, I can't find this to replace:


Then replace this:
Code:
$Unfiltered = $Ship -> get compatible missile array

With this:
Code:
gosub Get.Missiles:
$Unfiltered = $Missiles
in any of the Replication files (in t or scripts).

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Thu, 11. Sep 14, 15:07

Line 113 of glen.replication.menu.xml. I'm assuming you're familiar with X-Studio.

Code: Select all

113    * Determine the set of wares to show in the menu 
114    $Unfiltered = $Ship -> get compatible missile array 
115    append {Energy Cells} to array $Unfiltered 
116    append {Navigation Relay Satellite} to array $Unfiltered 
117    append {Advanced Satellite} to array $Unfiltered 
118    append {Keris} to array $Unfiltered 
119    append {Fighter Drone MKII} to array $Unfiltered 
120    append {Fighter Drone} to array $Unfiltered 

Pierre'70
Posts: 124
Joined: Sat, 30. Apr 05, 12:19
x4

Post by Pierre'70 » Thu, 11. Sep 14, 15:38

Ah. I've been trying to use Notepad++. I'm not really familiar with X-Studio. Sorry.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Thu, 11. Sep 14, 16:45

The scripts can't be edited directly as they have compiled code at the end. Not a problem with X-Studio though, just load the file in that, edit and save and it'll compile it to the right format. Has syntax highlighting, auto-completion and stuff.

X-Studio: http://forum.egosoft.com/viewtopic.php?t=301433

Pierre'70
Posts: 124
Joined: Sat, 30. Apr 05, 12:19
x4

Post by Pierre'70 » Thu, 11. Sep 14, 17:15

I've got X-Studio working and opened the correct file in it. I've tried following your instructions but it refuses to save the file after I have altered it. I'm getting the following errors:

Unrecognised or incomplete script command on line 114 : 'gosub Get.Missiles:'
Unrecognised or incomplete script command on line 295 : 'Get.Missiles:'
The variable '$Missiles' on line 115 is being used without being assigned
Compilation aborted due to syntax errors in script commands

Forgive my muppetry over this, thanks for your patience.

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Thu, 11. Sep 14, 17:50

I've never seen that before. You can ignore the use without assignment warning, it's just a simple top to bottom check and doesn't follow branches.

Thoughts:

There are other gosubs in the file. Does what was pasted look different? Try copy and pasting one of them then rename it to Get.Missiles.

Maybe some strange characters got pasted in that's confusing it, like with Word's smart quotes. A funky colon? :)

On rare occasions I've seen X-Studio occasionally report a line as an error until I retype it. Try re-typing those lines manually.

If you saved the file in notepad++ previously maybe it's corrupt.

Pierre'70
Posts: 124
Joined: Sat, 30. Apr 05, 12:19
x4

Post by Pierre'70 » Thu, 11. Sep 14, 18:21

SUCCESS! Er, oh dear. I took your advice and manually typed in the required lines (on a fresh version of the file I hadn't edited with Notepad ++). This saved properly with no error messages. The only problem is that when I loaded a save I found that I couldn't now Replicate ANY missiles at all - only satellites and drones!

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Thu, 11. Sep 14, 20:18

Progress :)

To debug, insert some logging into Get.Missiles as follows. It'll output to 'Documents\Egosoft\X3AP\log01234.txt'.
a. If no logging appears check that Get.Missiles is being called
b. If no missiles are found, check the logic of Get.Missiles
c. If missiles are found, check that the calling logic is assigning $Unsorted = $Missiles.

Code: Select all

Get.Missiles: 
    $Missiles = array alloc: size = 0 
    $idx = get number of subtypes of maintype 10

write to log file 1234 append=0 printf: fmt='Found %s missiles', $idx, null, null, null, null

    while $idx 
        dec $idx 
        $Missile = get ware from maintype 10 and subtype $idx 

write to log file 1234 append=1 printf: fmt='Missile=%s', $Missile, null, null, null, null

        append $Missile to array $Missiles 
    end 

write to log file 1234 append=1 printf: fmt='Missiles=%s', $Missiles, null, null, null, null

endsub 

Pierre'70
Posts: 124
Joined: Sat, 30. Apr 05, 12:19
x4

Post by Pierre'70 » Thu, 11. Sep 14, 22:43

I've created a log, it says

Found null missiles
Missiles=ARRAY ( )


Not sure what to do next!

Shimrod
Posts: 907
Joined: Tue, 18. Feb 03, 01:43
x4

Post by Shimrod » Fri, 12. Sep 14, 00:06

I pasted that same Get.Missiles code and it finds them for me, how bizarre.

The found 'null' missiles might be a clue though, as null tends to mean its either uninitialized or is returned as a fallback when doing dodgy operations (5 + null = null). I'd be suspicious of that $idx assignment.

In case you're wondering where the magic number of 10 comes from, maintypes are like ware categories and 10 is the category for missiles:
http://forum.egosoft.com/viewtopic.php?t=292613

Btw I noticed when pasting from the forum's code block that it adds a trailing space to every line, and this seems to be what caused the compile error in X-Studio. Trimming off the space makes it work.

Code: Select all

Found 49 missiles
Missile=Pirate Dummy Missile
...
Missile=Mosquito Missile
Missiles=ARRAY ( Pirate Dummy Missile, Teladi Dummy Missile, Split Dummy Missile, Paranid Dummy Missile, Boron Dummy Missile, Argon Dummy Missile, Gibson Barrage Missile, Heinlein Heavy Torpedo, ... )
As a last resort you could hardcode them:

Code: Select all

Get.Missiles: 
    $Missiles = array alloc: size = 0
    append {Mosquito Missile} to array $Missiles
    ...
endsub
You can use X-Studio's Game Objects tab on the right to filter down to a list of missiles then double-click them to insert the appropriate token for that missile into the code window at the cursor.

Pierre'70
Posts: 124
Joined: Sat, 30. Apr 05, 12:19
x4

Post by Pierre'70 » Fri, 12. Sep 14, 11:49

I've got it working. Copy-pasting, then removing the space from the end of each line, did the trick. Not sure how I managed to mess up manually typing the code in.

Thanks for your patience and help Shimrod. Not sure why there isn't more traffic on this topic, Replication is a great script.

Post Reply

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