Author Topic: planet.as function question  (Read 824 times)

ibanix

  • Newbie
  • *
  • Posts: 30
  • Karma: +0/-0
    • View Profile
planet.as function question
« on: March 29, 2013, 11:29:52 PM »
I don't understand the reason for the freeCargoSpace and state.inCargo variables used here. I thought state.val and state.max were the current and maximum values for the state (and therefore, the resource involved). This is on the planet so it isn't cargo space on a ship. What are those variables for?

Code: [Select]
float getResourceWeight(State@ state, float freeCargoSpace, float tradeToPct) {
if(abs(state.max) < 0.01f)
return 0.f;
float pct = (state.val + state.inCargo) / (state.max + state.inCargo + freeCargoSpace);
if(pct > 0.5f)
return (1.f/tradeToPct) * (pct - tradeToPct); // Always positive
else if(pct < 0.5f)
return (-1.f/tradeToPct) * (tradeToPct - pct); // Always negative
else
return 0;
}


Thy Reaper

  • BMS Lead Developer
  • BMS Administrator
  • Hopeless
  • *
  • Posts: 3237
  • Karma: +397/-8
    • View Profile
    • Blind Mind Studios
Re: planet.as function question
« Reply #1 on: March 29, 2013, 11:35:43 PM »
Planets can have cargo capacity from structures.

ibanix

  • Newbie
  • *
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: planet.as function question
« Reply #2 on: March 30, 2013, 05:16:07 PM »
But wouldn't that be reflected in the .max attribute? If not, what does .max actually define?

ibanix

  • Newbie
  • *
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: planet.as function question
« Reply #3 on: March 30, 2013, 08:41:16 PM »
I wanted to understand how the .val/.max/.required/.inCargo worked, so I stuck this inside planet.as tick() function:

Code: [Select]
float FoodVal = obj.getState(strFood).val;
float FoodMax = obj.getState(strFood).max;
float FoodReq = obj.getState(strFood).required;
float FoodCargo = obj.getState(strFood).inCargo;

string@ debug_out = f_to_s(FoodVal, 0);
debug_out += " / ";
debug_out += f_to_s(FoodMax,0);
debug_out += " / ";
debug_out += f_to_s(FoodReq,0);
debug_out += " / ";
debug_out += f_to_s(FoodCargo,0);

print(debug_out);

I get results like so:

1520 / 2181 / 0 / 0
1520 / 2181 / 0 / 0
1520 / 2181 / 0 / 0
1898 / 2146 / 0 / 0
1507 / 2181 / 0 / 0
1507 / 2181 / 0 / 0
1507 / 2181 / 0 / 0
1895 / 2146 / 0 / 0
1494 / 2181 / 0 / 0
1494 / 2181 / 0 / 0
1494 / 2181 / 0 / 0
1892 / 2146 / 0 / 0
1481 / 2181 / 0 / 0
1481 / 2181 / 0 / 0
1481 / 2181 / 0 / 0
1889 / 2146 / 0 / 0
1469 / 2181 / 0 / 0
1469 / 2181 / 0 / 0
1469 / 2181 / 0 / 0


by comparison with the planet economy window (default game, no mods), every 4th output - it should be obvious which - are correct, and the others are not.

Why is this so?

ibanix

  • Newbie
  • *
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: planet.as function question
« Reply #4 on: March 30, 2013, 09:29:36 PM »
Ok, I'm an idiot. Those are for the other three AI's homeworlds. DERRRR.  :-[

seronis

  • Distracted
  • ***
  • Posts: 338
  • Karma: +25/-0
    • View Profile
    • Steam Profile Link
Re: planet.as function question
« Reply #5 on: April 03, 2013, 06:35:48 AM »
The 'food' stat also has a flag set somewhere disallowing it to be stored in generalized 'cargo' space.  So probably not the best resource to print out to see how cargo is used.
Any code/mods I post on this site should be considered Public Domain. Borrow it, steal it, shred it into little pieces to your hearts content. I dont require credit but I appreciate bug fixes and suggestions.