Author Topic: A couple of bugs in governor, and my fixes  (Read 1036 times)

AnimateDream

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
    • StephenLujan.com
A couple of bugs in governor, and my fixes
« on: February 28, 2013, 09:44:44 PM »
The checkWorkers() and checkTrade() methods are removing structures every time.
Where they each call
Code: [Select]
uint slots = pl.getStructureCount(), structs = list.getCount();it should replaced with
Code: [Select]
uint slots = pl.getMaxStructureCount(), structs = list.getCount();otherwise those two values are identical.
« Last Edit: February 28, 2013, 09:50:39 PM by AnimateDream »

AnimateDream

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
    • StephenLujan.com
Re: A couple of bugs in governor, and my fixes
« Reply #1 on: February 28, 2013, 11:48:39 PM »
Ok I just decided to refactor them a bit too. This is bit easier to follow in my opinion.

EDIT: Disregard anything good you've ever heard about me. I posted broken code below before. Sorry. The code below is good now.
Code: [Select]
/*
 * Builds 1 of the input structure, tearing down old buildings if necessary for space
 */
bool buildRequired(Planet@ pl, const subSystemDef@ build)
{
  PlanetStructureList list;
  list.prepare(pl);
  uint slots = pl.getMaxStructureCount(), structs = list.getCount();
 
  // if we aren't full just build it and return
  if(structs < slots)
  {
    pl.buildStructure(build);
    return true;
  }

  // If we're full find the first thing we can replace and replace it.
  for(uint i = 0; i < list.getCount(); i++)
  {
    const subSystemDef@ def = list.getStructure(i).type;

    if(def is port || def is yard || def is city || def is capitol || def is GC || list.getCount(def) <= 1)
      continue;
    pl.removeStructure(i);
    pl.buildStructure(build);
    return true;
  }
  // All slots were filled with unreplaceables
  return false;
}

/*
 * This function checks the worker levels of a planet
 * and adjusts the number of cities as needed
 */
bool checkWorkers(Planet@ pl)
{
  Object@ obj = pl;
  State@ workers = obj.getState(strWorkers);
  float wmax = pl.getMaxPopulation();

  // leave now if a city is not needed
  if(wmax - workers.required >= 12.f * mil)
    return false;
   
  // Otherwise try to get a city
  return buildRequired(pl, city);
}

/*
 * This function checks the trade amount of a planet
 * and adjusts the number of ports as needed
 */
bool checkTrade(Planet@ pl)
{
  Object@ obj = pl;
  Empire@ emp = obj.getOwner();
  State@ trade = obj.getState(strTrade);
  State@ govTrade = obj.getState(strGovTrade);

  bool maxed = false;
  if(gameTime - govTrade.val > 5.f || gameTime <= 30) {
    //Work off an average of the last update and this one
    float req = (trade.inCargo + govTrade.max) / 2;

    //Error checking incase it hits halfway through a planet update
    if(req > trade.max * 10)
      return false;
     
    if(req >= trade.max)
      maxed = true;
     
    govTrade.val = gameTime;
    govTrade.max = req;
  }

  // Only continues if the planet is using its maximum trade capability for the last 10 seconds.
  // This will not be completely accurate as if a planet is importing the rate will be maxed
  // Need to find a way around this.
  if(!maxed)
    return false;

  //try to get a port
  return buildRequired(pl, port);
}
« Last Edit: March 02, 2013, 03:06:03 AM by AnimateDream »

AnimateDream

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
    • StephenLujan.com
Re: A couple of bugs in governor, and my fixes
« Reply #2 on: March 23, 2013, 12:21:30 PM »
So its been a few weeks and there's not a single response to the bugs? I understand XTRMNTR2K and Azalrion are working on a GA 2.0 that may totally redo the way governors work, but that doesn't mean the version 1.x branch couldn't benefit immediately or shouldn't be maintained at all.

Is there a version control repository like github? That way I could just send a pull request and they could accept my changes with a single button click. I wouldn't mind making an occasional contribution to this awesome mod.

Azalrion

  • Moderator
  • Delusional
  • *
  • Posts: 1325
  • Karma: +147/-1
  • Memory Murderer
    • View Profile
Re: A couple of bugs in governor, and my fixes
« Reply #3 on: March 23, 2013, 02:16:50 PM »
Honestly its more along the lines of too busy with work and other things to work on modding for both myself and XT at the moment. Thanks for noticing the bug missed it every time it will be added to the next patch but no idea when that will be depends when I get time to sit down and double check all the fixes and XT gets time to do a release.
GA - Mod Team
GA Forums

tcelvis

  • Newbie
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: A couple of bugs in governor, and my fixes
« Reply #4 on: March 23, 2013, 11:52:03 PM »
So how about his other question?  Is there a version control repository for GA that we can offer code to?  I am recently working on improving AI in Galactic Armory and it would be an honor if it can be merged into official release.

Azalrion

  • Moderator
  • Delusional
  • *
  • Posts: 1325
  • Karma: +147/-1
  • Memory Murderer
    • View Profile
Re: A couple of bugs in governor, and my fixes
« Reply #5 on: March 25, 2013, 06:05:13 PM »
Edit: You can use: https://github.com/Azalrion/galactic-armory/tree/maintenance

1.9.x development goes in the maintenance branch but i'd prefer if you add your own named branches so I can pull into maint for testing before doing anything else with it. Just to note this doesnt mean changes will make it in a release especially since 2.0 is a major overhaul and will be almost a complete re-write so its unlikely anything but bug fixes will as i just dont have time to test new features for 1.9.
« Last Edit: March 26, 2013, 05:29:47 AM by Azalrion »
GA - Mod Team
GA Forums

AnimateDream

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
    • StephenLujan.com
Re: A couple of bugs in governor, and my fixes
« Reply #6 on: March 28, 2013, 12:52:28 AM »
I didn't realize you already had an svn on google code or I would have made up a patch file. Either way github makes contributions so much easier for both contributors and maintainers, hopefully this will spur more programmers out of hiding. Thank you so much for putting it up. I've got my own github fork synced up to my computer and made my first pull request out of the bug fix I posted. Now I have no barrier to future contributions so let me know if you want help with  some 2.0 features.

tcelvis I would love to see your changes if you wouldn't mind forking on github too.
« Last Edit: March 28, 2013, 01:17:08 AM by AnimateDream »

Azalrion

  • Moderator
  • Delusional
  • *
  • Posts: 1325
  • Karma: +147/-1
  • Memory Murderer
    • View Profile
Re: A couple of bugs in governor, and my fixes
« Reply #7 on: March 28, 2013, 06:25:09 AM »
Ah it was more my private repo for playing about with 2.0 stuff, trying to add changes for 1.9 in there just wouldn't work as a lot of the stuff is experimental.

Accepted the pull request so thanks for that and I'll get back to you on the 2.0 stuff just got to do some checking.
GA - Mod Team
GA Forums