successful script that fixes factories - I told you so

The place to discuss scripting and game modifications for X²: The Threat.

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

easternblocrobotcowboy
Posts: 120
Joined: Sun, 15. Feb 04, 23:21
x2

successful script that fixes factories - I told you so

Post by easternblocrobotcowboy » Sat, 20. Mar 04, 20:58

I finally got around to writing a script that can fix ultra-high end fabs like 125 Mw Shield fabs and PPC fabs. It was damn easy, all you naysayers need to open your eyes and see that it was possible. In fact, when yuosee this script you will be dumbfounded noone has done this yet. Hell I cant believe I was the one who had to do this, Im not nearly as smart as some of the other scripters.

Anyway, the old 125 Mw shield fabs made you use about 600,000 credits to build an 850,000 credit shield, and they took 8 hours and twenty minutes to complete a cycle. TOTALLY NOT worth it. This script mods them to use 1/2 the resources to produce the same shield normally (not dependant on secondary resources), and if you fill em up with 82 quantum tubes (as secondary resource - worth about 250K total) they will build them twice as fast: one at the BEGINNING of the cycle and one at the END of the cycle.

All these parameters are adjustable depending on whatever any modder dreams up.

Now this script is just a working example, I have currently made it just for Argon fabs, but with a simple If/then tree you could easily add in the other racial fabs and add the appropriate commodity.

Please pardon the title and some of the comments/variable names - I STILL dont know how to start a script of my own, so I have to gut another uncommon script and fill it with my code. Thanks to Gnowar and Francium de Neobie who wrote the original code that inspired this script.

Code: Select all

001   * Author - francium de neobie
002   * Check if we are running from a newly started game
003 @ if [THIS] -> call script 'libfdn.CheckPlayingTime' :  name of script='Free 1MW Shield'
004    return -1
005   end
006   * Check if there are no previous instances, and get the pid if succeed
007 @ $pSignature = [THIS] -> call script 'libfdn.ScriptIsAlone' :  Race=Race 2  Sector=Akeela's Beacon  Ship Type=Xenon H
008   if not $pSignature
009    return -1
010   end
011   
012   $FoodArray =  array alloc: size=99
013   $i = 0
014   while $i < 99
015    $FoodArray[$i] = 0
016    inc $i = 
017   end
018   
019   * Begin the main loop
020   while [TRUE]
021   * Check if the current process is killed
022    if not $pSignature -> exists
023     return null
024    end
025   * All checks ok. First, get all player SSPs
026    $MySPPs =  array alloc: size=0
027    $AllSSPTypes =  array alloc: size=0
028    append Argon Shield Prod. Facility 125MW to array $AllSSPTypes
029    $nSSPTypes =  size of array $AllSSPTypes
030    
031    $i = 0
032    while $i < $nSSPTypes
033     $CurrentSSPType = $AllSSPTypes[$i]
034 @   $CurrentSSPs = [THIS] -> call script 'libfdn.GetAllStations' :  Race=Player  Sector=null  Station Type=$CurrentSSPType
035 @   $temp = [THIS] -> call script 'libfdn.CombineArrays' :  Array1=$MySPPs  Array2=$CurrentSSPs
036     $MySPPs = $temp
037     $i = $i + 1
038    end
039    
040   * Delete their primary crystal slot and create secondary crystal slot
041    $i = 0
042    $nSSPs =  size of array $MySPPs
043    while $i < $nSSPs
044     $CurrentSSP = $MySPPs[$i]
045     if not $CurrentSSP -> uses ware Quantum Tubes as secondary resource
046      $CurrentSSP -> add second resource to factory: Quantum Tubes
047     end
048     
049   * the o so difficult factory start checker
050     if $CurrentSSP -> uses ware Quantum Tubes as secondary resource
051      $x = $FoodArray[$i]
052      $y = $x - 4500
053      $z = $CurrentSSP -> get true amount of ware Meatsteak Cahoonas in cargo bay
054      
055      if $z < $y
056       $CycleStart = [TRUE]
057      else
058       $CycleStart = [FALSE]
059      end
060      
061   * resource regeneration upon the start of factory cycle
062      if $CycleStart == [TRUE]
063       $retvar = $CurrentSSP -> add 7500 units of Energy Cells
064       $retvar = $CurrentSSP -> add 2500 units of Meatsteak Cahoonas
065       $retvar = $CurrentSSP -> add 750 units of Ore
066       
067   * enhanced production with a full load of quantum tubes. 
068   * will only activate upon beginning of a start cycle
069       $Tubes = $CurrentSSP -> get true amount of ware Quantum Tubes in cargo bay
070       
071       if $Tubes >= 82
072        $retvar = $CurrentSSP -> add 1 units of 125 MW Shield
073        $retvar = $CurrentSSP -> add -82 units of Quantum Tubes
074       end
075      end
076      
077      $FoodArray[$i] = $z
078      $i = $i + 1
079     end
080     
081   * Repeat cycle every 60 seconds
082 @   = wait 60000 ms
083    end
084   * For debugging
085   *write to player logbook $nSSPs
086   end
087 @ = [THIS] -> call script 'libfdn.EndCurrentInstance' :  Race=Race 2  Sector=Akeela's Beacon  Ship Type=Xenon H
088   return null

This works, I have tested it extensively. the key is to tie the detection to the rate limiting resource, and set the threshold such that it is too much to be feasible to tranport. In this case it is equivalent to DROP in 19 FULL Manta-loads of Meatsteaks. And if you are someone who is prone to cheating, you can just make the script check every 5 seconds instead of every 60, making it impossible to load the tranports fast enough to trick the script.

For the love of god, I hope I start seeing some real economy fix mods out there now.

TW
Last edited by easternblocrobotcowboy on Sun, 21. Mar 04, 01:52, edited 1 time in total.

User avatar
giskard
Posts: 5230
Joined: Wed, 6. Nov 02, 20:31
xr

Post by giskard » Sat, 20. Mar 04, 21:11

Actually i think Burak (sorry i forget the spelling) sussed out the real issues involved and said that the pricing and cycles where all linked, so fixing one factory by halfing its production also halfed all the other factories products too.

Not looked into my self but he did it via the T files i believe. Not sure if a script works better. Your solution may actually be the first workable solution I have seen. I certainly hope so. :)

Giskard
This signature has been stolen by the well known Teladi Signature Thief X Siggy.

easternblocrobotcowboy
Posts: 120
Joined: Sun, 15. Feb 04, 23:21
x2

Post by easternblocrobotcowboy » Sat, 20. Mar 04, 21:17

I GUARANTEE you that this script works properly. I have been playing (actual playing, not just play-testing) with it for 3 days now.

I am fully aware of the auto-balancing issies. they only come into play if you adjust the ware values. Since this script does not adjust any ware values it completely bypasses the auto-balance code. It actually leaves the factories primary production alone an untouched and 'layers' another invisible manually scripted production/resource regeneration cycle on top of it, built to begin upon detection of a new factory production cycle.

Of course if you build the fab, command the tranports, and then just leave it alone, all you will see is XXX resources in, YYY products out, and that you MUST have all primary resources present and adequate to get any production at all.

TW

NeverSnake
Posts: 5159
Joined: Thu, 9. Oct 03, 20:44
x3tc

Post by NeverSnake » Sat, 20. Mar 04, 21:58

Having a script rebalancing all the factories all the time would be a bit CPU intensive though wouldn't it?
"There's an old story about the person who wished his computer were as easy to use as his telephone. That wish has come true, since I no longer know how to use my telephone" — Bjarne Stroustrup

easternblocrobotcowboy
Posts: 120
Joined: Sun, 15. Feb 04, 23:21
x2

Post by easternblocrobotcowboy » Sat, 20. Mar 04, 23:17

Each script would be exactly as demanding as one tranport running FATE auto-buy/sell, or get.ware which also loops. What you must remember is that the game is running on the order of 4000 scripts all the time before yuo add even your first one. Every TS you see has an egosoft script governing its behavior. Adding even 100 more scripts is a negligible addition.

This particular script only acts through a simple routine (coding wise) once every 60 seconds, so as scripts go it is not very demanding at all.

Personally, I only have 4 factories scripted at the moment, Computer Fabs, Microchip Fabs, Quantum Tube Fabs, and now 125 Mw Shield Fabs. I leave all the low-end fabs alone and only script the high end ones, because that was the primary complaint about the economy: there were no good investments for those with millions and millions of credits. I also dont script a factory untill I am in the market for one, and then I logically design the fab, calculate out the profit level, script it, and then use tFactories to make it have a 10 to 20-<game>hour pay-off time (SPP pay off time: about 3-5 hours) generally putting the cost of the factory somewhere around 5 million credits.

For my military Fabs like the 125 MW one I feel the profit should be a lot slower. I mean who makes more money? Intel or Lockheed Martin?
I am going to re-script my 125 Mw Fab so the resource regeneration is a little more unique the example is a bit of a rush job; I will probably script it to use Nividium as a secondary resource as well. In the end I will adjust the price to make it start earning a profit when it has built 8 125 mW shields. (about 26 game hours). Thus if you are going to buy 7 or less, it is cheaper just to buy the shields, but if you are outfitting a fleet, the factory is the way to go. (I plan on obliterating those 4 khaak sectors you get after the campaign.)

Anyway, for the exact mathematical models of the fabs you can check out Burianek's econ post.

TW

User avatar
giskard
Posts: 5230
Joined: Wed, 6. Nov 02, 20:31
xr

Post by giskard » Sun, 21. Mar 04, 18:28

Yes CPU time is something we must consider.
There are ways to help reduce it such as timing your script to run only once every few seconds etc. Which may or may not work with the factory script above.

Giskard
This signature has been stolen by the well known Teladi Signature Thief X Siggy.

easternblocrobotcowboy
Posts: 120
Joined: Sun, 15. Feb 04, 23:21
x2

Post by easternblocrobotcowboy » Mon, 22. Mar 04, 00:04

The scripts above only check once every 60 seconds, which is a negligible strain on processor power. Like I said, the game runs over 4000 scripts before you do anythign at all. Just hit page down in the script editor to see for yourself.

Anyway, if yuo are hell-bent on playnig the egosoft economy, fine be my guest. Go on telling yourself changes cant be made. But realize that will be a lie. For those who want more options besides SPPs, it is completely possible. I currently now have 8 factory types scripted and adjusted to be profitable options including the comp fabs, chip plants, quantum tube fabs, cahoona bakeries, 125 Mw fabs, 25 mw fabs, b-hept fabs, and b-ppc fabs with no problems or detectable slowdown as compared with my unscripted game (which I played the campaign on). Plus Im running the Khaak Second Invasion script. And I run an athalon 1.4.

TW

easternblocrobotcowboy
Posts: 120
Joined: Sun, 15. Feb 04, 23:21
x2

Post by easternblocrobotcowboy » Mon, 22. Mar 04, 00:23

BTW does anyone know how to actually write their own initialization of a script? I have tried as well as tried changing the titles with no luck. If someone can, I would like to send you my scripts and ask if you can give them appropriate titles.

(eg: currently my computer fab fixing script is called 'init.efefdn.mod.crystalfreeSPPs.xml'

once they are properly retitled I would feel comfortable posting them on xscripting and sharing them with everybody.

TW

User avatar
Burianek
Posts: 2981
Joined: Mon, 29. Dec 03, 03:29
x3tc

Re: successful script that fixes factories - I told you so

Post by Burianek » Mon, 22. Mar 04, 16:41

easternblocrobotcowboy wrote:For the love of god, I hope I start seeing some real economy fix mods out there now.

TW
If you'd like some help with "doing the math" behind using your scripts to rebalance things, let me know. I've spent a lot of time on this and have some ideas that might be helpful in making sure you don't make things too powerful, or too weak. This is a very good idea that, when implemented successfully, has the potential to be an extremely clever, viable, economy fix. Once the math is done, it's only a matter of coding it up.
The biggest thing to think about is whether or not you want to keep the 1:1 ratio of support fab to high end fab. There's something appealing to making ultra high end fabs require half the rate of resources as others. Makes it possible to support 2 high end fabs with one chain instead of just one. Not sure if there's a step in between though. Would you make medium end factories use 75% of the resources? Or make extra products per cycle? Something to think about. Like I said, I'd be very happy to assist.
"Nature's first green is gold" . . . stay golden.

easternblocrobotcowboy
Posts: 120
Joined: Sun, 15. Feb 04, 23:21
x2

Post by easternblocrobotcowboy » Mon, 22. Mar 04, 16:59

Im open to suggestions and collaborative ideas on fabs. If several peopl eoutline a mathematical model for fab idea, I could code it though once again, it will be inside a gutted shell of another script for the reasons I mentioned above.

As for resource utilization, I havnt quite balanced it yet. that cant really be done until the script is balanced for profitability, becasue I have noticed something that x2 scripting time is not normal time. it is sort of variable with an average of 1.6 sec scripting time = 1 sec real time. So even in my scripts, I have had to go back inside them after I have made them to speed up the cycles to bring them to 2x or 3x profitability of an SPP. once they are balanced there, it is pretty easy to balance resources to set whatever resource utilization you want.

I have been shooting for 1:1 but I tend to err on the side of high end fabs being resource hungry, so they are definitely 'top of the pyramid' fabs. with the exception of cahoona bakeries. I am sick and tired of needeing 1-2 damn bakeries for every fab. My sectors get filled up with a zillion bakeries. its really annoying though they look cool all lined up in a row in space.

ANyone who wants to suggest a math model for a redux of one of the factories go right ahead, so the forun can give their input.

TW

Return to “X²: The Threat - Scripts and Modding”