[Script] Scrap Ship at HQ v2.02 ** NON-BP version **

The place to discuss scripting and game modifications for X³: Reunion.

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

Jakesnake5
Posts: 2880
Joined: Fri, 17. Feb 06, 04:55
x4

Post by Jakesnake5 »

Actually, Eladan's code doesn't take 'factories' into consideration. Since they are not a ship class, they wouldn't receive the correct value.

However, I can point out that part of the time definition is a bit off, as Eladan used a slightly different bit of math to get a 'close' answer.

Code: Select all

$scraptime = $value * 18 / $classval * 100 / 100
While this will get a 'relatively' close approximation, it is not precise. Try using Euclids FP Math Libs (link a few messages up) and replace the code with:

Code: Select all

$divide = [THIS] -> call script "divide" : number of fpn array=180288, number of fpn array=1000,
$scraptime = [THIS] -> call script "divide" : number of fpn array=$value, number of fpn array=$classval,
$scraptime = [THIS] -> call script "prod" : number 1=$scraptime, number 2=$divide,
$scraptime = [THIS] -> call script "float2int" : fpn array (s,m,e)=$scraptime,
It will calc a very accurate time information.

Also, if you use the FP Libs, you can replace:

Code: Select all

if $relval < 9924
$value = $relval * 216413 / 100 * 100 / 10000
else
$int = $relval / 9923
$deci = $relval - $int * 9923
$num2 = $int * 216413 / 100 * 100 / 10000
$num1 = $deci * 216413 / 100 * 100 / 10000
$value = $num1 + $num2 * 9923
With:

Code: Select all

$Pprod = [THIS] -> call script "divide" : number of fpn array=216413, number of fpn array=10000,
$Pnum = [THIS] -> call script "prod" : number 1=$Pprod, number 2=$relval,
$value = [THIS] -> call script "float2int" : fpn array (sme)=$Pnum,
to increase the value returned from the 'relval'. On something the size of a station, this could be significant, and will affect the time as well.
Perfection is in the hands of God, we bags of dirt can only do the best we can©
[ external image ]
Modders are a source of ideas to help the Game Makers improve what they have made. Cherrish them, for they are the fruit of thy labors.©
eladan
Posts: 7168
Joined: Sat, 7. Jan 06, 16:01
x4

Post by eladan »

Jakesnake5 wrote:Actually, Eladan's code doesn't take 'factories' into consideration. Since they are not a ship class, they wouldn't receive the correct value.
Not quite true - the HQ file doesn't take factories into account, so there isn't a correct value. I actually do have a catch-all value in there, if something doesn't match the classes used.
However, I can point out that part of the time definition is a bit off, as Eladan used a slightly different bit of math to get a 'close' answer.
Indeed - the difficulties of integer maths. I used the 'close enough is good enough' approach as I was messing with the final values anyway.
On something the size of a station, this could be significant, and will affect the time as well.
Assuming that the relval of stations is proportional to the price of the station by the same amount as it is for ships, then the calcs should actually be fairly similar. (And despite what Jake says, it's not that far off the actual values... :P :D) However, if accuracy is important, I'd definitely endorse Jake's suggestion to use euclid's FP libs. And it would also likely help ease concerns with dealing with numbers that cause overflow (a major concern with my script.)
MJALowe
Posts: 461
Joined: Fri, 5. Jan 07, 06:27
x3

Post by MJALowe »

both good ideas close enough probably is good enough...but i might as well be exact if i can

as to the HQ thing...look at the nifty things thread....here is the code in my hq file *grin* mine handles factories *evil grin*

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<headquarters>
  <upgrades>
    <upgrade index="0" typename="SS_DOCK_P_HQ" storage="50000000">
      <blueprints>
        <blueprint typename="SS_SH_A_M4" />
      </blueprints>
      <production>
        <factor class="ship" value="1" />
        <factor class="factory" value="1" />
        <factor class="hq" value="2" />
        <factor class="laser" value="1" />
        <factor class="shield" value="1" />
      </production>
      <repair>
        <factor class="ship" value="2" />
        <factor class="hq" value="2" />
      </repair>
      <reverse>
        <factor class="ship" value="1" />
        <factor class="factory" value="1" />
        <factor class="hq" value="2" />
        <factor class="laser" value="1" />
        <factor class="shield" value="1" />
      </reverse>
    </upgrade>
  </upgrades>
  <resources>
    <!-- Time (uses the SETA upgrade as the typename!) -->
    <resource typename="SS_WARE_TECH231">
      <factor class="m5" value="10000" primary="1" />
      <factor class="m4" value="12500" primary="1" />
      <factor class="m3" value="16666" primary="1" />
      <factor class="gonership" value="16666" primary="1" />
      <factor class="freighter" value="5000" primary="1" />
      <factor class="bigship" value="25000" primary="1" />
      <factor class="factory" value="25000" primary="1" />
      <factor class="hq" value="25000" primary="1" />
      <factor class="laser" value="500" primary="1" />
      <factor class="shield" value="500" primary="1" />
    </resource>
    <!-- Money -->
    <resource typename="SS_WARE_CREDITS">
      <factor value="3" primary="1"/>
    </resource>
    <!-- Energy Cells -->
    <resource typename="SS_WARE_ENERGY">
      <factor value="885" primary="1" />
    </resource>
    <!-- Ore -->
    <resource typename="SS_WARE_ORE">
      <factor value="21250" primary="1" />
    </resource>
    <!-- Silicon -->
    <resource typename="SS_WARE_SILICON">
      <factor value="28333" primary="1" />
    </resource>
    <!-- Nividium -->
    <resource typename="SS_WARE_NIVIDIUM2">
      <factor racemask="khaak" value="170000" primary="1" />
    </resource>
    <!-- Cloth Rimes -->
    <resource typename="SS_WARE_F217">
      <factor value="85000" />
    </resource>
    <!-- Rastar Oil -->
    <resource typename="SS_WARE_F238" >
      <factor value="42500" />
    </resource>
    <!-- Teladianium -->
    <resource typename="SS_WARE_R255">
      <factor value="28333" primary="1" />
    </resource>
    <!-- Crystals -->
    <resource typename="SS_WARE_TECH205">
      <factor value="85000" primary="1" />
    </resource>
    <!-- Quantum Tubes -->
    <resource typename="SS_WARE_TECH206">
      <factor value="85000" />
    </resource>
    <!-- Microchips -->
    <resource typename="SS_WARE_TECH207">
      <factor value="85000" />
    </resource>
    <!-- Computer Components -->
    <resource typename="SS_WARE_TECH208">
      <factor value="85000" />
    </resource>
  </resources>
</headquarters>
MJALowe
Posts: 461
Joined: Fri, 5. Jan 07, 06:27
x3

Post by MJALowe »

Jakesnake5 wrote:

Code: Select all

$scraptime = $value * 18 / $classval * 100 / 100
While this will get a 'relatively' close approximation, it is not precise. Try using Euclids FP Math Libs (link a few messages up) and replace the code with:

Code: Select all

$divide = [THIS] -> call script "divide" : number of fpn array=180288, number of fpn array=1000,
$scraptime = [THIS] -> call script "divide" : number of fpn array=$value, number of fpn array=$classval,
$scraptime = [THIS] -> call script "prod" : number 1=$scraptime, number 2=$divide,
$scraptime = [THIS] -> call script "float2int" : fpn array (s,m,e)=$scraptime,
It will calc a very accurate time information.

Also, if you use the FP Libs, you can replace:

Code: Select all

if $relval < 9924
$value = $relval * 216413 / 100 * 100 / 10000
else
$int = $relval / 9923
$deci = $relval - $int * 9923
$num2 = $int * 216413 / 100 * 100 / 10000
$num1 = $deci * 216413 / 100 * 100 / 10000
$value = $num1 + $num2 * 9923
With:

Code: Select all

$Pprod = [THIS] -> call script "divide" : number of fpn array=216413, number of fpn array=10000,
$Pnum = [THIS] -> call script "prod" : number 1=$Pprod, number 2=$relval,
$value = [THIS] -> call script "float2int" : fpn array (sme)=$Pnum,
to increase the value returned from the 'relval'. On something the size of a station, this could be significant, and will affect the time as well.
obviously im missing something, probably with the float2int....puting these in cashes the game to freeze *grin* atleast as is....more research

edit: well, its not the fpn stuff....its something in my script that is now acting up, i can't think of what cause it was working last night


edit: well ive narrowed it down to this section of code

Code: Select all

$worked = get index of $answer in array $textarray offset= 0 053 1
$current3 =  $idarray [ $worked ]
$ware = $current3 -> get ware type code of object
$relval = get relvalue of $ware

$Pnum = [THIS] -> call script "prod" : number 1=216413, number 2=$relval,
$value = [THIS] -> call script "float2int" : fpn array (s,m,e)=$Pnum,

$classval = 25000

$divide = [THIS] -> call script "divide" : number of fpn array=180288, number of fpn array=1000,
$scraptime = [THIS] -> call script "divide" : number of fpn array=$value, number of fpn array=$classval,
$scraptime = [THIS] -> call script "prod" : number 1=$scraptime, number 2=$divide,
$scraptime = [THIS] -> call script "float2int" : fpn array (s,m,e)=$scraptime,
edit: this is just wierd....

was "-> get ware type code of object" one of the commands that doesnt work right except on references?
MJALowe
Posts: 461
Joined: Fri, 5. Jan 07, 06:27
x3

Post by MJALowe »

well....after much anoying experimentation it seems as if im gona have to "hardcode" the relval and the classval of all the items...

reason....i worked a few times again....but was returning a time in the 1min range....

assuming the math lib isn't messing up itself but just hanging cause of whatever value wound up in relval then ill be able to use it....but this is gona be a REAL pain....it means two more arrays to go with the textarray and the idarray (there is an entry for every ship and factory in there plus an entry for all the nonfactory produced weapons and a list of most standard "upgrade" items - something like 600 entries per array and now its gona be 4 arrays instead of 2....)

ahh well, its still beter than having to manualy set ALL the values

btw, the script im testing with is only to research the BPs....there will be another script for producing them (and there is gona be a research script for each type of item (ship weapon upgrade factory), there will however only be one for producing the items...
eladan
Posts: 7168
Joined: Sat, 7. Jan 06, 16:01
x4

Post by eladan »

MJALowe wrote:edit: well ive narrowed it down to this section of code

Code: Select all

$worked = get index of $answer in array $textarray offset= 0 053 1
$current3 =  $idarray [ $worked ]
$ware = $current3 -> get ware type code of object
$relval = get relvalue of $ware

$Pnum = [THIS] -> call script "prod" : number 1=216413, number 2=$relval,
$value = [THIS] -> call script "float2int" : fpn array (s,m,e)=$Pnum,

$classval = 25000

$divide = [THIS] -> call script "divide" : number of fpn array=180288, number of fpn array=1000,
$scraptime = [THIS] -> call script "divide" : number of fpn array=$value, number of fpn array=$classval,
$scraptime = [THIS] -> call script "prod" : number 1=$scraptime, number 2=$divide,
$scraptime = [THIS] -> call script "float2int" : fpn array (s,m,e)=$scraptime,
edit: this is just wierd....

was "-> get ware type code of object" one of the commands that doesnt work right except on references?
'get ware type...' works on existing objects - pretty sure it won't work on object types. What exactly is idarray an array of?
Jakesnake5
Posts: 2880
Joined: Fri, 17. Feb 06, 04:55
x4

Post by Jakesnake5 »

@MJALowe

I have an external script editor (made by Cool_Sniper, a russian) and can use it to change values on the fly. If you pop me a copy of your scripts, I can find out what exactly is causing the crash. (Specifically, by commenting lines in the EScE, then running the game, until something I un-comment causes the crash)
Perfection is in the hands of God, we bags of dirt can only do the best we can©
[ external image ]
Modders are a source of ideas to help the Game Makers improve what they have made. Cherrish them, for they are the fruit of thy labors.©
MJALowe
Posts: 461
Joined: Fri, 5. Jan 07, 06:27
x3

Post by MJALowe »

id array is an array of all the items (the same values that would be needed for the add ware command)

i think suddenly that i dont need that line of code and its messing up the relval


i think that might be the same one i got....but its been sooo long...and there are a few things it doesn't handle well, atleast the version i got

it doesn't like the new commands (haven't been able to track down an update) and the get index command has to be commented out before it will compile....
MJALowe
Posts: 461
Joined: Fri, 5. Jan 07, 06:27
x3

Post by MJALowe »

all righty then, i seem to have it working....and boy was it a simple fix...here is the working code (i even got the times correct)

right now its fully functional but instead of updating a research time available variable it sends that info (debug mode basically)

Code: Select all

if $sizeofarray == 2
$answer =  $resarray [ 1 ]
$worked = get index of $answer in array $textarray offset= 0 053 1
$ware =  $idarray [ $worked ]
$relval = get relvalue of $ware
$classval = 2500
$class = $ware -> is of class Factory
if $worked >= 1 AND $worked <= 195
$classval = 25000
else
$classval = 2500 
end

$base = [THIS] -> call script "divide" : number of fpn array=649239, number of fpn array=10000,
$base = [THIS] -> call script "prod" : number 1=$base, number 2=$relval,
$scraptime = [THIS] -> call script "prod" : number 1=$base, number 2=60,
$scraptime = [THIS] -> call script "divide" : number of fpn array=$scraptime, number of fpn array=$classval,
$scraptime = [THIS] -> call script "divide" : number of fpn array=$scraptime, number of fpn array=2,
$scraptime = [THIS] -> call script "float2int" : fpn array (s,m,e)=$scraptime,


if $scraptime < 15
$scraptime = 15
end

$starttime =  $restime [ 1 ]
$currtime = playing time

if not $starttime == -1
$time = $currtime - $starttime
$x = $scraptime - $time

$hours = $x / 3600
$temp = $x - $hours * 3600
$hours = $hours + 100
$hours = sprintf: fmt= "%s" , $hours , null , null , null , null
$hours = get substring of $hours offset= 1 length= 2
$mins = $temp / 60
$temp = $temp - $mins * 60
$mins = $mins + 100
$mins = sprintf: fmt= "%s" , $mins , null , null , null , null
$mins = get substring of $mins offset= 1 length= 2
$temp = $temp + 100
$temp = sprintf: fmt= "%s" , $temp , null , null , null , null
$temp = get substring of $temp offset= 1 length= 2
$timeleft = sprintf: fmt= "%s:%s:%s" , $hours , $mins , $temp , null , null

$Title = "BP Manager Message"
$Messagebody = "Research time remaining:  " + $timeleft
$Message = sprintf: pageid= 8117 textid= 400 , $Author , $Title , $Messagebody , null , null
$Hardreturn = sprintf: pageid= 8117 textid= 203 , $Author , $Title , $Messagebody , null , null
$menu = $Message + $Hardreturn
$test = [THIS] -> call script "lib.st.md.message.ask" : pageid OR message string=$menu, textid OR null=null, arg1 OR null=null, arg2 OR null=null, arg3 OR null=null, arg4 OR null=null, arg5 OR null=null,
if $time >= $scraptime
$restime [ 1 ] = -1
append $answer to array $installedfactories
remove element from array $resarray at index 1
set global variable: name= $researchtime value= $restime
set global variable: name= $localinstalledfactories value= $installedfactories
set global variable: name= $researcharray value= $resarray
$Hardreturn = sprintf: pageid= 8117 textid= 203 , $Author , $Title , $Messagebody , null , null
$Author = "IFTSOS Management"
$Title = "BP Manager Message"
$Messagebody = "Installed"
$Message = sprintf: pageid= 8117 textid= 400 , $Author , $Title , $Messagebody , null , null
$menu = $Message
$test = [THIS] -> call script "lib.st.md.message.ask" : pageid OR message string=$menu, textid OR null=null, arg1 OR null=null, arg2 OR null=null, arg3 OR null=null, arg4 OR null=null, arg5 OR null=null,
end

else
$restime [ 1 ] = $currtime
set global variable: name= $researchtime value= $restime
end

end
note: i had to divide scraptime by 2 to get the same time that the pHQ gets....trying to figure out why

edit: the reason its >= 1 and <= 195 is because the 0 id is "blank entry" and the first 195 entries in both the textarray and idarray are factories - i can use this for all but the ships....the ships ill just have to sort in the array before it will work with them, which is no problem being as it doesn't matter if this array is sorted, so long as the text and id are in the same positions (and now so long as they are all in the correct blocks)

question: how many BPs should a player be able to research at the same time?

...current catagories are ships weapons upgrades and factories or should i limit it to one....for production ive decided on 2 ship or factories (or 1 of each) 5 weapons and 10 upgrades
MJALowe
Posts: 461
Joined: Fri, 5. Jan 07, 06:27
x3

Post by MJALowe »

eladan wrote:@MJALowe, I know you're familiar with the hq file - most of the values are directly from there, as follows:

The base figure used is proportional to the relval of the ship. The only empirically worked out value (Dave Toome calculated it) is the constant multiplier to relval. The amount of each resource is given in the hq file as a divisor of this base figure. So:

Base figure: base = 64.9239*relval

Energy cells = base/885
Ore = base/21250
Silicon = base/28333
Nividium = base/170000
Cloth Rimes = base/85000
Rastar Oil = base/42500
Teladianium = base/28333
Crystals = base/85000
Quantum Tubes = base/85000
Microchips = base/85000
Computer Components = base/85000
Credit Cost = base/3

Production time depends on the class of the ship, and is (in seconds)
time = base * 60 / classval

Where classval is
10000 for M5
12500 for M4
16666 for M3
5000 for TS,TP
25000 for M1,M2,M6,M7,TL
16666 for Gonership

I think I've got the values there right - I'll double check to be sure and fix it if they're not.
i think something is wrong with this...not sure about the rest, but if you do the time equation with a relval of 30,000 and a classval of 25,000 you will get 2x the time needed...but if the classval is say 2,500 it will be like 20x the value needed

shouldn't a classval of 2500 there give a time of like 10mins? or does it take longer to make the smaller ships? and having to divide it by two seemed a little silly

(it also might be the time code, but i dont see how, unless yours has errors too...its a direct copy)
eladan
Posts: 7168
Joined: Sat, 7. Jan 06, 16:01
x4

Post by eladan »

MJALowe wrote:i think something is wrong with this...not sure about the rest, but if you do the time equation with a relval of 30,000 and a classval of 25,000 you will get 2x the time needed...but if the classval is say 2,500 it will be like 20x the value needed

shouldn't a classval of 2500 there give a time of like 10mins? or does it take longer to make the smaller ships? and having to divide it by two seemed a little silly

(it also might be the time code, but i dont see how, unless yours has errors too...its a direct copy)
The time equation is correct.

Have you checked the code with a ship? I'm assuming that you're messing with factory classval in the HQ file and getting different results to what you expect? Try with a ship, where you know that my equation works, and can be checked. Also, remember that classval is a divisor - smaller classval means larger time.

From what you're saying, it sounds like factories are supposed to have a classval of 50000. Have you given factories a value of 2 under whichever category you're testing with? (Production/RE?)
MJALowe
Posts: 461
Joined: Fri, 5. Jan 07, 06:27
x3

Post by MJALowe »

doh, that would be the problem....and one that doesn't update with a load of a savegame....bah.....the value under production was 2 (like the hq entry that was already there) atleast now i know what that value does

note reverese engining at the very least can't be changed from changing the hq file, dont know about repairing...production values now...THOSE we can change

Return to “X³: Reunion - Scripts and Modding”