View unanswered posts | View active topics It is currently Sat Apr 18, 2026 2:33 am



Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
 resetting static array 
Author Message
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post resetting static array
Can you reset a static array in a script, if your array reaches it's limit but you know that there are going to be additional variables that need to be added to the array?

I am working on a script that gets the initial values of a port as I am doing world trade or a world SSM script, and I don't want to set the array too large initially because when I am debugging the script I don't want to have to sit through too many variables being output - and also if there are too many variables it will take up all your scrollback buffer and you can't go back up and check the triggers and other variables from the script.

So I was thinking if this is possible, you set your dynamic array at like 100 or 500 or something. You keep a counter of the port visits. Then you do a routine to check the array size against the counter. When the array reaches the same size as the counter, I would reset the array adding like 100 or 500 to it's size.

Another question, if you do this, do you lose all the data that was originally in the array?


Mon Aug 24, 2009 10:50 pm
Profile
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: resetting static array
Yes. If you:
setArray $array 0

You will delete the array. If you:

setArray $array $newsize

It will resize the old array to $newsize.

If the array reaches the old limit and you need more values then I suggest a dynamic array. It'll be a little lower in execution, but a lot faster than having to constantly resize the array.

if you are setting values of a port into an array, well, you don't need to. That information is stored in the twx DB. But for some reason should you feel the need, well, use an array of SECTORS instead.

setArray $visited SECTORS

So that the index of each array is the sector being referenced. Will make your life a lot easier than trying to append to the end of an array over and over, stacks can be messy like that. Naturally you can't output something like that as a watchpoint, but it's not really necessary either. An $sv will be a bit floody tho.

And yes, if you resize the array I believe you lose all data. I could be wrong tho, ask EP to verify.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Tue Aug 25, 2009 4:42 am
Profile ICQ WWW
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: resetting static array
All true. There is no function to alter the size of a static array, and if you recreate it using setArray, it is zeroed in the process.

Also, as Sing said... you may be duplicating what is already in the TWX database. The port will need to display it's values, either by porting or by a CR report, and then those values can be pulled from the database, using PORT.EQUIP[sector number] for example. Of course, you may be doing something where you do need to save them to an array, but use the DB whenever possible.

+EP+

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Tue Aug 25, 2009 7:43 am
Profile WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: resetting static array
Thanks Singularity and +EP+ knowing the answer to this question is helpful. I didn't even think about using the DB to get the values, that will make what I am trying to do much easier if it saves the values of the product at their max. Of course I will still have to keep track of the sector numbers of the ports I have visited, and step through an array or file of these sector numbers so that I can avoid duplicating the sector numbers as I am out trading or it will put multiple instances of the same port number in the array or file I am using to keep track of visited ports.


Wed Aug 26, 2009 9:46 pm
Profile
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: resetting static array
Quote:
I didn't even think about using the DB to get the values, that will make what I am trying to do much easier if it saves the values of the product at their max.


It saves the last known values, ie: the percentage and the amount. From that you can do a little algebra and get the total max, minus fractional percentage precision.

It gets these values from a cr port report or a CIM.

Quote:
Of course I will still have to keep track of the sector numbers of the ports I have visited, and step through an array or file of these sector numbers so that I can avoid duplicating the sector numbers as I am out trading or it will put multiple instances of the same port number in the array or file I am using to keep track of visited ports.


You might not need to, depending on what you're planning. Run a CIM and use PORT.EXISTS. If it shows up as a port that exists then you've been there. If you don't want to duplicate traded ports then set a threshold that would occur during trading as the cutoff. Ie: If eq % is less than 40%, ignore it.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Thu Aug 27, 2009 2:16 am
Profile ICQ WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: resetting static array
Thanks Sing, hadn't thought of that. What I am trying to do is to use scripts to get the product totals from every port I visited, then find the good port pairs by MCIC from the +EP+ haggle script, then do the math and figure up how much I need to upgrade each product on that port to keep them equal for trade port pairs or to get the equipment to a certain level for Red scripts, then go out and upgrade these ports using a no alignment gain upgrade script.

I was going to be running this script while running a world trade script or a world SSM script, so I would be unable to do the no alignment upgrade at the time. I am sure that the World Trade and world SSM scripts are quite complicated, so it would probably be hard to figure out where to put in the gosub command to keep from breaking the script.

I don't know that much algebra so not sure how I would get the total max minus fractional percentage precision, so I was just going to run a script as I was out trading that got the totals on the first trade at the port and write the sector number and the pertinent port info into a text file - after checking an array to make sure I hadn't already visited that port that day.

Of course I could also just do a script that did a computer port report after the ports had regenerated, and get the values that way.


Thu Aug 27, 2009 3:30 am
Profile
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: resetting static array
Quote:
Thanks Sing, hadn't thought of that. What I am trying to do is to use scripts to get the product totals from every port I visited, then find the good port pairs by MCIC from the +EP+ haggle script, then do the math and figure up how much I need to upgrade each product on that port to keep them equal for trade port pairs or to get the equipment to a certain level for Red scripts, then go out and upgrade these ports using a no alignment gain upgrade script.


Start with a CIM. Go thru 11 to SECTORS. If the port exists and buys (or sells) eq, check for EP's MCIC parm. If it's there and meets the required levels, then do the math. Max = ((1 / Percentage) * Current Port level) works for any percentage greater than 0. If it's 0, wait for it to be 1%. Easiest way to do that is just to ignore anything less than 0, or if it's 0 use 1 and carry enough extra padding for an extra percent or 2 upgrade. The right noexp upgrade macro will be safe in this regard.

For red scripts you probably don't need the product to be equal or big as you're stealing and selling and stealing and selling you end up using the same X amount of product over and over. If you run SDT it's best to upgrade it over time up to like 5k, there's no reason to waste turns going to that port any earlier, and no reason to invest money before you have to. The obvious exception there being something like an RTR after a big buydown, but in that case you're just upgrading for the buydown so maxing the port makes the most sense.

Of course for port pairs that's a different story. You basically have to start with a "source" port and search adjs for a "pair" then upgrade the lower one.

For noexp upgrades all you have to do is a little at a time. Just enough for the exp to round down. If you get no exp, you'll get no alignment either.

Quote:
I was going to be running this script while running a world trade script or a world SSM script, so I would be unable to do the no alignment upgrade at the time. I am sure that the World Trade and world SSM scripts are quite complicated, so it would probably be hard to figure out where to put in the gosub command to keep from breaking the script.


Keep in mind that if you upgrade an XXB, the buying port doesn't automatically upgrade. Buyers take the remainder of a port decay cycle to reach their new peak. That could be a day, maybe more if the port regen is crap. Sellers upgrade automatically.

The way xide's world trade stuff works... eh, you could do it if you wanted to sort thru the mess of includes. IMO it's easier to just write your own, and put the upgrades in as needed. You don't need to upgrade for world SSM (or wsst) tho, so you'd have to be planning that for the next phase. If that's the case you might just want to do it afterwards since selecting a good port location will be more important than MCIC.

Quote:
I don't know that much algebra so not sure how I would get the total max minus fractional percentage precision, so I was just going to run a script as I was out trading that got the totals on the first trade at the port and write the sector number and the pertinent port info into a text file - after checking an array to make sure I hadn't already visited that port that day.


Percentage = Current / Total

Right?

You have the current and the percentage, solve for total.

ie:
Percentage * Total = Current

divide by Percentage for:
Total = Current / Percentage

Which is the same as:
Total = (Current * 1/Percentage)

Done and done. Works for all percentages greater than 0, as obviously you can't divide by 0.

Quote:
Of course I could also just do a script that did a computer port report after the ports had regenerated, and get the values that way.


You'll need to wait for the port to reach 1% unless you want to include a fudge factor. EP figured out a way to get fractional percents, or so I'm told... ;) Probably has to do with the port timestamp and the regen rate, if I had to make a wild guess.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Thu Aug 27, 2009 4:31 am
Profile ICQ WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: resetting static array
Sing, thanks for the math lesson and the other info, was very informative. Was wondering if you could elaborate more on the part about selecting a good port location being more important than MCIC? I know MCIC would be very important as far as making the most money on the sell part of it, so in what way do you mean "selecting a good port location"? I know that question probably belongs in the TW school forum or something but since we're already here.

Ya, that +EP+ is a sneaky one alright, figures out all the good stuff. :wink:


Thu Aug 27, 2009 5:21 am
Profile
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: resetting static array
Quote:
Sing, thanks for the math lesson and the other info, was very informative. Was wondering if you could elaborate more on the part about selecting a good port location being more important than MCIC? I know MCIC would be very important as far as making the most money on the sell part of it, so in what way do you mean "selecting a good port location"? I know that question probably belongs in the TW school forum or something but since we're already here.


Upgrading a port in the middle of the universe isn't going to work if you have an enemy to contend with. Unlims are tricky in that arena since grid is so fluid it almost makes it worthless to upgrade anything you can't secure. Hiding ports in a turns game... eh, a little different.

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Thu Aug 27, 2009 5:46 am
Profile ICQ WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: resetting static array
Sing, just noticed something in your earlier post. You said check the sector params for +EP+'s MCIC, what is the name this is written under? Does the haggle.ts script he wrote for 2_WorldTrade to use write this param to the sectors? Or is it just his .cts haggle script that writes these params to the sector?


Thu Aug 27, 2009 6:44 am
Profile
Veteran Op
User avatar

Joined: Thu Jun 02, 2005 2:00 am
Posts: 5558
Location: USA
Unread post Re: resetting static array
EP's haggle script writes certain sector parms to the DB as it goes, including MCIC. Ask him for the list, I'm sure he has it. Maybe he'll post it here? :)

_________________
May the unholy fires of corbomite ignite deep within the depths of your soul...

1. TWGS server @ twgs.navhaz.com
2. The NavHaz Junction - Tradewars 2002 Scripts, Resources and Downloads
3. Open IRC chat @ irc.freenode.net:6667 #twchan
4. Parrothead wrote: Jesus wouldn't Subspace Crawl.

*** SG memorial donations via paypal to: dpocky68@booinc.com
Image


Thu Aug 27, 2009 7:22 am
Profile ICQ WWW
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: resetting static array
Haha, there actually is a trick to find the exact amount a port has been upgraded, but the caveat is that you can't do it from a CIM. I actually blogged about it once upon a time, so I've disclosed it before. The funny part was that I had spent so much time improving the accuracy mathematically (rember that TWX didn't even do decimals back when I started), and this trick doesn't require any of it. But since I know you guys want to have the same AHAH moment that I had, I'll give you a hint instead of just blurting it out.

Only a red can determine the exact amount that a port has been upgraded.

Regards,
+EP+

P.S. I'll post the params tonight. They're supposed to be public knowledge, but I've probably done a poor job disclosing them. Also, I introduced the listSectorParameters command so that there could be no hidden params anymore.

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Thu Aug 27, 2009 9:35 am
Profile WWW
Ensign

Joined: Wed Nov 06, 2002 3:00 am
Posts: 270
Unread post Re: resetting static array
After looking at haggle.ts it appears it doesn't write the MCIC params to the sector. Am I wrong?


Thu Aug 27, 2009 10:18 pm
Profile
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: resetting static array
No, haggle.ts is strictly to let some pack 2 routines use my haggle.

The parameters that are set by my haggle are as follows:
$product & "-" : This is LowMCIC
$product & "+" : This is HighMCIC
$product & "L" : This is LowProductivity
$product & "H" : This is HighProductivity

Brief explanations...
$product will be FUEL, ORGANICS, or EQUIPMENT. So the params for equipment would be:
EQUIPMENT-
EQUIPMENT+
EQUIPMENTL
EQUIPMENTH

Sorry for the bad param names, but I'm working with a 10 character limit for the parameter name, and I wanted it to be as autonomous as possible.

LowMCIC refers to the MCIC possibility closest to zero, which is the poorest possible value. Remember that there are negative MCICs too, so if the range is -40 to -38, LowMCIC would be -38. When you are evaluating ports, use this value, since it is the worst case scenario.

Productivity is defined in TEdit. This is basically the number of units the port buys or sells when at 100%, divided by 10. So a maxed product with 32,760 units has a productivity of 3,276.

I'll try and post a script shortly that shows how to use those params to locate a good port pair.

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Thu Aug 27, 2009 10:44 pm
Profile WWW
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post Re: resetting static array
Here is an example of how to use the sector params from my haggle to locate the single best port pair for SST / SDT. You would certainly want to expand upon this to make it really useful, but I leave that exercise to the reader.

It's a rather complex script, but feel free to ask for clarification.
Code:
# modify this based on your sst / sdt ship's xport range
setVar $xportRange 7
# now sort the known MCICs into a 2-dimensional array, where dim 1 = MCIC value,
# and dim 2 is the list of sectors at a given MCIC value
setVar $i 1
while ($i <= SECTORS)
   getSectorParameter $i "EQUIPMENT-" $value
   if ($value <> "")
      if ($value < 0)
         # so if the value was -65, we'll use $mcic[-65] like a var to track how many -65s we've found
         # in other words, the size of the second dimension of the $mcic[-65] array
         add $mcic[$value] 1
         # if we've just found the 4th -65, then this next line will add its sector # at $mcic[-65][4]
         setVar $mcic[$value][$mcic[$value]] $i
         # and finally, so we don't have to look it up again later...
         setVar $equipMCIC[$i] $value
      end
   end
   add $i 1
end
# clear any internal voids
clearAllAvoids
setVar $a "-65"
while ($a <> "-39")
   setVar $b 1
   while ($b <= $mcic[$a])
      setVar $testSector $mcic[$a][$b]
      # Now let's see where the best port is within xport range
      getNearestWarps $warps $testSector
      setVar $i 2
      while ($i <= $warps)
         setVar $thisWarp $warps[$i]
         setVar $thisMCIC $equipMCIC[$thisWarp]
         if (($thisMCIC + $a) < $bestMCICs)
            getDistance $distance $testSector $thisWarp
            if ($distance <= $xportRange)
               setVar $bestMCICs ($thisMCIC + $a)
               setVar $bestPair[1] $testSector
               setVar $bestPair[2] $thisWarp
               setVar $bestDistance $distance
            end
         end
         add $i 1
      end
      add $b 1
   end
   add $a 1
end
echo "*Best Pair: " $bestPair[1] " (" $equipMCIC[$bestPair[1]] ") - " $bestPair[2] " (" $equipMCIC[$bestPair[2]] "), Distance = " $bestDistance "*"

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Thu Aug 27, 2009 11:30 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 17 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by wSTSoftware.