Question about this save file

ok so i was looking through the save file of Prison Architect which is a Indie game and it looked like this:

Version alpha-11
NumCellsX 100
NumCellsY 80
OriginW 100
OriginH 80
TimeIndex 37268.6
ObjectId.next 650667
EnabledElectricity true
EnabledWater true
EnabledFood true
EnabledMisconduct true
EnabledDecay true
ObjectsCentreAligned true
FoodQuantity 3
FoodVariation 3
BioVersions 3
Intake.next 37919.0
Intake.numPrisoners 15
Intake.reqNormal false
BEGIN Cells
BEGIN "0 0" Mat PavingStone Con 0.000000 END
BEGIN "0 1" Con 0.000000 END
BEGIN "0 2" Con 0.000000 END
BEGIN "0 3" Mat PavingStone Con 0.000000 END
BEGIN "0 4" Mat PavingStone Con 0.000000 END
BEGIN "0 5" Mat PavingStone Con 0.000000 END
BEGIN "0 6" Mat PavingStone Con 0.000000 END

...

BEGIN "[i 522]"
Id.i 522
Id.u 629870
Type Prisoner
SubType 3
Pos.x 42.9990
Pos.y 44.4637
Vel.x 0.206368
Vel.y -0.319687
Dest.x 63.8152
Dest.y 47.6036
AttackTimer 1.26525
Shackled true
Cell.i 69
Cell.u 91131
RequiredCellType Solitary
Category MinSec
BoilingPoint 100.000
Gang.id 1
BEGIN Bio
Forname Dan
Surname Gordon
Age 39.0000
BodyType 3
BodyScale 0.781719
HeadType Head3
Traits Fraud
Traits Theft
Traits Narcotics
Traits Petty
Sentence 16
Served 6.53939
Parole 12
SkinColour 0xcb946cff
BEGIN Convictions
Size 4
BEGIN "[i 0]" Crime Blackmail Sentence 13 Plea true Guilty true END
BEGIN "[i 1]" Crime Bribery Sentence 3 Plea true Guilty true END
BEGIN "[i 2]" Crime Bribery Sentence 6 Plea true Guilty true Served true END
BEGIN "[i 3]" Crime Robbery Sentence 8 Plea true Guilty true Served true END
END

theres more but its 27000+ lines long so i wont post it but i was wondering how the game knows to read the values and skip the text? this game is written in C++ i might add, so obviousley they know more about coding than me, i know you could probably write code to ignore the strings but idk can anyone tell me what you think?
I just bought that game. Interesting.
EDIT: I only bought it because it was supported for linux in steam

Most of those are in the format of NAME VALUE, so something with that would just split the file by newline, then split the line by space putting the first value as description of the value, and the second as the actual value and converting it from string to double. Maybe an std::map. Not sure.

For those that are split and have a length greater than 2, would obviously not fit this criteria, so those could be put into another map or something. Or could be caught by the keyword BEGIN. Again not sure.

my best guess would be something like this, where save_file is the string from the file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <sstream>


std::vector<std::string> split(std::string s, char delim=' '){
    std::vector<std::string> v;
    std::stringstream ss(s);
    std::string temp;
    
    while( getline(ss, temp, delim)){
        v.push_back(temp);
    }
    return v;
}

double str2dou(std::string str){
    double i;
    std::stringstream ss(str);
    ss >> i;
    return i;
}

int main(){
    const char *save_file = 
        "NumCellsX 100\n"
        "NumCellsY 80\n"
        "OriginW 100\n"
        "OriginH 80 \n"
        "TimeIndex 37268.6\n"
        "ObjectId.next 650667\n"
        "EnabledElectricity true\n"
        "EnabledWater true\n"
        "EnabledFood true\n"
        "EnabledMisconduct true\n"
        "EnabledDecay true\n"
        "ObjectsCentreAligned true\n"
        "FoodQuantity 3\n"
        "FoodVariation 3\n"
        "BioVersions 3\n"
        "Intake.next 37919.0\n"
        "Intake.numPrisoners 15\n"
        "Intake.reqNormal false\n";
        
    std::vector<std::string> lines = split(save_file, '\n'), line;
    std::map<std::string, std::string> mapsave;
    
    for (auto i:lines){
        line = split(i);
        mapsave[line[0]] = line[1];
    }
    
    std::cout << mapsave.size() << std::endl;
    std::cout << str2dou(mapsave["TimeIndex"]) + 1 << std::endl;
    
}
Last edited on
Seems to me that it's just skipping characters and only reading in numbers, unless keyword BEGIN is found and then it reads in everything after that.
If you are referring to the code snippet: i didnt bother making code to accommodate the BEGIN lines. It was just an example code. If you are referring to the OP, that doesn't make sense. You cannot skip characters and read in the numbers, as they mean nothing. They have to be associated with something to clarify what it is for. The fact that the characters exist probably means they are using it to associate it with the numbers.

You probably will never know either, as there are only two developers to the game i hear. The characters have meaning, but the only ones that know would be the developers.
Last edited on
Topic archived. No new replies allowed.