Author Topic: Save File Generation  (Read 14531 times)

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Save File Generation
« Reply #15 on: November 04, 2011, 04:30:29 pm »
It will actually forcibly delete extra harvesters, just FYI.

The AIP is actually stored in duplicate on each AI Player, because at one point I'd been flirting with the idea of different AIP per AI player (long before even beta of the game).
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Save File Generation
« Reply #16 on: November 04, 2011, 04:31:05 pm »
OK, it turns out that the player data format is less rigid than I thought. I'm updating the player data post with what I have found.

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Save File Generation
« Reply #17 on: November 04, 2011, 04:32:07 pm »
It will actually forcibly delete extra harvesters, just FYI.

Darn it, you're too smart for "cheating" ways.  :P

The AIP is actually stored in duplicate on each AI Player, because at one point I'd been flirting with the idea of different AIP per AI player (long before even beta of the game).

There's the data I need. Time to crank up the AIP to 1 million and see what insanity happens. :D

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Save File Generation
« Reply #18 on: November 04, 2011, 04:36:23 pm »
By the by, two things to watch out for:

1. In the case of the foreground objects in particular, but also I think the player objects might have been converted to this, there are two-character prefix codes before a lot of the top-level values.  So you have 00, 01, 09, etc.  No delimiter between those and the data, it's always exactly two characters so no delimiter is needed.  This lets us include and exclude various groups of data that may or may not be present.  For instance, with data that only applies to ships with cloaking, that whole section would be omitted from the data store of ships without cloaking.  Etc.

2. There's also the FInt stuff that you need to be aware of as how it's being stored in some cases: http://stackoverflow.com/questions/605124/fixed-point-math-in-c  Numbers that would be float types are instead FInt types, which means that you have some bitwise shifting to do to see the "real" number in a human readable format.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Save File Generation
« Reply #19 on: November 04, 2011, 04:44:40 pm »
By the by, two things to watch out for:

1. In the case of the foreground objects in particular, but also I think the player objects might have been converted to this, there are two-character prefix codes before a lot of the top-level values.  So you have 00, 01, 09, etc.  No delimiter between those and the data, it's always exactly two characters so no delimiter is needed.  This lets us include and exclude various groups of data that may or may not be present.  For instance, with data that only applies to ships with cloaking, that whole section would be omitted from the data store of ships without cloaking.  Etc.

Ah, that would explain a lot of what seems to be "header" type values.

2. There's also the FInt stuff that you need to be aware of as how it's being stored in some cases: http://stackoverflow.com/questions/605124/fixed-point-math-in-c  Numbers that would be float types are instead FInt types, which means that you have some bitwise shifting to do to see the "real" number in a human readable format.

Hmm, although that would explain the weird encoding for the metal and crystal values, I have to say, if metal and crystal are integral, why are you using a fixed point number to store them?


Also, I updated the player data info with resource info and "historic statistics" info.

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Save File Generation
« Reply #20 on: November 04, 2011, 04:46:16 pm »
Oh, and thank you so much for taking time out of your heavy work for AVWW to help me out figure out very, VERY, low level stuff that is completely not supported and no sane player should worry about.

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Save File Generation
« Reply #21 on: November 04, 2011, 04:48:18 pm »
No worries at all.

In terms of M&C, those are actually NOT integral.  The reason they aren't integral is that for reasons you may recall with precision and frequency of updates, the inflows and outflows of M&C need to happen once per sim frame, rather than once per second.  That means that your actual outflows and inflows are usually in individual portions less than 1, incremented 20x a second by default.  We just round it for display purposes in the game, because nobody needs to worry about it to that degree during gameplay.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Save File Generation
« Reply #22 on: November 04, 2011, 04:55:28 pm »
No worries at all.

In terms of M&C, those are actually NOT integral.  The reason they aren't integral is that for reasons you may recall with precision and frequency of updates, the inflows and outflows of M&C need to happen once per sim frame, rather than once per second.  That means that your actual outflows and inflows are usually in individual portions less than 1, incremented 20x a second by default.  We just round it for display purposes in the game, because nobody needs to worry about it to that degree during gameplay.

Got it. Now I gotta figure out how many shifts to do and where you are placing the decimal point. Shouldn't be too hard.

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Save File Generation
« Reply #23 on: November 04, 2011, 05:06:49 pm »
Two additional saves from slightly different points in time.

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Save File Generation
« Reply #24 on: November 05, 2011, 12:05:00 am »
Wait a second. Why am I trying to effectively re-implement by hand Game.DoLoadGame and Game.DoSaveGame?


Something like this should be much easier
Code: [Select]
static int Main(string[] args) //SUPPOSED to add a single Mk. I bomber to player 0 at planet 0 at position 0,0 to the given savegame
{
Game game = new Game();
result.DoLoadGame(args[0]);
Planet planet0 = game.planets[0];
ForegroundObject bomber = new ForegroundObject();
bomber.SetUnitDataFromPlayer(0, ForegroundObjectType.Bomber); //Very nice utility method I might add. Setting the unit type by hand apparently requires 3 levels of object nesting.
bomber.SetCurrentPlanet(planet0, false, true);
bomber.SetPosition(0,0);
game.AddFgObject(bomber);
game.DoSaveGame(args[0] + "EDITED.sav");
}

Of course, this is probably wrong. But I hope it gets the idea across. And no disassembling! Only linking!
« Last Edit: November 05, 2011, 12:13:39 am by techsy730 »

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Save File Generation
« Reply #25 on: November 05, 2011, 06:00:53 pm »
Very good idea -- something along those lines would really speed up your process of generating all of this, for sure!
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Nalgas

  • Hero Member
  • *****
  • Posts: 680
Re: Save File Generation
« Reply #26 on: November 05, 2011, 09:14:30 pm »
The AIP is actually stored in duplicate on each AI Player, because at one point I'd been flirting with the idea of different AIP per AI player (long before even beta of the game).

So what happens if they don't match?  Does it use the first one it finds?  Does the last one it reads overwrite whatever happened to be there?  Does it throw an error?  Does the AI explode?  Heh.

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Save File Generation
« Reply #27 on: November 05, 2011, 09:16:54 pm »
The AIP is actually stored in duplicate on each AI Player, because at one point I'd been flirting with the idea of different AIP per AI player (long before even beta of the game).

So what happens if they don't match?  Does it use the first one it finds?  Does the last one it reads overwrite whatever happened to be there?  Does it throw an error?  Does the AI explode?  Heh.

Well, for visual purposes it uses the first one.  And next time the AIP changes, it would set all the others to match it.  But until then, you would see the second AI acting somewhat like it had the higher AIP values.  I say somewhat because some things just use the value from the first player anyhow.  It's pretty much self-correcting.
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Save File Generation
« Reply #28 on: November 07, 2011, 10:10:12 am »
When trying to run the code (with fixes), I ran into an issue. As you might know, I am running Linux. Well, thankfully, Mono on Linux can load managed libraries built in Windows just fine. However, what it can't do is run native (C/C++) libraries built for Windows, and sadly Unity has one of those.

Without access to the code, I can't know for sure, but according to the stack trace, Game's static initializer (or static constructor in C# terms) does try to initialize some of the Unity stuff. The managed Unity stuff then tries to call the native Unity stuff, which of course does not work in Linux, and I get an exception indicating it cannot find a method it needs.

Sigh, I guess I will have to setup an IDE in Wine and try again there.

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Save File Generation
« Reply #29 on: November 07, 2011, 10:23:15 am »
Yeah, the unity engine is all integrated, unfortunately, so it's going to try to init that stuff when you init game...
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!