axx0/Civ2-clone

Can load scenarios

Closed this issue · 14 comments

Can load scenarios
axx0 commented

A .SCN is basically a .SAV file but there are some differences in the binary layout. I'll try to find out what the differences are.

What the game does when you read a .scn:

  • it looks for .gif files (Cities, units, etc.) in the local directory of the scenario. If it can't find those files, it uses gifs from root Civ2.
  • similar procedure with city.txt, rules.txt, game.txt, labels.txt, pedia.txt, advice.txt
  • title.gif (if it exits)
  • scenario intro txt file (if it exits)
  • sound files
  • it loads EVENTS.TXT (if it exists)
  • then it loads the game

If you load a .scn and it loads the events (either from .txt or you make the events in the events editor) and then save the game, the .sav then contains these events. A .scn may contain these events if they were added manually.

(Also - if you load a .scn in the civ2 root and then try to use the scenario editor, it will prompt you to choose a new scenario folder where it will then drop all the files. This is so that you don't mess with original gif/txt files in the root)

So basically we have to:

  1. add reading of events in .sav/.scn files (they may or may not be in there)
  2. make an EVENTS.TXT parser
  3. find out the layout of .scn files
  4. make some sort of ScenarioEvents class which will make these objects from read .sav game data in LoadedGameObjects.cs
  5. enable opening .scn from the main menu

These are existing triggers:
image

and actions which the game uses:
image

Our current file loading capability already has the ability to load the images and txt files from the sav or scn directory and then fall back to root if not found so there is not much to do there.

I would suggest getting the scenario loading and player selection working and worrying about the events as a separate task. Some scenarios such as the rome.scn don't even have events

axx0 commented

Ok I'll try to do scenario loading.
I also implemented events reading to get it out of the way.

axx0 commented

FW and MGE scenarios can be loaded now, but there are some minor issues with certain scenarios.
The loaded map appears blank, there's some issue with visibility or sth else, I'll have to look it up.

I had some trouble with popup boxes which are not listed in Game.txt (they are either read from scenario .txt files or are just custom dialogs, like player selection dialog for scenarios). I added these dialogs manually in Read.PopupBoxes since I don't know how to do a custom dialog.

Also some dialogs are duplicated (like difficulty/gender selection for load game and scenarios). I had to add additional classes for these. This can probably be done more elegantly.

I tried it with the classic rome and ww2 scenarios but it seems it's not reading the data correctly not sure why. I get a null reference error as the values loaded are way outside the expected ranges

axx0 commented

Ww2 and Rome are two early Conflicts in civilization scenarios. The .scn and .sav structure are different than FW and MGE so I'll have to install CiC version of the game on my comp somehow to test it.
Try downloading some fw/mge scenarios from civfanatics or scenario league.

FW and MGE scenarios can be loaded now, but there are some minor issues with certain scenarios. The loaded map appears blank, there's some issue with visibility or sth else, I'll have to look it up.

I found an issue in the visibility code so that may be the cause of what you're seeing here, I've now fixed it in my latest PR

Ww2 and Rome are two early Conflicts in civilization scenarios. The .scn and .sav structure are different than FW and MGE so I'll have to install CiC version of the game on my comp somehow to test it. Try downloading some fw/mge scenarios from civfanatics or scenario league.

I don't think I was using CIC versions of the scenarios, I was using the default ones that come with MPG

axx0 commented

Correct, those two came with the base game.
Edit: ok I checked, hex editor indicates they're from <=2.42 version of the game. I'll try installing that version with wineVdm to test the file structure so we can read those & CIC scenarios. Also it would probably be wise to start adding changes so that we can read TOT sav files. At least TOT structure is well documented.

axx0 commented

MGE and those older two scenarios (ww2 & rome) that came bundled with the base game should now be ok.
I still need to make FW scn/sav files to work.

I opened up both scenarios and they look good.

There seems to be something wrong with the fortress and airbase handling, there are airbases where there shouldn't be in WW2 scn and then a bunch that should be there are missing

axx0 commented

I'll look into it. Also FW scenarios and load games work.
You'll get some obscure errors in some scenarios, mostly additional whitespaces in strings, inconsistencies in Rules file, etc.
So only TOT left, but I'm guessing TOT will require adding more properties to cities, units, ... that don't exist in MGE.

axx0 commented

Fortress and airbase should be fixed now, unlike other tiles they are 48 px high. But it's not a very elegant solution.
Another problem is that fortress should be drawn only after units are drawn.
Same with city names - they are always last thing that is drawn on the map.

I can solve the draw order problem if you're not working on it. I think I've found an elegant solution for it