Re: Savegame editing

From: outis02 <uly_at_...>
Date: Sun, 24 Jan 2010 20:09:26 -0000


This is the updated KoDP savegame template file, for anyone interested. It's now slightly better formatted for viewing. As with before, please ignore all the SetColor functions.

BigEndian(); BitfieldRightToLeft();
enum <byte> BOOL { False, True=0xFF};
local int i = 0;

////////////////////////////////////////////////////////////////STR////////////////////////////////////////////////////////////////
typedef struct {
SetForeColor(cPurple);

        short len;
SetForeColor(cDkPurple);

	local int64 pos = FTell();
	if (len) uchar Str[len];

SetForeColor(cNone);
} STR <read=STRread, write=STRwrite>;

////////////////////////////////////////////////////////////////ARRAY////////////////////////////////////////////////////////////////
typedef struct { local int64 pos = FTell(); SetForeColor(cWhite);

        short ct;
SetForeColor(cDkBlue);

        if (ct) short Int[ct] <format=hex>;
SetForeColor(cNone);
} ARRAY <optimize=false, read=ARRAYread>;

////////////////////////////////////////////////////////////////POP////////////////////////////////////////////////////////////////
typedef struct { short Healthy, Absent, Sick, Wounded; } POP <read=POPread>;

////////////////////////////////////////////////////////////////GODS////////////////////////////////////////////////////////////////

typedef struct {	local int64 pos = FTell();
	long :1,				Ancestors	:1,	ArganArgar:1,	Barntar		:1,	ChalanaArroy:1,	Elmal		:1,	Ernalda	:1,	Eurmal	:1,
		Humakt		:1,	Issaries	:1,	KeroFin		:1,	LhankorMhy:1,	Malia				:1,	MaranGor:1,	Odayla	:1,	Orlanth	:1,
		TarardRiel:1,	Uralda		:1,	Urox			:1,	Vinga			:1,	WindSpirits	:1;
} GODS <read=GODSread>;

////////////////////////////////////////////////////////////////RAID////////////////////////////////////////////////////////////////
typedef struct {

	typedef short CLANIDX <read=CLANIDXread>;
	CLANIDX ClanIdx;
	enum <short> { Cattle=0xFFF7, Battle=0xFFFC } Type <format=hex>;
	typedef short DATE <read=DATEread>;
 	DATE Date;
	enum <short> { disengaged, win_caught, loss_stole=0xFFFF } Result <format=hex>;
} RAID <read=RAIDread>;

////////////////////////////////////////////////////////////////BALANCE////////////////////////////////////////////////////////////////
enum <short> BALANCE { War, Balanced, Peace };

////////////////////////////////////////////////////////////////TRAIT////////////////////////////////////////////////////////////////
typedef struct { local int64 pos = FTell();
// Trait=sure, trait=not sure about the name, _trait=not sure at all

	long AntiAldryami:1, AntiUndead:1,
		_bully:1, //bully? ;war: raid feuding neighbours; diplo: we can survive alone; reorg: the ring needs me; die in rage trifles
		_Courageous:1, //dictatorial, tribute: contest; kallyr: toast; reorg: the ring needs me; die great adventure
		_confident:1, //reorg: I can...; die surprised longevity
		Coward:1, //tribute: avoid contest; trade: fear of ambush; magic: nervous of gods; die lost heart; blackspear search: must give blessing
		_17:1, //forgetful? Illator: reminds...sorry
		critical:1, //die admit enjoy; Einarth: anti-tribe; offend king event?

		crybaby:1, //tribute: can't win contest; die foolish worry; Robarth: this is my fault; farm: "we failed our ppl"
		_22:1, //daring?; Einarth: new isn't bad
		_23:1, //cites lore?
		_24:1,
		Matriarchal:1, mindless:1, //say crazy things, proverbial
		Miserly:1, Patriarchal:1,

		peaceful:1, //peaceful? skull: trade to foster harmony
		Pious:1, Poet:1, pragmatic:1, //tribute: don't threaten; die no trouble
		ProDragonewt:1, Proverbial:1,
		royal:1, //royal? diplo: gift neighbours to form tribe; trade: less trade, go explore (per omens); tribute: if break vow>disastrous; Einarth: hurry!
		Spendthrift:1,

		_scornful:1, //stupid? spiteful? stubborn?;lousy XXX!; tribute: "whatever"
		_42:1, //blackspear search: if bless->all go->forbid
		_43:1, //spiritual?; alliance: worship; magic: build more temple
		told:1, //"told you..."; war: "told you XXX were gonna raid us!"
		_trader:1, //trade: more treasure
		_tribelike:1, //alliance: tribe
		warmonger:1, //die outlive enemy; clan: reorg as war clan; surprise feud event
		_48:1;

//duck attitude? literate? impious? //magic?
} TRAIT <read=TRAITread>;

string TRAITread (TRAIT &t) { string s;

	if (t.AntiAldryami) s += "·xA";	if (t.AntiUndead) s += "·xU";
	if (t._bully) s += "·?bul";			if (t._Courageous) s += "·?crg";
	if (t._confident) s += "·cf";		if (t.Coward) s += "·Cw";
	if (t._17) s += "·17";					if (t.critical) s += "·?crt";

	if (t.crybaby) s += "·?cry";		if (t._22) s += "·22";
	if (t._23) s += "·23";					if (t._24) s += "·24";
	if (t.Matriarchal) s += "·Ma";	if (t.mindless) s += "·Md";
	if (t.Miserly) s += "·Ms";			if (t.Patriarchal) s += "·Pa";

	if (t.peaceful) s += "·Pc";			if (t.Pious) s += "·Pi";
	if (t.Poet) s += "·Pt";					if (t.pragmatic) s += "·Pg";
	if (t.ProDragonewt) s += "·oD";	if (t.Proverbial) s += "·Pv";
	if (t.royal) s += "·R";					if (t.Spendthrift) s += "·Sp";

	if (t._scornful) s += "·?sc";		if (t._42) s += "·42";
	if (t._43) s += "·?tmpl";					if (t.told) s += "·to";
	if (t._trader) s += "·?trd";		if (t._tribelike) s += "·?trb";
	if (t.warmonger) s += "·W";			if (t._48) s += "·48";
	return s = SubStr(s, 1);

}

////////////////////////////////////////////////////////////////LEADER////////////////////////////////////////////////////////////////
typedef struct {
SetBackColor(cDkGray);

        short Age;
SetBackColor(cLtPurple);

	CLANIDX ClanIdx;
	enum <short> { Male=1, Female } Gender;
	short TurnsUnavailable; //gone from tula or other reasons, cannot work
	BOOL Heroic; //GoodNews "heroic level"
	enum <short> { Home, emissary, explorer=13, caravan=16, enthralled=18, Dead } Location; //enthralled by horsespawn
	STR Name;
	char Picture[12];
	GODS Religion;
	short Seat, Sick;
	typedef struct { SetForeColor(cDkBlue); LittleEndian();
		double Animals, Bargaining, Combat, Custom, Leadership, Magic, Plant;
		BigEndian(); } SKILLS <read=SKILLSread>;
	SKILLS Skills;
	enum <short> { Alive, Dead_tmp1, Dead_tmp2, Dead_perm } State;
SetBackColor(cDkRed);
	TRAIT Trait;
SetBackColor(cLtPurple);
	enum <short> { craft=1, farm, heal, hunter, law, magic, noble, trader, trick, war } Type;
	short Wounded, YearsOnRing;

} LEADER <optimize=false, read=LEADERread, write=LEADERwrite>;

////////////////////////////////////////////////////////////////RITUAL////////////////////////////////////////////////////////////////
typedef struct {

	struct { byte Divinition,			Protection,			SummonsOfEvil,	_,									_;					} Ancestors;
	struct { byte _,							_,							_,							_,									_;					} ArganArgar;
	struct { byte Plowsong,				Vigor,					_,							_,									_;					} Barntar;
	struct { byte Curing,					Healing,				Resurrection,		Hope,								Mysteries;	} ChalanaArroy;
	struct { byte Horsefriend,		Shield,					Steadfast,			Sun,								Mysteries;	} Elmal;
	struct { byte BlessChildren,	BlessCrops,			Preserve,				SwineBlessing,			Mysteries;	} Ernalda;
	struct { byte Bless,					Curse,					_,							_,									_;					} Eurmal;
	struct { byte BattleLuck,			Morale,					Oath,						Truesword,					Mysteries;	} Humakt;
	struct { byte Silvertongue,		Market,					SpareGrain,			Trading,						Mysteries;	} Issaries;
	struct { byte MaternalWard,		_,							_,							_,									_;					} KeroFin;
	struct { byte Divination,			ClanLore,				LawSpeaker,			Literacy,						Mysteries;	} LhankorMhy;
	struct { byte Curing,					CausePlague,		Immunity,				_,									_;					} Malia;
	struct { byte BlastEarth,			Earthblood,			_,							_,									_;					} MaranGor;
	struct { byte SureShot,				Tracking,				FriendOfYinkin,	_,									_;					} Odayla;
	struct { byte Lightning,			Rain,						Thunderstone,		Woad,								Mysteries;	} Orlanth;
	struct { byte Watchfulness,		_,							_,							_,									_;					} TarardRiel;
	struct { byte CalfBlessing,		MilkBlessing,		_,							_,									Mysteries;	} Uralda;
	struct { byte Berserker,			SenseChaos,			SmiteChaos,			_,									_;					} Urox;
	struct { byte Fyrdwomen,			Pathfinder,			_,							_,									_;					} Vinga;
	struct { byte _,							ListeningWind,	SeeingWind,			UnderstandingWind,	_;					} WindSpirits;
} RITUAL <optimize=false>;

//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////HEADER////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
struct {

	char Opal[4];
	byte __, __, __, __, __, __, __, __;
	short Omens, //Omens or seed?
		__;
	enum <short> { Short=1, Long } Length;
	DATE Date;
	short Harvest; //1 to 7

} Header;

////////////////////////////////////////////////////////////////VARS////////////////////////////////////////////////////////////////
local int VarIdx = 0;
struct {
SetForeColor(cWhite);

	short ct;
	typedef struct {
		local int Idx = VarIdx++;
SetForeColor(cBlue);
		enum <short> { Leader=0x7FF2, clan, tribe, treasure, leaders=0x7FFA, clans, tribes, treasures, neg=0xFFFF } Class <format=hex>;
SetForeColor(cGray);
		short Value, Short;
		BOOL Bool;
		STR String;
	} VAR <optimize=false, read=VARread>;
	VAR Var[ct];

} Vars;

////////////////////////////////////////////////////////////////MAP////////////////////////////////////////////////////////////////
SetBackColor(cLtYellow);
struct { struct { BOOL Hex[27]; } Row[32]; } Map;

////////////////////////////////////////////////////////////////TREASURES////////////////////////////////////////////////////////////////
SetBackColor(cNone);
struct {

	short Total;
	i = 1;
	typedef struct {
		local int Idx = i++;
		short Qt;
	} ONSALE <optimize=false, read=ONSALEread, write=ONSALEwrite>;
	ONSALE OnSale[120];

} Treasures;

////////////////////////////////////////////////////////////////ARRAYS////////////////////////////////////////////////////////////////
struct { ARRAY Array[12]; } __arrays; //randomized at gamestart, all empty arrays for Tutorial and Opal

////////////////////////////////////////////////////////////////LEADERNAMES////////////////////////////////////////////////////////////////
struct { i = 0;

	short females;
	typedef struct { local int Idx = i++; short Used; } FEMALE <optimize=false, read=FEMALEread>;
	if (females) FEMALE Female[females];
	short males;
	typedef struct { local int Idx = i++ - females; short Used; } MALE <optimize=false, read=MALEread>;
	if (males) MALE Male[males];

} LeaderNames;

////////////////////////////////////////////////////////////////CLANS////////////////////////////////////////////////////////////////
struct {
SetBackColor(cLtBlue);

        short ct;
SetForeColor(cNone);
////////////////////////////////////////////////////////////////CLAN A-L////////////////////////////////////////////////////////////////
        typedef struct {
SetBackColor(cLtBlue);

		struct {
			BOOL __Exists;
SetForeColor(cDkGreen);
			short __xAB; //short, alternates 1/0 from the first clan
SetForeColor(cNone);
			short Barley;
			BOOL BasicClan; //True for the starting 26 human clans
			short Cattle;
			typedef struct { enum <short> { low=1, mid, high, pc=0xCDCD } ChiefDaring, ChiefGenerosity, ChiefGuile, ChiefPiety; } CHIEF <read=CHIEFread>;
			CHIEF Chief;
			typedef struct { short Children[15]; } CHILDREN <read=CHILDRENread>;
			CHILDREN Children;
			enum <short> { Player, Orlanthi, Foreigner } ClanClass; //guessed, affects whether borders are displayed on map
			CLANIDX ClanIdx;
			BALANCE ClanType;
			POP Crafters;
			short Cropland;
			enum <short> { possible, failed, joined } TribeForm;
			STR Description;
			POP Farmers;
			short Food;
			struct { short Ditch:1, Hillfort:1, Ramparts:1, StakePerimeter:1, WoodenStockade:1, StoneWall:1, WatchTower:1, ImprovedStoneWall:1; } Fortifications;
			short Goods;
			GODS GreatTemples;
			short Harvest;
SetForeColor(cDkGreen);
			short __xH; //is short
SetForeColor(cNone);
			short Horses;
			POP Housecarls; //Weaponthanes; //Housecarls
			POP Hunters;
SetForeColor(cDkGreen);
			short __xHI[20]; //short
SetForeColor(cNone);
			short InnerPatrol, KingIdx, KingshipReputation;
SetForeColor(cDkGreen);
			short __xKL1; //short
			byte __xKL2[10]; //byte
SetForeColor(cNone);
			struct { RAID LastRaided, LastRaidedBy; } LastRaids;
SetForeColor(cDkGreen);
			short __xL; //LastPeace? 2=marriage alliance, 3=beaten/warned, decreases over time
		} AtoL;
	

////////////////////////////////////////////////////////////////LEADERS////////////////////////////////////////////////////////////////
struct { SetBackColor(cNone); short ct; if (ct) LEADER Leader[ct]; } Leaders;
////////////////////////////////////////////////////////////////DATA M-R////////////////////////////////////////////////////////////////
struct { SetBackColor(cLtAqua); short MaranGorEarthblood; struct { byte Children, Crops, Diplomacy, Health, Herds, Hunting, Mysteries, Quests, Trade, War, Destiny, Heroism; } Magics; enum <short> { Ancestors=1, ArganArgar, Barntar, ChalanaArroy, Elmal, Ernalda, Eurmal, Humakt, Issaries, KeroFin, LhankorMhy, Malia, MaranGor, Odayla, Orlanth, TarardRiel, Uralda, Urox, Vinga, WindSpirits } MainDeity; struct { short Clan, Farmer, Warrior; } Mood; STR Name; POP Nobles; SetForeColor(cDkGreen); short __xNO; //short SetForeColor(cNone); short OuterPatrol, Pasture, Pigs; struct { short Farmers, Oxen; } Planted; BOOL PlayerHasThralls; STR Plural; short PowerPointsMagic; struct { enum <byte> { disabled=0xFF } Plain, Fancy, Amulets, Gems, Greenware, Iron, Ivory; } Production; GODS Protection; //sacrifice to Chalana->toggles Malia struct { struct RAIDS { short ct; if (ct) RAID Raid[ct]; } Raided; RAIDS RaidedBy; } Raids; short __VictoryScore; //increase over time? increase per raid? } MtoR;
////////////////////////////////////////////////////////////////RELATIONS////////////////////////////////////////////////////////////////
SetBackColor(cLtYellow); struct { short ct; typedef struct { CLANIDX ClanIdx; short Attitude, __always0, FavorsDueUs, Alliance, Feud; BOOL Trade, Near, Neighbour; //Near=canRaid (N), Neighbour=canSeize short __SlightsTribal, TimesRaidedBy, //negative __, TimesRaided, __, Slights; struct { short __wePayTribute, Cattle, Food, Goods; } Tribute; short __FavorsTribal, __Flag; //changes whether a clan is displayed } RELATION <optimize=false, read=RELATIONread, write=RELATIONwrite>; if (ct) RELATION Relation[ct]; } Relations;

SetBackColor(cNone);         

////////////////////////////////////////////////////////////////DATA R-W////////////////////////////////////////////////////////////////

	i = 0;
		struct {
SetColor(cNone,cLtAqua);
			short RingMemberIdx[7];
			BOOL RoyalClan;
			short __RoyalJealousy, //=1 upon Einarth Milk-Eyes prophecy, =1/2 upon new npc tribes formation, =0 upon moot for new king
				Rye;
			struct { RITUAL Sacrifice, Known; } Rituals;
			struct { byte Ancestors, ArganArgar, Barntar, ChalanaArroy, Elmal, Ernalda, Eurmal, Humakt, Issaries, KeroFin, LhankorMhy, Malia, MaranGor, Odayla, Orlanth, TarardRiel, Uralda, Urox, Vinga, WindSpirits; } Sacrificed;
			short Sheep;
			GODS Shrines;
			short __shrine__; //shorts
			short __shrine__; //shorts
SetColor(cNone,cLtGreen);
			RITUAL ShrinePermanent;
SetColor(cNone,cLtAqua);
			GODS Temples;
			POP Thralls;
			BOOL ThrallsOkay;
			struct { i = 1;
				short ct;
				typedef struct { local int Idx = i++; short Qt, WearerIdx; } TREASURE <optimize=false, read=TREASUREread, write=TREASUREwrite>;
				if (ct) TREASURE Treasure[ct];
			} Treasures;
			short TribeIdx,
				__xTW,
				Wildlands, Wheat;
		} RtoW;
		ARRAY Zones; //display only

////////////////////////////////////////////////////////////////HISTORY////////////////////////////////////////////////////////////////
if (AtoL.ClanIdx==1) struct { //all data lengths confirmed SetBackColor(cNone); short GoodsProduced; enum <short> { ancestors=1, elmal, urox, odayla, ernalda, orlanth, issaries, lhankormhy, chalanaarroy, uralda } Awakened; SetForeColor(cDkGreen); short __, __; //short SetForeColor(cNone); GODS DeitiesKnown; enum <short> { Battle_of_Extinguishing_Field=1, Hundred_Day_Hunt, Jesteds_Settlement, Procession_of_Animals, Harnessed_Oxen, Hidden_Place, Marking_Bone, First_Pot, Clan_Making_Dance } EarliestEvent; DATE EmissaryLast, ExploreLast; BOOL FirstYear; struct { short Ate, Produced, Spoilage; } Food; BOOL EarthRaided; SetForeColor(cDkGreen); BOOL __bool, __bool; SetForeColor(cNone); DATE LastHunterAssign, LastCarlShortage; enum <short> { needed=1, more, lots, huge } LandClaim; DATE __LastMission; //last diplo/trade mission, not sure short __YearNow; //short enum <short> { merits=1, generous, enemies, friends } TribePolicy; SetForeColor(cDkGreen); short __; //short SetForeColor(cNone); short BabiesBorn; BALANCE ClanType; SetForeColor(cDkGreen); short __; //short DATE __DateLastTrade; //not sure SetForeColor(cNone); BOOL SeaRaided; struct { short Cattle, __food, __goods, //both always 0xCDCD, just guessing from context Horses, Pigs, Population, Sheep; } Resources; SetForeColor(cDkGreen); long __long; //long SetForeColor(cNone); DATE LastHeroQuest; struct { BOOL ChalanaArroy, Elmal, Ernalda, Humakt, Issaries, LhankorMhy, StormTribe, Orlanth, Uralda; } HeroQuest; SetForeColor(cDkGreen); BOOL __bool; SetForeColor(cNone); short MarketProfit; SetForeColor(cDkGreen); DATE __GameStart; short __; //short SetForeColor(cNone); struct { enum <short> { simple=1, full, deeper=4 } HowBegan, SwordStory, Contests, StormAge, StormTribe, Humakt, Issaries, LhankorMhy, Orlanth, JusticeBringer, ChalanaArroy, GreatDarkness, Elmal, Uralda, Ernalda; } Myth;
//local string s = SPrintf(s, "History= %i, %i", __[0], __[2]); Printf(s);
} History; } CLAN <optimize=false, read=CLANread, write=CLANwrite>; if (ct) CLAN Clan[ct] <optimize=false>;
} Clans;
SetBackColor(cNone);

//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
struct {

	short __LunarWar, //=0 gamestart, =2 upon Tarsh Illastor recruit event for Lunar war
		__; //=-1 always

} __shorts;

////////////////////////////////////////////////////////////////CLANNAMES////////////////////////////////////////////////////////////////
struct {

	typedef struct { short Name; } CLANNAME <optimize=false, read=CLANNAMEread>;
	struct {
		short ct;
		if (ct) CLANNAME Clan[ct];
	} ClanName;

	short count;
	byte __byte[7];
	STR __array;
	struct {
		short ct;
		if (ct) CLANNAME Clan[ct];
	} ClanPlural;

} ClanNames;

////////////////////////////////////////////////////////////////TRIBES////////////////////////////////////////////////////////////////
SetBackColor(cLtRed);

struct {

	short ct;
	typedef struct {
		DATE LastElection;
		BOOL __hasKing;
		STR Name;
		CLANIDX RoyalClanIdx;
		short __short; //always0
		struct {
			local int64 pos = FTell();
			short ct;
			if (ct) struct {
				CLANIDX ClanIdx;
				DATE DateJoined;
			} Clan[ct];
		} Tulas;
		short __short; //always0
		VAR Var;
	} TRIBE <optimize=false, read=TRIBEread>;
	TRIBE Tribe[ct];

} Tribes;
SetBackColor(cNone);

////////////////////////////////////////////////////////////////?////////////////////////////////////////////////////////////////
//struct {

typedef struct {
SetBackColor(cLtYellow);

        short __[5]; //tribes related? _x1[0]==-1 until tribe formed } __SHORT <read=SHORTread>;
__SHORT __short_5;
typedef struct {
SetBackColor(cLtPurple);

        BOOL __[53];
} __BOOL <read=BOOLread>;
__BOOL __bool_53;
//SetBackColor(cNone);
//} _static; //always same value at gamestart (not randomized)

////////////////////////////////////////////////////////////////EVENTS////////////////////////////////////////////////////////////////
SetBackColor(cLtBlue);
struct {
SetForeColor(cWhite);

        short ct;
SetForeColor(cNone);

	typedef struct {
		short EventIdx;
		enum <short> { code, _, explore=0xFFF8, trade=0xFFFA, diplo, raid, event=0xFFFE } Mission <format=hex>;
		short Turns, __, LeaderIdx;
		CLANIDX ClanIdx;
		short __;
		struct {
			short Weaponthane, Weaponthane, Fyrd, Cattle, Horses, Goods, Food;
			enum <short> { Slowly=1, Normally, Quickly } Travel;
			short Treasure;
		} Convoy;
		struct {
			short TargetX, TargetY;
			enum <short> { ask_cattle_route=1, ask_food, ask_info, ask_magic, tribute, gift, alliance, peace } Goal;
			enum <short> { Small=1, Medium, Large, Pathfinder=15328 } Caravan;
		} Objective;
	} QUE <optimize=false, read=QUEread, write=QUEwrite>;
	if (ct) QUE Que[ct];

	local int EventIdx = 0;
	typedef struct {
		local int Idx = EventIdx++;
		short Value;
	} EVENT <optimize=false, read=EVENTread>;
SetBackColor(cLtGreen);
	struct { EventIdx = 0; EVENT Event[1579]; } Times; //how many times it happened?
SetBackColor(cLtAqua);
	struct { EventIdx = 0; EVENT Event[1579]; } Years; //upon event, usually set to 0x7FFF, -1 per year

} Events;

////////////////////////////////////////////////////////////////ZONES////////////////////////////////////////////////////////////
SetBackColor(cLtYellow);
struct {
SetForeColor(cWhite);

        short ct;
SetForeColor(cNone);

        if (ct) short Owner[ct];
SetColor(cNone,cNone);

        char Opal[4];
} Zones;

#include "KoDPinc.bt"

Powered by hypermail