<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://moddingwiki.shikadi.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Treeswift</id>
	<title>ModdingWiki - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="https://moddingwiki.shikadi.net/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Treeswift"/>
	<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/wiki/Special:Contributions/Treeswift"/>
	<updated>2026-05-14T05:01:33Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.11</generator>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11694</id>
		<title>King&#039;s Bounty Index Tables</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11694"/>
		<updated>2024-02-05T04:14:15Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: type (extra parenthesis)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;As indicated in [[King&#039;s Bounty Saved game Format]], some of the values that define [[King&#039;s Bounty]]&#039;s world and mission are hardcoded within the main executable (KB.EXE). Specifically, assuming&lt;br /&gt;
&lt;br /&gt;
 constexpr int kAlphabet = 26; // &#039;Z&#039; - &#039;A&#039; + 1&lt;br /&gt;
 constexpr int kAlphaExt = kAlphabet + 1; // extra element at the end is the king&#039;s castle&lt;br /&gt;
&lt;br /&gt;
the following index tables exist (sample locations provided):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Offset 1990!!Data Type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0x183f8||[[BYTE]] x[kAlphaExt], y[kAlphaExt]||Castle gate locations (27 X values, then 27 Y values)&lt;br /&gt;
|-&lt;br /&gt;
|0x1867d||[[BYTE]] c[kAlphabet]||Continent of the castle (0-3).&amp;lt;ref&amp;gt;Used for Castle Gate and for castle entry detection.&amp;lt;/ref&amp;gt; 26 values (the king&#039;s continent is always 0)&lt;br /&gt;
|-&lt;br /&gt;
|0x165cb||[[BYTE]] c[kAlphabet]||An identical copy of the above, with unclear purpose.&amp;lt;ref&amp;gt;Possibly a rudiment of an early design allowing town placement on a different continent from its castle?&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x169d6||[[BYTE]] c[kAlphabet]||A THIRD identical copy of the above, used e.g. for villain contracts.&lt;br /&gt;
|-&lt;br /&gt;
|0x18481||[[BYTE]] x[kAlphabet], y[kAlphabet]||Town square coordinates (26 X values, then 26 Y values), *in corresponding castle order*.&amp;lt;ref&amp;gt;The game treats castle-town pairs as, essentially, castle objects with town properties. All town data, except (obviously) for the Town Gate lookup table, are arranged in castle order, i.e. Riverton is #0 because of Azram, Underfoot is #1 because of Basefit, etc. Even the town name strings appear in the file in corresponding castle alphabetical order (Riverton, Underfoot...) instead of their own alphabetical order (Anomaly, Bayview...)&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x1852d||[[BYTE]] x[kAlphabet], y[kAlphabet]||Harbor coordinates (where the boat appears); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18649||[[BYTE]] x[kAlphabet], y[kAlphabet]||&amp;quot;Airport&amp;quot; coordinates (where Town Gate lands the hero); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18697||[[BYTE]] m[kAlphabet]||town letter -&amp;gt; castle letter mapping for Town Gate (26 indices). E.g. &amp;lt;tt&amp;gt;m[0]&amp;lt;/tt&amp;gt; (town of A-Anomaly) is &amp;lt;tt&amp;gt;0x3&amp;lt;/tt&amp;gt; (castle of D-Duvock).&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Obviously, all of the offsets apply to the uncompressed file.&lt;br /&gt;
&lt;br /&gt;
The Castle Gate spell always places the hero south of the actual castle gate (the Y coordinate is less by 1).&lt;br /&gt;
&lt;br /&gt;
Stepping on a Castle Gate tile (&amp;lt;tt&amp;gt;0x85&amp;lt;/tt&amp;gt;) that does not correspond to a recognized castle freezes the game.&lt;br /&gt;
&lt;br /&gt;
Stepping on a Town tile (&amp;lt;tt&amp;gt;0x8a&amp;lt;/tt&amp;gt;) that does not correspond to a recognized town immediately returns the hero one step back.&lt;br /&gt;
&lt;br /&gt;
Stepping onto a registered map location (one that&#039;s present in the tables) that&#039;s not marked by a corresponding interactive tile (town walls or castle gate) on the map does not by itself result in an interaction. In other words, coordinate matching only occurs after tile code matching.&lt;br /&gt;
&lt;br /&gt;
== Original geography ==&lt;br /&gt;
&lt;br /&gt;
The offsets to index tables vary between released game builds. It is, however, possible to locate those tables in the game file by value by using the original castle and town coordinates to build canonical representations of the original index tables and then searching for representative byte sequences.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/treeswift/royalreward Modena] (the KB modding tool) uses the following castle/town coordinates (the first pair being the castle entry, the second the town square, the first directional vector offset to the &amp;quot;Rent Boat&amp;quot; harbor and the second offset to the Town Gate &amp;quot;airfield&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
        {{30,	27},	{{29,	12},	se,	ss}},&lt;br /&gt;
        {{47,	6}, 	{{58,	4},	ne,	ww}},&lt;br /&gt;
        {{36,	49},	{{38,	50},	ee,	ss}},&lt;br /&gt;
        {{30,	18},	{{34,	23},	ss,	ee}},&lt;br /&gt;
        {{11,	46},	{{5,	50},	sw,	ss}},&lt;br /&gt;
        {{22,	49},	{{17,	44},	ee,	ww}},&lt;br /&gt;
        {{41,	36},	{{13,	60},	ee,	ww}},&lt;br /&gt;
        {{43,	27},	{{9,	39},	se,	ss}},&lt;br /&gt;
        {{11,	30},	{{14,	27},	ss,	ww}},&lt;br /&gt;
        {{41,	34},	{{58,	33},	ss,	ww}},&lt;br /&gt;
        {{57,	58},	{{51,	28},	ss,	nn}},&lt;br /&gt;
        {{52,	57},	{{57,	57},	se,	ss}},&lt;br /&gt;
        {{25,	39},	{{3,	37},	sw,	ss}},&lt;br /&gt;
        {{22,	24},	{{17,	21},	ee,	ww}},&lt;br /&gt;
        {{6, 	57},	{{41,	58},	ss,	ww}},&lt;br /&gt;
        {{58,	23},	{{50,	13},	sw,	nn}},&lt;br /&gt;
        {{42,	56},	{{58,	60},	ee,	ss}},&lt;br /&gt;
        {{54,	6}, 	{{57,	5},	sw,	ww}},&lt;br /&gt;
        {{17,	39},	{{9,	60},	ee,	ss}},&lt;br /&gt;
        {{9, 	18},	{{13,	7},	ww,	nn}},&lt;br /&gt;
        {{41,	12},	{{7,	3},	ee,	ww}},&lt;br /&gt;
        {{40,	5}, 	{{12,	3},	ww,	nn}},&lt;br /&gt;
        {{40,	41},	{{46,	35},	ne,	ee}},&lt;br /&gt;
        {{45,	6}, 	{{49,	8},	ne,	ee}},&lt;br /&gt;
        {{19,	19},	{{3,	8},	nw,	nn}},&lt;br /&gt;
        {{46,	43},	{{58,	48},	ee,	ss}},&lt;br /&gt;
        {{11,	7},     {}} // Washington, D.C.&lt;br /&gt;
&lt;br /&gt;
...and the following castle/continent breakdown:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!C-index!!Continent!!Castles!!Villains|Castle initials (for Info)&lt;br /&gt;
|-&lt;br /&gt;
|0||Continentia||11||6|ACFIKNOPRVW&lt;br /&gt;
|-&lt;br /&gt;
|1||Forestria||6||4|BDJMQY&lt;br /&gt;
|-&lt;br /&gt;
|2||Archipelia||6||4|EGHLTX&lt;br /&gt;
|-&lt;br /&gt;
|3||Saharia||3||3|SUZ&lt;br /&gt;
|-&lt;br /&gt;
|=||(total)||26||17|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;lt;tt&amp;gt;ham&amp;lt;/tt&amp;gt; (name shortened from &amp;quot;Hamming&amp;quot;) tool from the [https://github.com/treeswift/royalreward Royal Reward] project to analyze a binary file. Sample output:&lt;br /&gt;
&lt;br /&gt;
 conts: 0x165cb # (hamming=0 confidence=100.00%)&lt;br /&gt;
 conts: 0x169d6 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 conts: 0x1867d # (hamming=0 confidence=100.00%)&lt;br /&gt;
 forts[X]: 0x183f8 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 forts[Y]: 0x18413 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 ports[X]: 0x18481 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 ports[Y]: 0x1849b # (hamming=0 confidence=100.00%)&lt;br /&gt;
 p_bay[X]: 0x1852d # (hamming=0 confidence=100.00%)&lt;br /&gt;
 p_bay[Y]: 0x18547 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 p_air[X]: 0x18649 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 p_air[Y]: 0x18663 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 ptofs: 0x18697 # (hamming=0 confidence=100.00%)&lt;br /&gt;
&lt;br /&gt;
The tool has been tested on three different versions of &amp;lt;tt&amp;gt;KB.EXE&amp;lt;/tt&amp;gt; and successfully located all the 6 kinds of lookup tables (4 of them broken down by X and Y) in each.&lt;br /&gt;
&lt;br /&gt;
By editing all the correlated tables simultaneously it is then possible to move the castles and towns both within and across continents. However, placement of a castle and its corresponding town on two different continents has not yet been achieved and is most probably impossible.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11680</id>
		<title>King&#039;s Bounty Index Tables</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11680"/>
		<updated>2024-02-02T14:30:45Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: a tool for adaptive index table patching has been added; a third index table found&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;As indicated in [[King&#039;s Bounty Saved game Format]], some of the values that define [[King&#039;s Bounty]]&#039;s world and mission are hardcoded within the main executable (KB.EXE). Specifically, assuming&lt;br /&gt;
&lt;br /&gt;
 constexpr int kAlphabet = 26; // &#039;Z&#039; - &#039;A&#039; + 1&lt;br /&gt;
 constexpr int kAlphaExt = kAlphabet + 1; // extra element at the end is the king&#039;s castle&lt;br /&gt;
&lt;br /&gt;
the following index tables exist (sample locations provided):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Offset 1990!!Data Type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0x183f8||[[BYTE]] x[kAlphaExt], y[kAlphaExt]||Castle gate locations (27 X values, then 27 Y values)&lt;br /&gt;
|-&lt;br /&gt;
|0x1867d||[[BYTE]] c[kAlphabet]||Continent of the castle (0-3).&amp;lt;ref&amp;gt;Used for Castle Gate and for castle entry detection.&amp;lt;/ref&amp;gt; 26 values (the king&#039;s continent is always 0)&lt;br /&gt;
|-&lt;br /&gt;
|0x165cb||[[BYTE]] c[kAlphabet]||An identical copy of the above, with unclear purpose.&amp;lt;ref&amp;gt;Possibly a rudiment of an early design allowing town placement on a different continent from its castle?&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x169d6||[[BYTE]] c[kAlphabet]||A THIRD identical copy of the above, used e.g. for villain contracts.&lt;br /&gt;
|-&lt;br /&gt;
|0x18481||[[BYTE]] x[kAlphabet], y[kAlphabet]||Town square coordinates (26 X values, then 26 Y values), *in corresponding castle order*.&amp;lt;ref&amp;gt;The game treats castle-town pairs as, essentially, castle objects with town properties. All town data, except (obviously) for the Town Gate lookup table, are arranged in castle order, i.e. Riverton is #0 because of Azram, Underfoot is #1 because of Basefit, etc. Even the town name strings appear in the file in corresponding castle alphabetical order (Riverton, Underfoot...) instead of their own alphabetical order (Anomaly, Bayview...)&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x1852d||[[BYTE]] x[kAlphabet], y[kAlphabet]||Harbor coordinates (where the boat appears); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18649||[[BYTE]] x[kAlphabet], y[kAlphabet]||&amp;quot;Airport&amp;quot; coordinates (where Town Gate lands the hero); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18697||[[BYTE]] m[kAlphabet]||town letter -&amp;gt; castle letter mapping for Town Gate (26 indices). E.g. &amp;lt;tt&amp;gt;m[0]&amp;lt;/tt&amp;gt; (town of A-Anomaly) is &amp;lt;tt&amp;gt;0x3&amp;lt;/tt&amp;gt; (castle of D-Duvock).&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Obviously, all of the offsets apply to the uncompressed file.&lt;br /&gt;
&lt;br /&gt;
The Castle Gate spell always places the hero south of the actual castle gate (the Y coordinate is less by 1).&lt;br /&gt;
&lt;br /&gt;
Stepping on a Castle Gate tile (&amp;lt;tt&amp;gt;0x85&amp;lt;/tt&amp;gt;)) that does not correspond to a recognized castle freezes the game.&lt;br /&gt;
&lt;br /&gt;
Stepping on a Town tile (&amp;lt;tt&amp;gt;0x8a&amp;lt;/tt&amp;gt;) that does not correspond to a recognized town immediately returns the hero one step back.&lt;br /&gt;
&lt;br /&gt;
Stepping onto a registered map location (one that&#039;s present in the tables) that&#039;s not marked by a corresponding interactive tile (town walls or castle gate) on the map does not by itself result in an interaction. In other words, coordinate matching only occurs after tile code matching.&lt;br /&gt;
&lt;br /&gt;
== Original geography ==&lt;br /&gt;
&lt;br /&gt;
The offsets to index tables vary between released game builds. It is, however, possible to locate those tables in the game file by value by using the original castle and town coordinates to build canonical representations of the original index tables and then searching for representative byte sequences.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/treeswift/royalreward Modena] (the KB modding tool) uses the following castle/town coordinates (the first pair being the castle entry, the second the town square, the first directional vector offset to the &amp;quot;Rent Boat&amp;quot; harbor and the second offset to the Town Gate &amp;quot;airfield&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
        {{30,	27},	{{29,	12},	se,	ss}},&lt;br /&gt;
        {{47,	6}, 	{{58,	4},	ne,	ww}},&lt;br /&gt;
        {{36,	49},	{{38,	50},	ee,	ss}},&lt;br /&gt;
        {{30,	18},	{{34,	23},	ss,	ee}},&lt;br /&gt;
        {{11,	46},	{{5,	50},	sw,	ss}},&lt;br /&gt;
        {{22,	49},	{{17,	44},	ee,	ww}},&lt;br /&gt;
        {{41,	36},	{{13,	60},	ee,	ww}},&lt;br /&gt;
        {{43,	27},	{{9,	39},	se,	ss}},&lt;br /&gt;
        {{11,	30},	{{14,	27},	ss,	ww}},&lt;br /&gt;
        {{41,	34},	{{58,	33},	ss,	ww}},&lt;br /&gt;
        {{57,	58},	{{51,	28},	ss,	nn}},&lt;br /&gt;
        {{52,	57},	{{57,	57},	se,	ss}},&lt;br /&gt;
        {{25,	39},	{{3,	37},	sw,	ss}},&lt;br /&gt;
        {{22,	24},	{{17,	21},	ee,	ww}},&lt;br /&gt;
        {{6, 	57},	{{41,	58},	ss,	ww}},&lt;br /&gt;
        {{58,	23},	{{50,	13},	sw,	nn}},&lt;br /&gt;
        {{42,	56},	{{58,	60},	ee,	ss}},&lt;br /&gt;
        {{54,	6}, 	{{57,	5},	sw,	ww}},&lt;br /&gt;
        {{17,	39},	{{9,	60},	ee,	ss}},&lt;br /&gt;
        {{9, 	18},	{{13,	7},	ww,	nn}},&lt;br /&gt;
        {{41,	12},	{{7,	3},	ee,	ww}},&lt;br /&gt;
        {{40,	5}, 	{{12,	3},	ww,	nn}},&lt;br /&gt;
        {{40,	41},	{{46,	35},	ne,	ee}},&lt;br /&gt;
        {{45,	6}, 	{{49,	8},	ne,	ee}},&lt;br /&gt;
        {{19,	19},	{{3,	8},	nw,	nn}},&lt;br /&gt;
        {{46,	43},	{{58,	48},	ee,	ss}},&lt;br /&gt;
        {{11,	7},     {}} // Washington, D.C.&lt;br /&gt;
&lt;br /&gt;
...and the following castle/continent breakdown:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!C-index!!Continent!!Castles!!Villains|Castle initials (for Info)&lt;br /&gt;
|-&lt;br /&gt;
|0||Continentia||11||6|ACFIKNOPRVW&lt;br /&gt;
|-&lt;br /&gt;
|1||Forestria||6||4|BDJMQY&lt;br /&gt;
|-&lt;br /&gt;
|2||Archipelia||6||4|EGHLTX&lt;br /&gt;
|-&lt;br /&gt;
|3||Saharia||3||3|SUZ&lt;br /&gt;
|-&lt;br /&gt;
|=||(total)||26||17|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
You can use the &amp;lt;tt&amp;gt;ham&amp;lt;/tt&amp;gt; (name shortened from &amp;quot;Hamming&amp;quot;) tool from the [https://github.com/treeswift/royalreward Royal Reward] project to analyze a binary file. Sample output:&lt;br /&gt;
&lt;br /&gt;
 conts: 0x165cb # (hamming=0 confidence=100.00%)&lt;br /&gt;
 conts: 0x169d6 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 conts: 0x1867d # (hamming=0 confidence=100.00%)&lt;br /&gt;
 forts[X]: 0x183f8 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 forts[Y]: 0x18413 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 ports[X]: 0x18481 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 ports[Y]: 0x1849b # (hamming=0 confidence=100.00%)&lt;br /&gt;
 p_bay[X]: 0x1852d # (hamming=0 confidence=100.00%)&lt;br /&gt;
 p_bay[Y]: 0x18547 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 p_air[X]: 0x18649 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 p_air[Y]: 0x18663 # (hamming=0 confidence=100.00%)&lt;br /&gt;
 ptofs: 0x18697 # (hamming=0 confidence=100.00%)&lt;br /&gt;
&lt;br /&gt;
The tool has been tested on three different versions of &amp;lt;tt&amp;gt;KB.EXE&amp;lt;/tt&amp;gt; and successfully located all the 6 kinds of lookup tables (4 of them broken down by X and Y) in each.&lt;br /&gt;
&lt;br /&gt;
By editing all the correlated tables simultaneously it is then possible to move the castles and towns both within and across continents. However, placement of a castle and its corresponding town on two different continents has not yet been achieved and is most probably impossible.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11627</id>
		<title>King&#039;s Bounty Index Tables</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11627"/>
		<updated>2024-01-25T07:03:37Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: continent labeling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;As indicated in [[King&#039;s Bounty Saved game Format]], some of the values that define [[King&#039;s Bounty]]&#039;s world and mission are hardcoded within the main executable (KB.EXE). Specifically, assuming&lt;br /&gt;
&lt;br /&gt;
 constexpr int kAlphabet = 26; // &#039;Z&#039; - &#039;A&#039; + 1&lt;br /&gt;
 constexpr int kAlphaExt = kAlphabet + 1; // extra element at the end is the king&#039;s castle&lt;br /&gt;
&lt;br /&gt;
the following index tables exist (I only have the DOS 1990 version at the moment; need to find and examine the 1995 version):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Offset 1990!!Offset 1995!!Data Type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0x183f8||?||[[BYTE]] x[kAlphaExt], y[kAlphaExt]||Castle gate locations (27 X values, then 27 Y values)&lt;br /&gt;
|-&lt;br /&gt;
|0x1867d||?||[[BYTE]] c[kAlphabet]||Continent of the castle (0-3).&amp;lt;ref&amp;gt;Used for Castle Gate and for castle entry detection.&amp;lt;/ref&amp;gt; 26 values (the king&#039;s continent is always 0)&lt;br /&gt;
|-&lt;br /&gt;
|0x165cb||?||[[BYTE]] c[kAlphabet]||An identical copy of the above, with unclear purpose.&amp;lt;ref&amp;gt;Possibly a rudiment of an early design allowing town placement on a different continent from its castle?&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x18481||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||Town square coordinates (26 X values, then 26 Y values), *in corresponding castle order*.&amp;lt;ref&amp;gt;The game treats castle-town pairs as, essentially, castle objects with town properties. All town data, except (obviously) for the Town Gate lookup table, are arranged in castle order, i.e. Riverton is #0 because of Azram, Underfoot is #1 because of Basefit, etc. Even the town name strings appear in the file in corresponding castle alphabetical order (Riverton, Underfoot...) instead of their own alphabetical order (Anomaly, Bayview...)&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x1852d||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||Harbor coordinates (where the boat appears); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18649||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||&amp;quot;Airport&amp;quot; coordinates (where Town Gate lands the hero); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18697||?||[[BYTE]] m[kAlphabet]||town letter -&amp;gt; castle letter mapping for Town Gate (26 indices). E.g. &amp;lt;tt&amp;gt;m[0]&amp;lt;/tt&amp;gt; (town of A-Anomaly) is &amp;lt;tt&amp;gt;0x3&amp;lt;/tt&amp;gt; (castle of D-Duvock).&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Obviously, all of the offsets apply to the uncompressed file.&lt;br /&gt;
&lt;br /&gt;
The Castle Gate spell always places the hero south of the actual castle gate (the Y coordinate is less by 1).&lt;br /&gt;
&lt;br /&gt;
Stepping on a Castle Gate tile (&amp;lt;tt&amp;gt;0x85&amp;lt;/tt&amp;gt;)) that does not correspond to a recognized castle freezes the game.&lt;br /&gt;
&lt;br /&gt;
Stepping on a Town tile (&amp;lt;tt&amp;gt;0x8a&amp;lt;/tt&amp;gt;) that does not correspond to a recognized town immediately returns the hero one step back.&lt;br /&gt;
&lt;br /&gt;
Stepping onto a registered map location (one that&#039;s present in the tables) that&#039;s not marked by a corresponding interactive tile (town walls or castle gate) on the map does not by itself result in an interaction. In other words, coordinate matching only occurs after tile code matching.&lt;br /&gt;
&lt;br /&gt;
== Constraints ==&lt;br /&gt;
&lt;br /&gt;
Not all possible index combinations (even those that maintain the permutation invariant, i.e. correctly define 26 distinct towns, castles and the king&#039;s castle) are supported. Bugs ranging from sad (game freeze) to funny (corrupt text messages, inconsistent Contract Info) ensue if the numbers of castles and villains on each continents deviate from the prearranged distribution (below). Insult to injury, the castle-to-continent mapping seems to be defined in a not yet found THIRD lookup table that affects the villain&#039;s Last Seen continent on the Contract Info screen.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!C-index!!Continent!!Castles!!Villains|Castle initials (for Info)&lt;br /&gt;
|-&lt;br /&gt;
|0||Continentia||11||6|ACFIKNOPRVW&lt;br /&gt;
|-&lt;br /&gt;
|1||Forestria||6||4|BDJMQY&lt;br /&gt;
|-&lt;br /&gt;
|2||Archipelia||6||4|EGHLTX&lt;br /&gt;
|-&lt;br /&gt;
|3||Saharia||3||3|SUZ&lt;br /&gt;
|-&lt;br /&gt;
|=||(total)||26||17|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
It is, however, possible to arrange the castles on a particular continent in a pretty much arbitrary way; place castle gate tiles without the surrounding castle walls (allowing &amp;quot;backdoor access&amp;quot; to them); place villains in castles without regard to their difficulty level (e.g. place Arech in Continentia via the LUT in the save file); etc.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11626</id>
		<title>King&#039;s Bounty Index Tables</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11626"/>
		<updated>2024-01-25T07:02:24Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: ordering example, clarification&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;As indicated in [[King&#039;s Bounty Saved game Format]], some of the values that define [[King&#039;s Bounty]]&#039;s world and mission are hardcoded within the main executable (KB.EXE). Specifically, assuming&lt;br /&gt;
&lt;br /&gt;
 constexpr int kAlphabet = 26; // &#039;Z&#039; - &#039;A&#039; + 1&lt;br /&gt;
 constexpr int kAlphaExt = kAlphabet + 1; // extra element at the end is the king&#039;s castle&lt;br /&gt;
&lt;br /&gt;
the following index tables exist (I only have the DOS 1990 version at the moment; need to find and examine the 1995 version):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Offset 1990!!Offset 1995!!Data Type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0x183f8||?||[[BYTE]] x[kAlphaExt], y[kAlphaExt]||Castle gate locations (27 X values, then 27 Y values)&lt;br /&gt;
|-&lt;br /&gt;
|0x1867d||?||[[BYTE]] c[kAlphabet]||Continent of the castle (0-3).&amp;lt;ref&amp;gt;Used for Castle Gate and for castle entry detection.&amp;lt;/ref&amp;gt; 26 values (the king&#039;s continent is always 0)&lt;br /&gt;
|-&lt;br /&gt;
|0x165cb||?||[[BYTE]] c[kAlphabet]||An identical copy of the above, with unclear purpose.&amp;lt;ref&amp;gt;Possibly a rudiment of an early design allowing town placement on a different continent from its castle?&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x18481||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||Town square coordinates (26 X values, then 26 Y values), *in corresponding castle order*.&amp;lt;ref&amp;gt;The game treats castle-town pairs as, essentially, castle objects with town properties. All town data, except (obviously) for the Town Gate lookup table, are arranged in castle order, i.e. Riverton is #0 because of Azram, Underfoot is #1 because of Basefit, etc. Even the town name strings appear in the file in corresponding castle alphabetical order (Riverton, Underfoot...) instead of their own alphabetical order (Anomaly, Bayview...)&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x1852d||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||Harbor coordinates (where the boat appears); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18649||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||&amp;quot;Airport&amp;quot; coordinates (where Town Gate lands the hero); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18697||?||[[BYTE]] m[kAlphabet]||town letter -&amp;gt; castle letter mapping for Town Gate (26 indices). E.g. &amp;lt;tt&amp;gt;m[0]&amp;lt;/tt&amp;gt; (town of A-Anomaly) is &amp;lt;tt&amp;gt;0x3&amp;lt;/tt&amp;gt; (castle of D-Duvock).&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Obviously, all of the offsets apply to the uncompressed file.&lt;br /&gt;
&lt;br /&gt;
The Castle Gate spell always places the hero south of the actual castle gate (the Y coordinate is less by 1).&lt;br /&gt;
&lt;br /&gt;
Stepping on a Castle Gate tile (&amp;lt;tt&amp;gt;0x85&amp;lt;/tt&amp;gt;)) that does not correspond to a recognized castle freezes the game.&lt;br /&gt;
&lt;br /&gt;
Stepping on a Town tile (&amp;lt;tt&amp;gt;0x8a&amp;lt;/tt&amp;gt;) that does not correspond to a recognized town immediately returns the hero one step back.&lt;br /&gt;
&lt;br /&gt;
Stepping onto a registered map location (one that&#039;s present in the tables) that&#039;s not marked by a corresponding interactive tile (town walls or castle gate) on the map does not by itself result in an interaction. In other words, coordinate matching only occurs after tile code matching.&lt;br /&gt;
&lt;br /&gt;
== Constraints ==&lt;br /&gt;
&lt;br /&gt;
Not all possible index combinations (even those that maintain the permutation invariant, i.e. correctly define 26 distinct towns, castles and the king&#039;s castle) are supported. Bugs ranging from sad (game freeze) to funny (corrupt text messages, inconsistent Contract Info) ensue if the numbers of castles and villains on each continents deviate from the prearranged distribution (below). Insult to injury, the castle-to-continent mapping seems to be defined in a not yet found THIRD lookup table that affects the villain&#039;s Last Seen continent on the Contract Info screen.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!C-index!!Continent!!Castles!!Villains|Castle initials (for Info)&lt;br /&gt;
|-&lt;br /&gt;
|0||Continentia||11||6|ACFIKNOPRVW&lt;br /&gt;
|-&lt;br /&gt;
|1||Continentia||6||4|BDJMQY&lt;br /&gt;
|-&lt;br /&gt;
|2||Continentia||6||4|EGHLTX&lt;br /&gt;
|-&lt;br /&gt;
|3||Continentia||3||3|SUZ&lt;br /&gt;
|-&lt;br /&gt;
|=||(total)||26||17|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
It is, however, possible to arrange the castles on a particular continent in a pretty much arbitrary way; place castle gate tiles without the surrounding castle walls (allowing &amp;quot;backdoor access&amp;quot; to them); place villains in castles without regard to their difficulty level (e.g. place Arech in Continentia via the LUT in the save file); etc.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Map_Format&amp;diff=11625</id>
		<title>King&#039;s Bounty Map Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Map_Format&amp;diff=11625"/>
		<updated>2024-01-25T05:34:27Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: Modding hint (1990 version)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Map Infobox&lt;br /&gt;
 | Type = 2D tile-based&lt;br /&gt;
 | Games =&lt;br /&gt;
   {{Game|King&#039;s Bounty}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This format is used to store the world map for [[King&#039;s Bounty]] in both it&#039;s initial state (&amp;lt;tt&amp;gt;LAND.ORG&amp;lt;/tt&amp;gt; file) and in modified, randomized state (in the &amp;lt;tt&amp;gt;*.DAT&amp;lt;/tt&amp;gt; save files at offset &amp;lt;tt&amp;gt;0xFC5&amp;lt;/tt&amp;gt;). Consequently, there are minor format differences, described below.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The map always takes exactly 16384 bytes. As there are 4 continents 64 x 64 tiles each, and each tile takes 1 byte, all continents start at a convenient offset - 0x0000, 0x1000, 0x2000 or 0x3000.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]] map[4][64][64]||Map data&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Coordinates ===&lt;br /&gt;
&lt;br /&gt;
The game is consistent with it&#039;s map coordinate system, which goes in the &#039;&#039;&#039;bottom-to-top&#039;&#039;&#039;, left-to-right order. That means top left corner has coordinate X=0, Y=63.&lt;br /&gt;
&lt;br /&gt;
=== Salting ===&lt;br /&gt;
&lt;br /&gt;
When a new game is first created, the initial map data is read and then the following values are replaced:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0xFF - continent start           -&amp;gt; 0x20 - sea tile&lt;br /&gt;
0x8B - put something random here -&amp;gt; 0x8B - 0x93 , but not 0x90&lt;br /&gt;
0x8E - archmage&#039;s alcove         -&amp;gt; 0x00 (for mages) / 0x8E (for rest)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note, that the &amp;lt;tt&amp;gt;0x8B&amp;lt;/tt&amp;gt; index is used in both initial and salted data with different meanings - it stands for &#039;&#039;random object&#039;&#039; in &amp;lt;tt&amp;gt;LAND.ORG&amp;lt;/tt&amp;gt;, and a &#039;&#039;treasure chest&#039;&#039; in the save files. &lt;br /&gt;
&lt;br /&gt;
=== Tileset ===&lt;br /&gt;
&lt;br /&gt;
The tileset is kept inside the &amp;lt;tt&amp;gt;tileseta.*&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;tilesetb.*&amp;lt;/tt&amp;gt; graphic files. Each file contains 36 tiles, making 72 in total. &#039;&#039;Additionally, &amp;lt;tt&amp;gt;tilesalt.*&amp;lt;/tt&amp;gt; contains replacements graphics for tiles &amp;lt;tt&amp;gt;0x11-0x13&amp;lt;/tt&amp;gt; for continents 2-4&#039;&#039;. Each level byte &#039;&#039;&#039;with it&#039;s most significant bit cleared&#039;&#039;&#039; maps directly into that range (&amp;lt;tt&amp;gt;0x00-0x47&amp;lt;/tt&amp;gt;). The high bit signifies if the tile is interactive, and those high-bit versions are always used instead of the regular indexes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0x80 - magic barrier (blocks followers)&lt;br /&gt;
0x85 - castle gate&lt;br /&gt;
0x8A - town&lt;br /&gt;
0x8B - treasure chest&lt;br /&gt;
0x8C - plains dwelling&lt;br /&gt;
0x8D - forest dwelling&lt;br /&gt;
0x8E - cave dwelling (multiple purposes)&lt;br /&gt;
0x8F - dungeon dwelling&lt;br /&gt;
0x90 - sign&lt;br /&gt;
0x91 - follower&lt;br /&gt;
0x92 - artifact 1&lt;br /&gt;
0x93 - artifact 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constant Locations ===&lt;br /&gt;
&lt;br /&gt;
Those locations are hard-coded into the game and can not be changed from within the map:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
X=11 Y=7  - King&#039;s Castle&lt;br /&gt;
X=11 Y=6  - Retreat location&lt;br /&gt;
X=11 Y=5  - Starting Location&lt;br /&gt;
X=11 Y=3  - Continent 1 starting location&lt;br /&gt;
X=1  Y=37 - Continent 2 starting location&lt;br /&gt;
X=14 Y=62 - Continent 3 starting location&lt;br /&gt;
X=9  Y=1  - Continent 4 starting location&lt;br /&gt;
X=11 Y=19 - Archmage&#039;s Alcove&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The king&#039;s castle coordinates are the last extra element of the [[King&#039;s Bounty Index Tables|castle location table]].&lt;br /&gt;
&lt;br /&gt;
== Constraints ==&lt;br /&gt;
&lt;br /&gt;
Remember that while it&#039;s possible to place any combination of the tiles on the map, not all of those combinations will be consistent:&lt;br /&gt;
&lt;br /&gt;
# Town square and castle gate locations need to be placed in the game&#039;s [[King&#039;s Bounty Index Tables|lookup tables]] to be interactive.&lt;br /&gt;
# If a desert tile is placed near the ocean tile, it&#039;s possible to pull the boat onto the beach and row it across the desert. Each step still takes a day. If this is not a desired effect, separate the desert from the sea with any other terrain (typically, road).&lt;br /&gt;
# Of terrain tiles, only the road tile (&amp;lt;tt&amp;gt;0x0&amp;lt;/tt&amp;gt;) can &amp;quot;seamlessly neighbor&amp;quot; both its own and all other terrains. Other terrain types (sea, desert, mountains and woods) have a &amp;quot;solid&amp;quot; tile (&amp;lt;tt&amp;gt;0x20&amp;lt;/tt&amp;gt; for the sea, &amp;lt;tt&amp;gt;0x2d&amp;lt;/tt&amp;gt; for the woods, &amp;lt;tt&amp;gt;0x3a&amp;lt;/tt&amp;gt; for the desert and &amp;lt;tt&amp;gt;0x47&amp;lt;/tt&amp;gt; for the mountains) that can only neighbor its own terrain and 12 border tiles.&lt;br /&gt;
&lt;br /&gt;
The following code example creates the tile code correction table for border tiles. The correction is added to the code of the respective solid tile:&lt;br /&gt;
&lt;br /&gt;
        constexpr int lb = 1, rb = 2, lt = 4, rt = 8;&lt;br /&gt;
        cor_sea.resize(0x10, 0); // all 16 combinations, though only 13 are supported&lt;br /&gt;
        cor_sea[lt | rt] = -1; // ▀&lt;br /&gt;
        cor_sea[lb | rb] = -2; // ▄&lt;br /&gt;
        cor_sea[rt | rb] = -3; // ▐&lt;br /&gt;
        cor_sea[lt | lb] = -4; // ▌&lt;br /&gt;
        cor_sea[rt | rb | lb] = -5; // ▟&lt;br /&gt;
        cor_sea[lt | rt | rb] = -6; // ▜&lt;br /&gt;
        cor_sea[rb | lb | lt] = -7; // ▙&lt;br /&gt;
        cor_sea[rt | lt | lb] = -8; // ▛&lt;br /&gt;
        cor_sea[lt] = -9;  // ▘&lt;br /&gt;
        cor_sea[lb] = -12; // ▖&lt;br /&gt;
        cor_sea[rt] = -10; // ▝&lt;br /&gt;
        cor_sea[rb] = -11; // ▗&lt;br /&gt;
        cor_for = cor_sea; // sea tiles have a special ordering&lt;br /&gt;
        cor_for[lb] = -10; // ▖&lt;br /&gt;
        cor_for[rt] = -11; // ▝&lt;br /&gt;
        cor_for[rb] = -12; // ▗&lt;br /&gt;
        cor_snd = cor_mnt = cor_for; // sands, mountains, and forest follow a common order&lt;br /&gt;
&lt;br /&gt;
Generally, every tile of a special terrain (sands, mountains, woods or sea) must be a part of at least one 2x2 patch of the same terrain — i.e., e.g., an isolated 1x1 patch of desert can&#039;t be displayed correctly. In addition, diagonal combinations (e.g. a sea tile that&#039;s neighboring a sea — i.e. is a part of a 2x2 sea square — to the northeast and southwest, but not to the northwest and southeast, *and has to be a part of both*&amp;lt;ref&amp;gt;Adjacent tiles of the same terrain can still be displayed as if they belonged to disconnected spans of it — look at the fractured desert between Nyre and Xoctan to see what I mean&amp;lt;/ref&amp;gt;) can&#039;t be displayed correctly, either. E.g. consider the following screen:&lt;br /&gt;
&lt;br /&gt;
 sea1 sea1 land&lt;br /&gt;
 sea1 sea* sea2&lt;br /&gt;
 land sea2 sea2&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sea*&amp;lt;/tt&amp;gt; tile can be a part of either the 2x2 &amp;lt;tt&amp;gt;sea1&amp;lt;/tt&amp;gt; patch or the 2x2 &amp;lt;tt&amp;gt;sea2&amp;lt;/tt&amp;gt; patch. If &amp;lt;tt&amp;gt;sea1&amp;lt;/tt&amp;gt; is a part of a greater ocean, then &amp;lt;tt&amp;gt;sea1&amp;lt;/tt&amp;gt; tiles can be displayed as its border tiles and &amp;lt;tt&amp;gt;sea*&amp;lt;/tt&amp;gt; form a block with &amp;lt;tt&amp;gt;sea2&amp;lt;/tt&amp;gt; (ditto if &amp;lt;tt&amp;gt;sea2&amp;lt;/tt&amp;gt; is a larger sea). If the sea tiles on the screen show a complete lake, there is no way to take the central tile out of either part of the lake without breaking the 2x2 rule.&lt;br /&gt;
&lt;br /&gt;
With narrow diagonal straits the limitation can be mitigated by displaying one of the corners cut off; it looks less crappy than displaying a solid tile (e.g. the &amp;lt;tt&amp;gt;sea*&amp;lt;/tt&amp;gt; tile above can have either a northeast or a southwest land corner, but not both). With forest tiles, ignoring inconsistent bottom corners produces slightly better looks than ignoring the top ones. Ideally, however, your generator and/or map editor should not allow graphically inconsistent tiles to border each other.&lt;br /&gt;
&lt;br /&gt;
Note that while original maps don&#039;t have narrow forest/mountain passages that only allow a diagonal move, such passages are possible. Followers know how to navigate them, and do.&lt;br /&gt;
&lt;br /&gt;
There is no practical limit on treasure chests (&amp;quot;loot boxes&amp;quot;), since what&#039;s in them is determined at random when they are open. However, limited numbers of followers and dwellings are allowed per continent, and these limits are smaller than the nominal array dimensions in the [[King&#039;s Bounty Saved game Format|save file]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Modding ==&lt;br /&gt;
&lt;br /&gt;
Note that there is no &amp;lt;code&amp;gt;land.org&amp;lt;/code&amp;gt; in the 1990 game edition -- to play on a custom map, you have to modify the [[King&#039;s Bounty Saved game Format|save file]] itself, possibly also modifying the [[King&#039;s Bounty Index Tables|lookup tables in KB.EXE]].&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;br /&gt;
&lt;br /&gt;
The constraints have been contributed by the [https://github.com/treeswift/royalreward Royal Reward] project.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=File:King%27s_Bounty_Map_Format.png&amp;diff=11624</id>
		<title>File:King&#039;s Bounty Map Format.png</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=File:King%27s_Bounty_Map_Format.png&amp;diff=11624"/>
		<updated>2024-01-25T05:30:10Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: Alternative Saharia. Own work (map generator), public domain.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Alternative Saharia. Own work (map generator), public domain.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Map_Format&amp;diff=11623</id>
		<title>King&#039;s Bounty Map Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Map_Format&amp;diff=11623"/>
		<updated>2024-01-25T05:26:18Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: terrain type named incorrectly&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Map Infobox&lt;br /&gt;
 | Type = 2D tile-based&lt;br /&gt;
 | Games =&lt;br /&gt;
   {{Game|King&#039;s Bounty}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This format is used to store the world map for [[King&#039;s Bounty]] in both it&#039;s initial state (&amp;lt;tt&amp;gt;LAND.ORG&amp;lt;/tt&amp;gt; file) and in modified, randomized state (in the &amp;lt;tt&amp;gt;*.DAT&amp;lt;/tt&amp;gt; save files at offset &amp;lt;tt&amp;gt;0xFC5&amp;lt;/tt&amp;gt;). Consequently, there are minor format differences, described below.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The map always takes exactly 16384 bytes. As there are 4 continents 64 x 64 tiles each, and each tile takes 1 byte, all continents start at a convenient offset - 0x0000, 0x1000, 0x2000 or 0x3000.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]] map[4][64][64]||Map data&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Coordinates ===&lt;br /&gt;
&lt;br /&gt;
The game is consistent with it&#039;s map coordinate system, which goes in the &#039;&#039;&#039;bottom-to-top&#039;&#039;&#039;, left-to-right order. That means top left corner has coordinate X=0, Y=63.&lt;br /&gt;
&lt;br /&gt;
=== Salting ===&lt;br /&gt;
&lt;br /&gt;
When a new game is first created, the initial map data is read and then the following values are replaced:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0xFF - continent start           -&amp;gt; 0x20 - sea tile&lt;br /&gt;
0x8B - put something random here -&amp;gt; 0x8B - 0x93 , but not 0x90&lt;br /&gt;
0x8E - archmage&#039;s alcove         -&amp;gt; 0x00 (for mages) / 0x8E (for rest)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note, that the &amp;lt;tt&amp;gt;0x8B&amp;lt;/tt&amp;gt; index is used in both initial and salted data with different meanings - it stands for &#039;&#039;random object&#039;&#039; in &amp;lt;tt&amp;gt;LAND.ORG&amp;lt;/tt&amp;gt;, and a &#039;&#039;treasure chest&#039;&#039; in the save files. &lt;br /&gt;
&lt;br /&gt;
=== Tileset ===&lt;br /&gt;
&lt;br /&gt;
The tileset is kept inside the &amp;lt;tt&amp;gt;tileseta.*&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;tilesetb.*&amp;lt;/tt&amp;gt; graphic files. Each file contains 36 tiles, making 72 in total. &#039;&#039;Additionally, &amp;lt;tt&amp;gt;tilesalt.*&amp;lt;/tt&amp;gt; contains replacements graphics for tiles &amp;lt;tt&amp;gt;0x11-0x13&amp;lt;/tt&amp;gt; for continents 2-4&#039;&#039;. Each level byte &#039;&#039;&#039;with it&#039;s most significant bit cleared&#039;&#039;&#039; maps directly into that range (&amp;lt;tt&amp;gt;0x00-0x47&amp;lt;/tt&amp;gt;). The high bit signifies if the tile is interactive, and those high-bit versions are always used instead of the regular indexes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0x80 - magic barrier (blocks followers)&lt;br /&gt;
0x85 - castle gate&lt;br /&gt;
0x8A - town&lt;br /&gt;
0x8B - treasure chest&lt;br /&gt;
0x8C - plains dwelling&lt;br /&gt;
0x8D - forest dwelling&lt;br /&gt;
0x8E - cave dwelling (multiple purposes)&lt;br /&gt;
0x8F - dungeon dwelling&lt;br /&gt;
0x90 - sign&lt;br /&gt;
0x91 - follower&lt;br /&gt;
0x92 - artifact 1&lt;br /&gt;
0x93 - artifact 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constant Locations ===&lt;br /&gt;
&lt;br /&gt;
Those locations are hard-coded into the game and can not be changed from within the map:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
X=11 Y=7  - King&#039;s Castle&lt;br /&gt;
X=11 Y=6  - Retreat location&lt;br /&gt;
X=11 Y=5  - Starting Location&lt;br /&gt;
X=11 Y=3  - Continent 1 starting location&lt;br /&gt;
X=1  Y=37 - Continent 2 starting location&lt;br /&gt;
X=14 Y=62 - Continent 3 starting location&lt;br /&gt;
X=9  Y=1  - Continent 4 starting location&lt;br /&gt;
X=11 Y=19 - Archmage&#039;s Alcove&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The king&#039;s castle coordinates are the last extra element of the [[King&#039;s Bounty Index Tables|castle location table]].&lt;br /&gt;
&lt;br /&gt;
== Constraints ==&lt;br /&gt;
&lt;br /&gt;
Remember that while it&#039;s possible to place any combination of the tiles on the map, not all of those combinations will be consistent:&lt;br /&gt;
&lt;br /&gt;
# Town square and castle gate locations need to be placed in the game&#039;s [[King&#039;s Bounty Index Tables|lookup tables]] to be interactive.&lt;br /&gt;
# If a desert tile is placed near the ocean tile, it&#039;s possible to pull the boat onto the beach and row it across the desert. Each step still takes a day. If this is not a desired effect, separate the desert from the sea with any other terrain (typically, road).&lt;br /&gt;
# Of terrain tiles, only the road tile (&amp;lt;tt&amp;gt;0x0&amp;lt;/tt&amp;gt;) can &amp;quot;seamlessly neighbor&amp;quot; both its own and all other terrains. Other terrain types (sea, desert, mountains and woods) have a &amp;quot;solid&amp;quot; tile (&amp;lt;tt&amp;gt;0x20&amp;lt;/tt&amp;gt; for the sea, &amp;lt;tt&amp;gt;0x2d&amp;lt;/tt&amp;gt; for the woods, &amp;lt;tt&amp;gt;0x3a&amp;lt;/tt&amp;gt; for the desert and &amp;lt;tt&amp;gt;0x47&amp;lt;/tt&amp;gt; for the mountains) that can only neighbor its own terrain and 12 border tiles.&lt;br /&gt;
&lt;br /&gt;
The following code example creates the tile code correction table for border tiles. The correction is added to the code of the respective solid tile:&lt;br /&gt;
&lt;br /&gt;
        constexpr int lb = 1, rb = 2, lt = 4, rt = 8;&lt;br /&gt;
        cor_sea.resize(0x10, 0); // all 16 combinations, though only 13 are supported&lt;br /&gt;
        cor_sea[lt | rt] = -1; // ▀&lt;br /&gt;
        cor_sea[lb | rb] = -2; // ▄&lt;br /&gt;
        cor_sea[rt | rb] = -3; // ▐&lt;br /&gt;
        cor_sea[lt | lb] = -4; // ▌&lt;br /&gt;
        cor_sea[rt | rb | lb] = -5; // ▟&lt;br /&gt;
        cor_sea[lt | rt | rb] = -6; // ▜&lt;br /&gt;
        cor_sea[rb | lb | lt] = -7; // ▙&lt;br /&gt;
        cor_sea[rt | lt | lb] = -8; // ▛&lt;br /&gt;
        cor_sea[lt] = -9;  // ▘&lt;br /&gt;
        cor_sea[lb] = -12; // ▖&lt;br /&gt;
        cor_sea[rt] = -10; // ▝&lt;br /&gt;
        cor_sea[rb] = -11; // ▗&lt;br /&gt;
        cor_for = cor_sea; // sea tiles have a special ordering&lt;br /&gt;
        cor_for[lb] = -10; // ▖&lt;br /&gt;
        cor_for[rt] = -11; // ▝&lt;br /&gt;
        cor_for[rb] = -12; // ▗&lt;br /&gt;
        cor_snd = cor_mnt = cor_for; // sands, mountains, and forest follow a common order&lt;br /&gt;
&lt;br /&gt;
Generally, every tile of a special terrain (sands, mountains, woods or sea) must be a part of at least one 2x2 patch of the same terrain — i.e., e.g., an isolated 1x1 patch of desert can&#039;t be displayed correctly. In addition, diagonal combinations (e.g. a sea tile that&#039;s neighboring a sea — i.e. is a part of a 2x2 sea square — to the northeast and southwest, but not to the northwest and southeast, *and has to be a part of both*&amp;lt;ref&amp;gt;Adjacent tiles of the same terrain can still be displayed as if they belonged to disconnected spans of it — look at the fractured desert between Nyre and Xoctan to see what I mean&amp;lt;/ref&amp;gt;) can&#039;t be displayed correctly, either. E.g. consider the following screen:&lt;br /&gt;
&lt;br /&gt;
 sea1 sea1 land&lt;br /&gt;
 sea1 sea* sea2&lt;br /&gt;
 land sea2 sea2&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sea*&amp;lt;/tt&amp;gt; tile can be a part of either the 2x2 &amp;lt;tt&amp;gt;sea1&amp;lt;/tt&amp;gt; patch or the 2x2 &amp;lt;tt&amp;gt;sea2&amp;lt;/tt&amp;gt; patch. If &amp;lt;tt&amp;gt;sea1&amp;lt;/tt&amp;gt; is a part of a greater ocean, then &amp;lt;tt&amp;gt;sea1&amp;lt;/tt&amp;gt; tiles can be displayed as its border tiles and &amp;lt;tt&amp;gt;sea*&amp;lt;/tt&amp;gt; form a block with &amp;lt;tt&amp;gt;sea2&amp;lt;/tt&amp;gt; (ditto if &amp;lt;tt&amp;gt;sea2&amp;lt;/tt&amp;gt; is a larger sea). If the sea tiles on the screen show a complete lake, there is no way to take the central tile out of either part of the lake without breaking the 2x2 rule.&lt;br /&gt;
&lt;br /&gt;
With narrow diagonal straits the limitation can be mitigated by displaying one of the corners cut off; it looks less crappy than displaying a solid tile (e.g. the &amp;lt;tt&amp;gt;sea*&amp;lt;/tt&amp;gt; tile above can have either a northeast or a southwest land corner, but not both). With forest tiles, ignoring inconsistent bottom corners produces slightly better looks than ignoring the top ones. Ideally, however, your generator and/or map editor should not allow graphically inconsistent tiles to border each other.&lt;br /&gt;
&lt;br /&gt;
Note that while original maps don&#039;t have narrow forest/mountain passages that only allow a diagonal move, such passages are possible. Followers know how to navigate them, and do.&lt;br /&gt;
&lt;br /&gt;
There is no practical limit on treasure chests (&amp;quot;loot boxes&amp;quot;), since what&#039;s in them is determined at random when they are open. However, limited numbers of followers and dwellings are allowed per continent, and these limits are smaller than the nominal array dimensions in the [[King&#039;s Bounty Saved game Format|save file]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=11622</id>
		<title>King&#039;s Bounty Saved game Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=11622"/>
		<updated>2024-01-25T03:48:53Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: Coordinate indices&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Playerdata Infobox&lt;br /&gt;
 | Savegame = Yes&lt;br /&gt;
 | Elements = Many&lt;br /&gt;
 | Games =&lt;br /&gt;
   {{Game|King&#039;s Bounty}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This format is used to save the whole game state for [[King&#039;s Bounty]].&lt;br /&gt;
&lt;br /&gt;
As the save files do not require re-insertion into group files, nor are compressed, yet maintain their own full copies of the game world, they provide good opportunity to distribute custom levels or maps.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
A save always takes exactly 20421 bytes. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0x000 - 0x00A   | name&lt;br /&gt;
0x00B           | class&lt;br /&gt;
0x00C           | rank&lt;br /&gt;
0x00D           | spell power&lt;br /&gt;
0x00E           | max # of spells&lt;br /&gt;
0x00F - 0x01F   | is villain N caught&lt;br /&gt;
0x020 - 0x027   | is artifact N found&lt;br /&gt;
0x028 - 0x02B   | is continent N available&lt;br /&gt;
0x02C - 0x02F   | is orb N found&lt;br /&gt;
0x030 - 0x03D   | number of spells N&lt;br /&gt;
0x03E           | knows magic &lt;br /&gt;
0x03F           | siege weapons&lt;br /&gt;
0x040           | current contract&lt;br /&gt;
0x041 - 0x045   | hero army&lt;br /&gt;
0x046           | Option: Delay (0-9) &lt;br /&gt;
0x047           | difficulty&lt;br /&gt;
0x048           | Option: Sounds&lt;br /&gt;
0x049           | Option: Walk Beep&lt;br /&gt;
0x04A           | Option: Animation&lt;br /&gt;
0x04B           | Option: Show Army Size&lt;br /&gt;
0x04C           | hero continent&lt;br /&gt;
0x04D           | hero X			&lt;br /&gt;
0x04E           | hero Y&lt;br /&gt;
0x04F           | last X&lt;br /&gt;
0x050           | last Y&lt;br /&gt;
0x051           | boat X&lt;br /&gt;
0x052           | boat Y&lt;br /&gt;
0x053           | boat continent (0xFF - no boat)&lt;br /&gt;
0x054           | mount mode (0x00 - boat, 0x04 - fly, 0x08 - horse)&lt;br /&gt;
0x055           | Option: CGA palette&lt;br /&gt;
0x056 - 0x069   | spell sold in town N&lt;br /&gt;
0x070 - 0x074   | contract cycle (5 villains)&lt;br /&gt;
0x075           | last contract (starts as 0x04 to flip to 0x00 on first run)&lt;br /&gt;
0x076           | max contract (starts as 0x05)&lt;br /&gt;
0x077           | steps left (until end of day; never becomes 0, always refills to 0x28=decimal 40)&lt;br /&gt;
0x078           | days left until the end of the week (never becomes 0, refills to 5 every new week)&lt;br /&gt;
0x079 - 0x092   | castle owned by... (0x7F = no one, 0xFF = you, LOW 5 bits = villain)&lt;br /&gt;
0x093 - 0x0AC   | visited castle N&lt;br /&gt;
0x0AD - 0x0C6   | visited town N&lt;br /&gt;
0x0C7           | scepter continent (&#039;encrypted&#039;)&lt;br /&gt;
0x0C8           | scepter X (&#039;encrypted&#039;)&lt;br /&gt;
0x0C9           | scepter Y (&#039;encrypted&#039;)&lt;br /&gt;
0x0CA - 0x8C9   | fog of war (1bpp)&lt;br /&gt;
0x8CA - 0x94B   | garrison troops &lt;br /&gt;
0x94C - 0x973   | foeF coords (2 bytes each, 5 per continent)&lt;br /&gt;
0x974 - 0x979   | map chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x97a - 0x981   | orb chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x982 - 0x991   | teleporter coords (2 bytes each, 2 per continent)&lt;br /&gt;
0x992 - 0x9E9   | dwelling coords (2 bytes each, 11 per continent)&lt;br /&gt;
0x9EA - 0xB01   | foeH coords (2 bytes each, 35 per continent)&lt;br /&gt;
0xB02 - 0xCA5   | foeH troops (3 bytes each)&lt;br /&gt;
0xCA6 - 0xE49   | foeH numbers (3 bytes each)&lt;br /&gt;
0xE4A - 0xE75   | dwelling N troop&lt;br /&gt;
0xE76 - 0xEA1   | dwelling N population&lt;br /&gt;
0xEA2           | scepter key (to XOR scepter coords with)&lt;br /&gt;
0xEA3 - 0xEA4   | base leadership&lt;br /&gt;
0xEA5 - 0xEA6   | leadership&lt;br /&gt;
0xEA7 - 0xEA8   | commission&lt;br /&gt;
0xEA9 -	0xEAA   | followers killed&lt;br /&gt;
0xEAB - 0xEB4   | hero army numbers&lt;br /&gt;
0xEB5 - 0xFB8   | garrison numbers &lt;br /&gt;
0xFB9 - 0xFBA   | time stop (&amp;quot;free&amp;quot; steps left)&lt;br /&gt;
0xFBB - 0xFBC   | days left&lt;br /&gt;
0xFBD - 0xFBE   | score (never actually used)&lt;br /&gt;
0xFBF           | ? // unknown1, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC0           | ? // unknown2, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC1 - 0xFC4   | gold&lt;br /&gt;
0xFC5 - END     | map dump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- TODO: proper mediawiki table --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Player name is padded with spaces&lt;br /&gt;
* There are 26 castles, 26 towns, 17 villains, 25 troops, 14 spells and 4 continents in the game.&lt;br /&gt;
* Coordinates always take 2 bytes and always go in X, Y order.&lt;br /&gt;
* Scepter coordinates are XORed with &#039;&#039;scepter key&#039;&#039; upon load/save.&lt;br /&gt;
* Troop and villain indexes are in production order (as seen in .CC files).&lt;br /&gt;
* Dwelling populations are kept in [[BYTE]]s, 250 being maximum possible value.&lt;br /&gt;
* Hero and castle army numbers are kept in [[UINT16LE]]s, 5 per army.&lt;br /&gt;
* Hostile foes only have 3 troops and their numbers are kept in [[BYTE]]s.&lt;br /&gt;
* The &#039;&#039;mount mode&#039;&#039; is also an offset into hero&#039;s sprite-sheet.&lt;br /&gt;
* The map is a complete dump in [[King&#039;s Bounty Map Format]].&lt;br /&gt;
&lt;br /&gt;
=== Coordinates ===&lt;br /&gt;
&lt;br /&gt;
The game is consistent with it&#039;s map coordinate system, which goes in the &#039;&#039;&#039;bottom-to-top&#039;&#039;&#039;, left-to-right order. That means top left corner has coordinate X=0, Y=63.&lt;br /&gt;
&lt;br /&gt;
=== Limitations ===&lt;br /&gt;
&lt;br /&gt;
Dwellings and followers must be sorted in ascending &amp;lt;code&amp;gt;&amp;lt;Y, then X&amp;gt;&amp;lt;/code&amp;gt; coordinate order to allow fast binary search. Breaking the order causes the game to &amp;quot;miss&amp;quot; some of them, handling them incorrectly. (Illegal dwellings cause the game to hang when entered, and illegal roaming gangs don&#039;t automatically follow the hero and don&#039;t display unit sizes when confronted.)&lt;br /&gt;
&lt;br /&gt;
The numbers of followers and dwellings on each continent are limited independently. Filling the dwelling and follower tables up to their declared array dimensions causes the game to freeze when the hero tries to confront a follower or enter a dwelling that&#039;s located too far to the north (in the greater Y coordinate direction). At least the following values are safe:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Continent!!Followers!!Dwellings&lt;br /&gt;
|-&lt;br /&gt;
|0=Continentia||35||11&lt;br /&gt;
|-&lt;br /&gt;
|1=Forestria||27||10&lt;br /&gt;
|-&lt;br /&gt;
|2=Archipelia||10||8&lt;br /&gt;
|-&lt;br /&gt;
|3=Saharia||15||7&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Un-filled coordinate array positions have X=0, Y=0.&lt;br /&gt;
&lt;br /&gt;
More (or fewer) sign poles can be placed on the map, but each continent&#039;s offset into the global &amp;quot;posted messages&amp;quot; table is fixed. For example, there are 22 sign poles in Continentia. If you place a 23rd one, they will be re-indexed (in the &amp;lt;code&amp;gt;Y, then X&amp;lt;/code&amp;gt; order) when the saved file is read, and the north-northeastern-most one will display the same message as the south-southwestern-most one in Forestria. However, the number of sign poles in Continentia does not affect offsets to messages (and, therefore, messages themselves) displayed by the sign poles in Forestria.&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=11621</id>
		<title>King&#039;s Bounty Saved game Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=11621"/>
		<updated>2024-01-25T03:47:44Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: Lookup table sizes and limitations on saved game files&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Playerdata Infobox&lt;br /&gt;
 | Savegame = Yes&lt;br /&gt;
 | Elements = Many&lt;br /&gt;
 | Games =&lt;br /&gt;
   {{Game|King&#039;s Bounty}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This format is used to save the whole game state for [[King&#039;s Bounty]].&lt;br /&gt;
&lt;br /&gt;
As the save files do not require re-insertion into group files, nor are compressed, yet maintain their own full copies of the game world, they provide good opportunity to distribute custom levels or maps.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
A save always takes exactly 20421 bytes. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0x000 - 0x00A   | name&lt;br /&gt;
0x00B           | class&lt;br /&gt;
0x00C           | rank&lt;br /&gt;
0x00D           | spell power&lt;br /&gt;
0x00E           | max # of spells&lt;br /&gt;
0x00F - 0x01F   | is villain N caught&lt;br /&gt;
0x020 - 0x027   | is artifact N found&lt;br /&gt;
0x028 - 0x02B   | is continent N available&lt;br /&gt;
0x02C - 0x02F   | is orb N found&lt;br /&gt;
0x030 - 0x03D   | number of spells N&lt;br /&gt;
0x03E           | knows magic &lt;br /&gt;
0x03F           | siege weapons&lt;br /&gt;
0x040           | current contract&lt;br /&gt;
0x041 - 0x045   | hero army&lt;br /&gt;
0x046           | Option: Delay (0-9) &lt;br /&gt;
0x047           | difficulty&lt;br /&gt;
0x048           | Option: Sounds&lt;br /&gt;
0x049           | Option: Walk Beep&lt;br /&gt;
0x04A           | Option: Animation&lt;br /&gt;
0x04B           | Option: Show Army Size&lt;br /&gt;
0x04C           | hero continent&lt;br /&gt;
0x04D           | hero X			&lt;br /&gt;
0x04E           | hero Y&lt;br /&gt;
0x04F           | last X&lt;br /&gt;
0x050           | last Y&lt;br /&gt;
0x051           | boat X&lt;br /&gt;
0x052           | boat Y&lt;br /&gt;
0x053           | boat continent (0xFF - no boat)&lt;br /&gt;
0x054           | mount mode (0x00 - boat, 0x04 - fly, 0x08 - horse)&lt;br /&gt;
0x055           | Option: CGA palette&lt;br /&gt;
0x056 - 0x069   | spell sold in town N&lt;br /&gt;
0x070 - 0x074   | contract cycle (5 villains)&lt;br /&gt;
0x075           | last contract (starts as 0x04 to flip to 0x00 on first run)&lt;br /&gt;
0x076           | max contract (starts as 0x05)&lt;br /&gt;
0x077           | steps left (until end of day; never becomes 0, always refills to 0x28=decimal 40)&lt;br /&gt;
0x078           | days left until the end of the week (never becomes 0, refills to 5 every new week)&lt;br /&gt;
0x079 - 0x092   | castle owned by... (0x7F = no one, 0xFF = you, LOW 5 bits = villain)&lt;br /&gt;
0x093 - 0x0AC   | visited castle N&lt;br /&gt;
0x0AD - 0x0C6   | visited town N&lt;br /&gt;
0x0C7           | scepter continent (&#039;encrypted&#039;)&lt;br /&gt;
0x0C8           | scepter X (&#039;encrypted&#039;)&lt;br /&gt;
0x0C9           | scepter Y (&#039;encrypted&#039;)&lt;br /&gt;
0x0CA - 0x8C9   | fog of war (1bpp)&lt;br /&gt;
0x8CA - 0x94B   | garrison troops &lt;br /&gt;
0x94C - 0x973   | foeF coords (2 bytes each, 5 per continent)&lt;br /&gt;
0x974 - 0x979   | map chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x97a - 0x981   | orb chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x982 - 0x991   | teleporter coords (2 bytes each, 2 per continent)&lt;br /&gt;
0x992 - 0x9E9   | dwelling coords (2 bytes each, 11 per continent)&lt;br /&gt;
0x9EA - 0xB01   | foeH coords (2 bytes each, 35 per continent)&lt;br /&gt;
0xB02 - 0xCA5   | foeH troops (3 bytes each)&lt;br /&gt;
0xCA6 - 0xE49   | foeH numbers (3 bytes each)&lt;br /&gt;
0xE4A - 0xE75   | dwelling N troop&lt;br /&gt;
0xE76 - 0xEA1   | dwelling N population&lt;br /&gt;
0xEA2           | scepter key (to XOR scepter coords with)&lt;br /&gt;
0xEA3 - 0xEA4   | base leadership&lt;br /&gt;
0xEA5 - 0xEA6   | leadership&lt;br /&gt;
0xEA7 - 0xEA8   | commission&lt;br /&gt;
0xEA9 -	0xEAA   | followers killed&lt;br /&gt;
0xEAB - 0xEB4   | hero army numbers&lt;br /&gt;
0xEB5 - 0xFB8   | garrison numbers &lt;br /&gt;
0xFB9 - 0xFBA   | time stop (&amp;quot;free&amp;quot; steps left)&lt;br /&gt;
0xFBB - 0xFBC   | days left&lt;br /&gt;
0xFBD - 0xFBE   | score (never actually used)&lt;br /&gt;
0xFBF           | ? // unknown1, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC0           | ? // unknown2, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC1 - 0xFC4   | gold&lt;br /&gt;
0xFC5 - END     | map dump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- TODO: proper mediawiki table --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Player name is padded with spaces&lt;br /&gt;
* There are 26 castles, 26 towns, 17 villains, 25 troops, 14 spells and 4 continents in the game.&lt;br /&gt;
* Coordinates always take 2 bytes and always go in X, Y order.&lt;br /&gt;
* Scepter coordinates are XORed with &#039;&#039;scepter key&#039;&#039; upon load/save.&lt;br /&gt;
* Troop and villain indexes are in production order (as seen in .CC files).&lt;br /&gt;
* Dwelling populations are kept in [[BYTE]]s, 250 being maximum possible value.&lt;br /&gt;
* Hero and castle army numbers are kept in [[UINT16LE]]s, 5 per army.&lt;br /&gt;
* Hostile foes only have 3 troops and their numbers are kept in [[BYTE]]s.&lt;br /&gt;
* The &#039;&#039;mount mode&#039;&#039; is also an offset into hero&#039;s sprite-sheet.&lt;br /&gt;
* The map is a complete dump in [[King&#039;s Bounty Map Format]].&lt;br /&gt;
&lt;br /&gt;
=== Coordinates ===&lt;br /&gt;
&lt;br /&gt;
The game is consistent with it&#039;s map coordinate system, which goes in the &#039;&#039;&#039;bottom-to-top&#039;&#039;&#039;, left-to-right order. That means top left corner has coordinate X=0, Y=63.&lt;br /&gt;
&lt;br /&gt;
=== Limitations ===&lt;br /&gt;
&lt;br /&gt;
Dwellings and followers must be sorted in ascending &amp;lt;code&amp;gt;&amp;lt;Y, then X&amp;gt;&amp;lt;/code&amp;gt; coordinate order to allow fast binary search. Breaking the order causes the game to &amp;quot;miss&amp;quot; some of them, handling them incorrectly. (Illegal dwellings cause the game to hang when entered, and illegal roaming gangs don&#039;t automatically follow the hero and don&#039;t display unit sizes when confronted.)&lt;br /&gt;
&lt;br /&gt;
The numbers of followers and dwellings on each continent are limited independently. Filling the dwelling and follower tables up to their declared array dimensions causes the game to freeze when the hero tries to confront a follower or enter a dwelling that&#039;s located too far to the north (in the greater Y coordinate direction). At least the following values are safe:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Continent!!Followers!!Dwellings&lt;br /&gt;
|-&lt;br /&gt;
|0=Continentia||35||11&lt;br /&gt;
|-&lt;br /&gt;
|0=Forestria||27||10&lt;br /&gt;
|-&lt;br /&gt;
|0=Archipelia||10||8&lt;br /&gt;
|-&lt;br /&gt;
|0=Saharia||15||7&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Un-filled coordinate array positions have X=0, Y=0.&lt;br /&gt;
&lt;br /&gt;
More (or fewer) sign poles can be placed on the map, but each continent&#039;s offset into the global &amp;quot;posted messages&amp;quot; table is fixed. For example, there are 22 sign poles in Continentia. If you place a 23rd one, they will be re-indexed (in the &amp;lt;code&amp;gt;Y, then X&amp;lt;/code&amp;gt; order) when the saved file is read, and the north-northeastern-most one will display the same message as the south-southwestern-most one in Forestria. However, the number of sign poles in Continentia does not affect offsets to messages (and, therefore, messages themselves) displayed by the sign poles in Forestria.&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Map_Format&amp;diff=11620</id>
		<title>King&#039;s Bounty Map Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Map_Format&amp;diff=11620"/>
		<updated>2024-01-25T03:34:08Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: Level map consistency constraints&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Map Infobox&lt;br /&gt;
 | Type = 2D tile-based&lt;br /&gt;
 | Games =&lt;br /&gt;
   {{Game|King&#039;s Bounty}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This format is used to store the world map for [[King&#039;s Bounty]] in both it&#039;s initial state (&amp;lt;tt&amp;gt;LAND.ORG&amp;lt;/tt&amp;gt; file) and in modified, randomized state (in the &amp;lt;tt&amp;gt;*.DAT&amp;lt;/tt&amp;gt; save files at offset &amp;lt;tt&amp;gt;0xFC5&amp;lt;/tt&amp;gt;). Consequently, there are minor format differences, described below.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
The map always takes exactly 16384 bytes. As there are 4 continents 64 x 64 tiles each, and each tile takes 1 byte, all continents start at a convenient offset - 0x0000, 0x1000, 0x2000 or 0x3000.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Data type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|[[BYTE]] map[4][64][64]||Map data&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Coordinates ===&lt;br /&gt;
&lt;br /&gt;
The game is consistent with it&#039;s map coordinate system, which goes in the &#039;&#039;&#039;bottom-to-top&#039;&#039;&#039;, left-to-right order. That means top left corner has coordinate X=0, Y=63.&lt;br /&gt;
&lt;br /&gt;
=== Salting ===&lt;br /&gt;
&lt;br /&gt;
When a new game is first created, the initial map data is read and then the following values are replaced:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0xFF - continent start           -&amp;gt; 0x20 - sea tile&lt;br /&gt;
0x8B - put something random here -&amp;gt; 0x8B - 0x93 , but not 0x90&lt;br /&gt;
0x8E - archmage&#039;s alcove         -&amp;gt; 0x00 (for mages) / 0x8E (for rest)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note, that the &amp;lt;tt&amp;gt;0x8B&amp;lt;/tt&amp;gt; index is used in both initial and salted data with different meanings - it stands for &#039;&#039;random object&#039;&#039; in &amp;lt;tt&amp;gt;LAND.ORG&amp;lt;/tt&amp;gt;, and a &#039;&#039;treasure chest&#039;&#039; in the save files. &lt;br /&gt;
&lt;br /&gt;
=== Tileset ===&lt;br /&gt;
&lt;br /&gt;
The tileset is kept inside the &amp;lt;tt&amp;gt;tileseta.*&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;tilesetb.*&amp;lt;/tt&amp;gt; graphic files. Each file contains 36 tiles, making 72 in total. &#039;&#039;Additionally, &amp;lt;tt&amp;gt;tilesalt.*&amp;lt;/tt&amp;gt; contains replacements graphics for tiles &amp;lt;tt&amp;gt;0x11-0x13&amp;lt;/tt&amp;gt; for continents 2-4&#039;&#039;. Each level byte &#039;&#039;&#039;with it&#039;s most significant bit cleared&#039;&#039;&#039; maps directly into that range (&amp;lt;tt&amp;gt;0x00-0x47&amp;lt;/tt&amp;gt;). The high bit signifies if the tile is interactive, and those high-bit versions are always used instead of the regular indexes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0x80 - magic barrier (blocks followers)&lt;br /&gt;
0x85 - castle gate&lt;br /&gt;
0x8A - town&lt;br /&gt;
0x8B - treasure chest&lt;br /&gt;
0x8C - plains dwelling&lt;br /&gt;
0x8D - forest dwelling&lt;br /&gt;
0x8E - cave dwelling (multiple purposes)&lt;br /&gt;
0x8F - dungeon dwelling&lt;br /&gt;
0x90 - sign&lt;br /&gt;
0x91 - follower&lt;br /&gt;
0x92 - artifact 1&lt;br /&gt;
0x93 - artifact 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constant Locations ===&lt;br /&gt;
&lt;br /&gt;
Those locations are hard-coded into the game and can not be changed from within the map:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
X=11 Y=7  - King&#039;s Castle&lt;br /&gt;
X=11 Y=6  - Retreat location&lt;br /&gt;
X=11 Y=5  - Starting Location&lt;br /&gt;
X=11 Y=3  - Continent 1 starting location&lt;br /&gt;
X=1  Y=37 - Continent 2 starting location&lt;br /&gt;
X=14 Y=62 - Continent 3 starting location&lt;br /&gt;
X=9  Y=1  - Continent 4 starting location&lt;br /&gt;
X=11 Y=19 - Archmage&#039;s Alcove&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The king&#039;s castle coordinates are the last extra element of the [[King&#039;s Bounty Index Tables|castle location table]].&lt;br /&gt;
&lt;br /&gt;
== Constraints ==&lt;br /&gt;
&lt;br /&gt;
Remember that while it&#039;s possible to place any combination of the tiles on the map, not all of those combinations will be consistent:&lt;br /&gt;
&lt;br /&gt;
# Town square and castle gate locations need to be placed in the game&#039;s [[King&#039;s Bounty Index Tables|lookup tables]] to be interactive.&lt;br /&gt;
# If a desert tile is placed near the ocean tile, it&#039;s possible to pull the boat onto the beach and row it across the desert. Each step still takes a day. If this is not a desired effect, separate the desert from the sea with any other terrain (typically, road).&lt;br /&gt;
# Of terrain tiles, only the road tile (&amp;lt;tt&amp;gt;0x0&amp;lt;/tt&amp;gt;) can &amp;quot;seamlessly neighbor&amp;quot; both its own and all other terrains. Other terrain types (sea, desert, mountains and woods) have a &amp;quot;solid&amp;quot; tile (&amp;lt;tt&amp;gt;0x20&amp;lt;/tt&amp;gt; for the sea, &amp;lt;tt&amp;gt;0x2d&amp;lt;/tt&amp;gt; for the woods, &amp;lt;tt&amp;gt;0x3a&amp;lt;/tt&amp;gt; for the desert and &amp;lt;tt&amp;gt;0x47&amp;lt;/tt&amp;gt; for the mountains) that can only neighbor its own terrain and 12 border tiles.&lt;br /&gt;
&lt;br /&gt;
The following code example creates the tile code correction table for border tiles. The correction is added to the code of the respective solid tile:&lt;br /&gt;
&lt;br /&gt;
        constexpr int lb = 1, rb = 2, lt = 4, rt = 8;&lt;br /&gt;
        cor_sea.resize(0x10, 0); // all 16 combinations, though only 13 are supported&lt;br /&gt;
        cor_sea[lt | rt] = -1; // ▀&lt;br /&gt;
        cor_sea[lb | rb] = -2; // ▄&lt;br /&gt;
        cor_sea[rt | rb] = -3; // ▐&lt;br /&gt;
        cor_sea[lt | lb] = -4; // ▌&lt;br /&gt;
        cor_sea[rt | rb | lb] = -5; // ▟&lt;br /&gt;
        cor_sea[lt | rt | rb] = -6; // ▜&lt;br /&gt;
        cor_sea[rb | lb | lt] = -7; // ▙&lt;br /&gt;
        cor_sea[rt | lt | lb] = -8; // ▛&lt;br /&gt;
        cor_sea[lt] = -9;  // ▘&lt;br /&gt;
        cor_sea[lb] = -12; // ▖&lt;br /&gt;
        cor_sea[rt] = -10; // ▝&lt;br /&gt;
        cor_sea[rb] = -11; // ▗&lt;br /&gt;
        cor_for = cor_sea; // sea tiles have a special ordering&lt;br /&gt;
        cor_for[lb] = -10; // ▖&lt;br /&gt;
        cor_for[rt] = -11; // ▝&lt;br /&gt;
        cor_for[rb] = -12; // ▗&lt;br /&gt;
        cor_snd = cor_mnt = cor_for; // sands, mountains, and forest follow a common order&lt;br /&gt;
&lt;br /&gt;
Generally, every tile of a special terrain (sands, mountains, woods and road) must be a part of at least one 2x2 patch of the same terrain — i.e., e.g., an isolated 1x1 patch of desert can&#039;t be displayed correctly. In addition, diagonal combinations (e.g. a sea tile that&#039;s neighboring a sea — i.e. is a part of a 2x2 sea square — to the northeast and southwest, but not to the northwest and southeast, *and has to be a part of both*&amp;lt;ref&amp;gt;Adjacent tiles of the same terrain can still be displayed as if they belonged to disconnected spans of it — look at the fractured desert between Nyre and Xoctan to see what I mean&amp;lt;/ref&amp;gt;) can&#039;t be displayed correctly, either. E.g. consider the following screen:&lt;br /&gt;
&lt;br /&gt;
 sea1 sea1 land&lt;br /&gt;
 sea1 sea* sea2&lt;br /&gt;
 land sea2 sea2&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sea*&amp;lt;/tt&amp;gt; tile can be a part of either the 2x2 &amp;lt;tt&amp;gt;sea1&amp;lt;/tt&amp;gt; patch or the 2x2 &amp;lt;tt&amp;gt;sea2&amp;lt;/tt&amp;gt; patch. If &amp;lt;tt&amp;gt;sea1&amp;lt;/tt&amp;gt; is a part of a greater ocean, then &amp;lt;tt&amp;gt;sea1&amp;lt;/tt&amp;gt; tiles can be displayed as its border tiles and &amp;lt;tt&amp;gt;sea*&amp;lt;/tt&amp;gt; form a block with &amp;lt;tt&amp;gt;sea2&amp;lt;/tt&amp;gt; (ditto if &amp;lt;tt&amp;gt;sea2&amp;lt;/tt&amp;gt; is a larger sea). If the sea tiles on the screen show a complete lake, there is no way to take the central tile out of either part of the lake without breaking the 2x2 rule.&lt;br /&gt;
&lt;br /&gt;
With narrow diagonal straits the limitation can be mitigated by displaying one of the corners cut off; it looks less crappy than displaying a solid tile (e.g. the &amp;lt;tt&amp;gt;sea*&amp;lt;/tt&amp;gt; tile above can have either a northeast or a southwest land corner, but not both). With forest tiles, ignoring inconsistent bottom corners produces slightly better looks than ignoring the top ones. Ideally, however, your generator and/or map editor should not allow graphically inconsistent tiles to border each other.&lt;br /&gt;
&lt;br /&gt;
Note that while original maps don&#039;t have narrow forest/mountain passages that only allow a diagonal move, such passages are possible. Followers know how to navigate them, and do.&lt;br /&gt;
&lt;br /&gt;
There is no practical limit on treasure chests (&amp;quot;loot boxes&amp;quot;), since what&#039;s in them is determined at random when they are open. However, limited numbers of followers and dwellings are allowed per continent, and these limits are smaller than the nominal array dimensions in the [[King&#039;s Bounty Saved game Format|save file]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=11619</id>
		<title>King&#039;s Bounty</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=11619"/>
		<updated>2024-01-25T02:49:04Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: Link to a modding toolset added (open source, public domain)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NeedMoreInfo}}&lt;br /&gt;
{{Game Infobox&lt;br /&gt;
 | Levels = Some&lt;br /&gt;
 | Tiles = No&lt;br /&gt;
 | Sprites = No&lt;br /&gt;
 | Fullscreen = No&lt;br /&gt;
 | Sound = No&lt;br /&gt;
 | Music = No&lt;br /&gt;
 | Text = No&lt;br /&gt;
 | Story = No&lt;br /&gt;
 | Interface = No&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{BeginGameFileList}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = 416.cc&amp;lt;br/&amp;gt;256.cc&lt;br /&gt;
 | Format = [[CC Format]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Archive files&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = *.4&amp;lt;br/&amp;gt;*.16&amp;lt;br/&amp;gt;*.256&lt;br /&gt;
 | Format = [[King&#039;s Bounty Graphics Format]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Graphics files&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = land.org&lt;br /&gt;
 | Format = [[King&#039;s Bounty Map Format]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = World map&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = *.dat&lt;br /&gt;
 | Format = [[King&#039;s Bounty Saved game Format]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Saved games&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = kb.ch&lt;br /&gt;
 | Format = Bitmap font, 8x8 1bpp&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Font&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = N/A&lt;br /&gt;
 | Format = [[King&#039;s Bounty Music Format]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Music (stored inside in &amp;lt;tt&amp;gt;KB.EXE&amp;lt;/tt&amp;gt;)&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = N/A&lt;br /&gt;
 | Format = [[King&#039;s Bounty Index Tables]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Castle/town locations and mapping (inside &amp;lt;tt&amp;gt;KB.EXE&amp;lt;/tt&amp;gt;)&lt;br /&gt;
}}&lt;br /&gt;
{{EndGameFileList}}&lt;br /&gt;
&lt;br /&gt;
== EXE compression ==&lt;br /&gt;
&lt;br /&gt;
The 1995 version of &amp;lt;tt&amp;gt;kb.exe&amp;lt;/tt&amp;gt; contains no compression. The 1990 version is compressed twice: with&lt;br /&gt;
[[Microsoft EXEPACK]] in inner layer and [[Knowledge Dynamics LZW COMPRESSOR]] in outer layer. &lt;br /&gt;
To mod this version, both compressions should be removed. Telling two versions apart is easy - uncompressed&lt;br /&gt;
exe is 113718 bytes long, while compressed takes only 79839 bytes.&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [https://sourceforge.net/p/openkb/wiki/Home/ OpenKB] - open-source clone / digital preservation project.&lt;br /&gt;
* [https://github.com/treeswift/royalreward Royal Reward] - a research/modding toolset aiming at a public domain reimplementation&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=File:Mod-King%27s_Bounty.png&amp;diff=11618</id>
		<title>File:Mod-King&#039;s Bounty.png</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=File:Mod-King%27s_Bounty.png&amp;diff=11618"/>
		<updated>2024-01-25T02:44:07Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: Playing on a custom autogenerated map. Own work, public domain.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
Playing on a custom autogenerated map. Own work, public domain.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=User:Treeswift&amp;diff=11617</id>
		<title>User:Treeswift</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=User:Treeswift&amp;diff=11617"/>
		<updated>2024-01-25T02:23:03Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: Link to modding project page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Class &amp;quot;C&amp;quot;: church, cooking, cats, concepts, coding, castles, combat, command, conquest, pedantiCism and nitpiCking.&lt;br /&gt;
&lt;br /&gt;
* Medium-term plans: researching and modding the original [[King&#039;s Bounty]]. (DoD: playing KB on a new, randomly generated map.)&lt;br /&gt;
* Long-term goals: a public domain implementation of the game mechanics. If you know your party&#039;s ext... sorry. If you know exactly how attack and retaliation damage are calculated, it would be great if you leave a comment or drop me a message.&lt;br /&gt;
&lt;br /&gt;
External link: [https://github.com/treeswift/royalreward Royal Reward (a KB map generator and modding toolset, early but already playable)]&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=11616</id>
		<title>King&#039;s Bounty</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty&amp;diff=11616"/>
		<updated>2024-01-25T02:16:59Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: Linked to castles and towns metadata page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{NeedMoreInfo}}&lt;br /&gt;
{{Game Infobox&lt;br /&gt;
 | Levels = No&lt;br /&gt;
 | Tiles = No&lt;br /&gt;
 | Sprites = No&lt;br /&gt;
 | Fullscreen = No&lt;br /&gt;
 | Sound = No&lt;br /&gt;
 | Music = No&lt;br /&gt;
 | Text = No&lt;br /&gt;
 | Story = No&lt;br /&gt;
 | Interface = No&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{BeginGameFileList}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = 416.cc&amp;lt;br/&amp;gt;256.cc&lt;br /&gt;
 | Format = [[CC Format]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Archive files&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = *.4&amp;lt;br/&amp;gt;*.16&amp;lt;br/&amp;gt;*.256&lt;br /&gt;
 | Format = [[King&#039;s Bounty Graphics Format]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Graphics files&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = land.org&lt;br /&gt;
 | Format = [[King&#039;s Bounty Map Format]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = World map&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = *.dat&lt;br /&gt;
 | Format = [[King&#039;s Bounty Saved game Format]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Saved games&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = kb.ch&lt;br /&gt;
 | Format = Bitmap font, 8x8 1bpp&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Font&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = N/A&lt;br /&gt;
 | Format = [[King&#039;s Bounty Music Format]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Music (stored inside in &amp;lt;tt&amp;gt;KB.EXE&amp;lt;/tt&amp;gt;)&lt;br /&gt;
}}&lt;br /&gt;
{{GameFile&lt;br /&gt;
 | Name = N/A&lt;br /&gt;
 | Format = [[King&#039;s Bounty Index Tables]]&lt;br /&gt;
 | KnownFormat = Yes&lt;br /&gt;
 | Desc = Castle/town locations and mapping (inside &amp;lt;tt&amp;gt;KB.EXE&amp;lt;/tt&amp;gt;)&lt;br /&gt;
}}&lt;br /&gt;
{{EndGameFileList}}&lt;br /&gt;
&lt;br /&gt;
== EXE compression ==&lt;br /&gt;
&lt;br /&gt;
The 1995 version of &amp;lt;tt&amp;gt;kb.exe&amp;lt;/tt&amp;gt; contains no compression. The 1990 version is compressed twice: with&lt;br /&gt;
[[Microsoft EXEPACK]] in inner layer and [[Knowledge Dynamics LZW COMPRESSOR]] in outer layer. &lt;br /&gt;
To mod this version, both compressions should be removed. Telling two versions apart is easy - uncompressed&lt;br /&gt;
exe is 113718 bytes long, while compressed takes only 79839 bytes.&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [https://sourceforge.net/p/openkb/wiki/Home/ OpenKB] - open-source clone / digital preservation project.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11615</id>
		<title>King&#039;s Bounty Index Tables</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11615"/>
		<updated>2024-01-25T02:12:18Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: mal-formatted TODO&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;As indicated in [[King&#039;s Bounty Saved game Format]], some of the values that define [[King&#039;s Bounty]]&#039;s world and mission are hardcoded within the main executable (KB.EXE). Specifically, assuming&lt;br /&gt;
&lt;br /&gt;
 constexpr int kAlphabet = 26; // &#039;Z&#039; - &#039;A&#039; + 1&lt;br /&gt;
 constexpr int kAlphaExt = kAlphabet + 1; // extra element at the end is the king&#039;s castle&lt;br /&gt;
&lt;br /&gt;
the following index tables exist (I only have the DOS 1990 version at the moment; need to find and examine the 1995 version):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Offset 1990!!Offset 1995!!Data Type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0x183f8||?||[[BYTE]] x[kAlphaExt], y[kAlphaExt]||Castle gate locations (27 X values, then 27 Y values)&lt;br /&gt;
|-&lt;br /&gt;
|0x1867d||?||[[BYTE]] c[kAlphabet]||Continent of the castle (0-3).&amp;lt;ref&amp;gt;Used for Castle Gate and for castle entry detection.&amp;lt;/ref&amp;gt; 26 values (the king&#039;s continent is always 0)&lt;br /&gt;
|-&lt;br /&gt;
|0x165cb||?||[[BYTE]] c[kAlphabet]||An identical copy of the above, with unclear purpose.&amp;lt;ref&amp;gt;Possibly a rudiment of an early design allowing town placement on a different continent from its castle?&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x18481||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||Town square coordinates (26 X values, then 26 Y values), *in corresponding castle order*.&amp;lt;ref&amp;gt;The game treats castle-town pairs as, essentially, castle objects with town properties. All town data, except (obviously) for the Town Gate lookup table, are arranged in castle order, i.e. Riverton is #0 because of Azram, Underfoot is #1 because of Basefit, etc.&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x1852d||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||Harbor coordinates (where the boat appears); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18649||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||&amp;quot;Airport&amp;quot; coordinates (where Town Gate lands the hero); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18697||?||[[BYTE]] m[kAlphabet]||town letter -&amp;gt; castle letter mapping for Town Gate (26 indices). E.g. &amp;lt;tt&amp;gt;m[0]&amp;lt;/tt&amp;gt; (town of A-Anomaly) is &amp;lt;tt&amp;gt;0x3&amp;lt;/tt&amp;gt; (castle of D-Duvock).&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Obviously, all of the offsets apply to the uncompressed file.&lt;br /&gt;
&lt;br /&gt;
The Castle Gate spell always places the hero south of the actual castle gate (the Y coordinate is less by 1).&lt;br /&gt;
&lt;br /&gt;
Stepping on a Castle Gate tile (&amp;lt;tt&amp;gt;0x85&amp;lt;/tt&amp;gt;)) that does not correspond to a recognized castle freezes the game.&lt;br /&gt;
&lt;br /&gt;
Stepping on a Town tile (&amp;lt;tt&amp;gt;0x8a&amp;lt;/tt&amp;gt;) that does not correspond to a recognized town immediately returns the hero one step back.&lt;br /&gt;
&lt;br /&gt;
Stepping on a registered tile (one that&#039;s present in the table) but doesn&#039;t have a corresponding interactive map object (town walls or castle gate) does not by itself result in an interaction.&lt;br /&gt;
&lt;br /&gt;
== Constraints ==&lt;br /&gt;
&lt;br /&gt;
Not all possible index combinations (even those that maintain the permutation invariant, i.e. correctly define 26 distinct towns, castles and the king&#039;s castle) are supported. Bugs ranging from sad (game freeze) to funny (corrupt text messages, inconsistent Contract Info) ensue if the numbers of castles and villains on each continents deviate from the prearranged distribution (below). Insult to injury, the castle-to-continent mapping seems to be defined in a not yet found THIRD lookup table that affects the villain&#039;s Last Seen continent on the Contract Info screen.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!C-index!!Continent!!Castles!!Villains|Castle initials (for Info)&lt;br /&gt;
|-&lt;br /&gt;
|0||Continentia||11||6|ACFIKNOPRVW&lt;br /&gt;
|-&lt;br /&gt;
|1||Continentia||6||4|BDJMQY&lt;br /&gt;
|-&lt;br /&gt;
|2||Continentia||6||4|EGHLTX&lt;br /&gt;
|-&lt;br /&gt;
|3||Continentia||3||3|SUZ&lt;br /&gt;
|-&lt;br /&gt;
|=||(total)||26||17|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
It is, however, possible to arrange the castles on a particular continent in a pretty much arbitrary way; place castle gate tiles without the surrounding castle walls (allowing &amp;quot;backdoor access&amp;quot; to them); place villains in castles without regard to their difficulty level (e.g. place Arech in Continentia via the LUT in the save file); etc.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11614</id>
		<title>King&#039;s Bounty Index Tables</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Index_Tables&amp;diff=11614"/>
		<updated>2024-01-25T02:10:46Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: Lookup tables defining correspondences between castle locations, town locations, castle and town names, and continents.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;As indicated in [[King&#039;s Bounty Saved game Format]], some of the values that define [[King&#039;s Bounty]]&#039;s world and mission are hardcoded within the main executable (KB.EXE). Specifically, assuming&lt;br /&gt;
&lt;br /&gt;
 constexpr int kAlphabet = 26; // &#039;Z&#039; - &#039;A&#039; + 1&lt;br /&gt;
 constexpr int kAlphaExt = kAlphabet + 1; // extra element at the end is the king&#039;s castle&lt;br /&gt;
&lt;br /&gt;
the following index tables exist (I only have the DOS 1990 version at the moment; {{TODO: find and examine the 1995 version}}):&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!Offset 1990!!Offset 1995!!Data Type!!Description&lt;br /&gt;
|-&lt;br /&gt;
|0x183f8||?||[[BYTE]] x[kAlphaExt], y[kAlphaExt]||Castle gate locations (27 X values, then 27 Y values)&lt;br /&gt;
|-&lt;br /&gt;
|0x1867d||?||[[BYTE]] c[kAlphabet]||Continent of the castle (0-3).&amp;lt;ref&amp;gt;Used for Castle Gate and for castle entry detection.&amp;lt;/ref&amp;gt; 26 values (the king&#039;s continent is always 0)&lt;br /&gt;
|-&lt;br /&gt;
|0x165cb||?||[[BYTE]] c[kAlphabet]||An identical copy of the above, with unclear purpose.&amp;lt;ref&amp;gt;Possibly a rudiment of an early design allowing town placement on a different continent from its castle?&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x18481||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||Town square coordinates (26 X values, then 26 Y values), *in corresponding castle order*.&amp;lt;ref&amp;gt;The game treats castle-town pairs as, essentially, castle objects with town properties. All town data, except (obviously) for the Town Gate lookup table, are arranged in castle order, i.e. Riverton is #0 because of Azram, Underfoot is #1 because of Basefit, etc.&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|0x1852d||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||Harbor coordinates (where the boat appears); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18649||?||[[BYTE]] x[kAlphabet], y[kAlphabet]||&amp;quot;Airport&amp;quot; coordinates (where Town Gate lands the hero); 26 X values, then 26 Y values&lt;br /&gt;
|-&lt;br /&gt;
|0x18697||?||[[BYTE]] m[kAlphabet]||town letter -&amp;gt; castle letter mapping for Town Gate (26 indices). E.g. &amp;lt;tt&amp;gt;m[0]&amp;lt;/tt&amp;gt; (town of A-Anomaly) is &amp;lt;tt&amp;gt;0x3&amp;lt;/tt&amp;gt; (castle of D-Duvock).&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Castle Gate spell always places the hero south of the actual castle gate (the Y coordinate is less by 1).&lt;br /&gt;
&lt;br /&gt;
Stepping on a Castle Gate tile (&amp;lt;tt&amp;gt;0x85&amp;lt;/tt&amp;gt;)) that does not correspond to a recognized castle freezes the game.&lt;br /&gt;
&lt;br /&gt;
Stepping on a Town tile (&amp;lt;tt&amp;gt;0x8a&amp;lt;/tt&amp;gt;) that does not correspond to a recognized town immediately returns the hero one step back.&lt;br /&gt;
&lt;br /&gt;
Stepping on a registered tile (one that&#039;s present in the table) but doesn&#039;t have a corresponding interactive map object (town walls or castle gate) does not by itself result in an interaction.&lt;br /&gt;
&lt;br /&gt;
== Constraints ==&lt;br /&gt;
&lt;br /&gt;
Not all possible index combinations (even those that maintain the permutation invariant, i.e. correctly define 26 distinct towns, castles and the king&#039;s castle) are supported. Bugs ranging from sad (game freeze) to funny (corrupt text messages, inconsistent Contract Info) ensue if the numbers of castles and villains on each continents deviate from the prearranged distribution (below). Insult to injury, the castle-to-continent mapping seems to be defined in a not yet found THIRD lookup table that affects the villain&#039;s Last Seen continent on the Contract Info screen.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
!C-index!!Continent!!Castles!!Villains|Castle initials (for Info)&lt;br /&gt;
|-&lt;br /&gt;
|0||Continentia||11||6|ACFIKNOPRVW&lt;br /&gt;
|-&lt;br /&gt;
|1||Continentia||6||4|BDJMQY&lt;br /&gt;
|-&lt;br /&gt;
|2||Continentia||6||4|EGHLTX&lt;br /&gt;
|-&lt;br /&gt;
|3||Continentia||3||3|SUZ&lt;br /&gt;
|-&lt;br /&gt;
|=||(total)||26||17|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
It is, however, possible to arrange the castles on a particular continent in a pretty much arbitrary way; place castle gate tiles without the surrounding castle walls (allowing &amp;quot;backdoor access&amp;quot; to them); place villains in castles without regard to their difficulty level (e.g. place Arech in Continentia via the LUT in the save file); etc.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=User:Treeswift&amp;diff=11594</id>
		<title>User:Treeswift</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=User:Treeswift&amp;diff=11594"/>
		<updated>2024-01-19T08:56:56Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: link to the game page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Class &amp;quot;C&amp;quot;: church, cooking, cats, concepts, coding, castles, combat, command, conquest, pedantiCism and nitpiCking.&lt;br /&gt;
&lt;br /&gt;
* Medium-term plans: researching and modding the original [[King&#039;s Bounty]]. (DoD: playing KB on a new, randomly generated map.)&lt;br /&gt;
* Long-term goals: a public domain implementation of the game mechanics. If you know your party&#039;s ext... sorry. If you know exactly how attack and retaliation damage are calculated, it would be great if you leave a comment or drop me a message.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=User:Treeswift&amp;diff=11593</id>
		<title>User:Treeswift</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=User:Treeswift&amp;diff=11593"/>
		<updated>2024-01-19T08:55:05Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: Clarification of longer-term plans.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Class &amp;quot;C&amp;quot;: church, cooking, cats, concepts, coding, castles, combat, command, conquest, pedantiCism and nitpiCking.&lt;br /&gt;
&lt;br /&gt;
* Medium-term plans: researching and modding the original King&#039;s Bounty. (DoD: playing KB on a new, randomly generated map.)&lt;br /&gt;
* Long-term goals: a public domain implementation of the game mechanics. If you know your party&#039;s ext... sorry. If you know exactly how attack and retaliation damage are calculated, it would be great if you leave a comment or drop me a message.&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
	<entry>
		<id>https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=11592</id>
		<title>King&#039;s Bounty Saved game Format</title>
		<link rel="alternate" type="text/html" href="https://moddingwiki.shikadi.net/w/index.php?title=King%27s_Bounty_Saved_game_Format&amp;diff=11592"/>
		<updated>2024-01-19T08:41:41Z</updated>

		<summary type="html">&lt;p&gt;Treeswift: clarified the meaning of fields at offsets 0x77 and 0x78&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Playerdata Infobox&lt;br /&gt;
 | Savegame = Yes&lt;br /&gt;
 | Elements = Many&lt;br /&gt;
 | Games =&lt;br /&gt;
   {{Game|King&#039;s Bounty}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This format is used to save the whole game state for [[King&#039;s Bounty]].&lt;br /&gt;
&lt;br /&gt;
As the save files do not require re-insertion into group files, nor are compressed, yet maintain their own full copies of the game world, they provide good opportunity to distribute custom levels or maps.&lt;br /&gt;
&lt;br /&gt;
== File format ==&lt;br /&gt;
&lt;br /&gt;
A save always takes exactly 20421 bytes. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
0x000 - 0x00A   | name&lt;br /&gt;
0x00B           | class&lt;br /&gt;
0x00C           | rank&lt;br /&gt;
0x00D           | spell power&lt;br /&gt;
0x00E           | max # of spells&lt;br /&gt;
0x00F - 0x01F   | is villain N caught&lt;br /&gt;
0x020 - 0x027   | is artifact N found&lt;br /&gt;
0x028 - 0x02B   | is continent N available&lt;br /&gt;
0x02C - 0x02F   | is orb N found&lt;br /&gt;
0x030 - 0x03D   | number of spells N&lt;br /&gt;
0x03E           | knows magic &lt;br /&gt;
0x03F           | siege weapons&lt;br /&gt;
0x040           | current contract&lt;br /&gt;
0x041 - 0x045   | hero army&lt;br /&gt;
0x046           | Option: Delay (0-9) &lt;br /&gt;
0x047           | difficulty&lt;br /&gt;
0x048           | Option: Sounds&lt;br /&gt;
0x049           | Option: Walk Beep&lt;br /&gt;
0x04A           | Option: Animation&lt;br /&gt;
0x04B           | Option: Show Army Size&lt;br /&gt;
0x04C           | hero continent&lt;br /&gt;
0x04D           | hero X			&lt;br /&gt;
0x04E           | hero Y&lt;br /&gt;
0x04F           | last X&lt;br /&gt;
0x050           | last Y&lt;br /&gt;
0x051           | boat X&lt;br /&gt;
0x052           | boat Y&lt;br /&gt;
0x053           | boat continent (0xFF - no boat)&lt;br /&gt;
0x054           | mount mode (0x00 - boat, 0x04 - fly, 0x08 - horse)&lt;br /&gt;
0x055           | Option: CGA palette&lt;br /&gt;
0x056 - 0x069   | spell sold in town N&lt;br /&gt;
0x070 - 0x074   | contract cycle (5 villains)&lt;br /&gt;
0x075           | last contract (starts as 0x04 to flip to 0x00 on first run)&lt;br /&gt;
0x076           | max contract (starts as 0x05)&lt;br /&gt;
0x077           | steps left (until end of day; never becomes 0, always refills to 0x28=decimal 40)&lt;br /&gt;
0x078           | days left until the end of the week (never becomes 0, refills to 5 every new week)&lt;br /&gt;
0x079 - 0x092   | castle owned by... (0x7F = no one, 0xFF = you, LOW 5 bits = villain)&lt;br /&gt;
0x093 - 0x0AC   | visited castle N&lt;br /&gt;
0x0AD - 0x0C6   | visited town N&lt;br /&gt;
0x0C7           | scepter continent (&#039;encrypted&#039;)&lt;br /&gt;
0x0C8           | scepter X (&#039;encrypted&#039;)&lt;br /&gt;
0x0C9           | scepter Y (&#039;encrypted&#039;)&lt;br /&gt;
0x0CA - 0x8C9   | fog of war (1bpp)&lt;br /&gt;
0x8CA - 0x94B   | garrison troops &lt;br /&gt;
0x94C - 0x973   | foeF coords (2 bytes each, 5 per continent)&lt;br /&gt;
0x974 - 0x979   | map chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x97a - 0x981   | orb chests coords (2 bytes each, 1 per continent)&lt;br /&gt;
0x982 - 0x991   | teleporter coords (2 bytes each, 2 per continent)&lt;br /&gt;
0x992 - 0x9E9   | dwelling coords (2 bytes each, 11 per continent)&lt;br /&gt;
0x9EA - 0xB01   | foeH coords (2 bytes each, 35 per continent)&lt;br /&gt;
0xB02 - 0xCA5   | foeH troops (3 bytes each)&lt;br /&gt;
0xCA6 - 0xE49   | foeH numbers (3 bytes each)&lt;br /&gt;
0xE4A - 0xE75   | dwelling N troop&lt;br /&gt;
0xE76 - 0xEA1   | dwelling N population&lt;br /&gt;
0xEA2           | scepter key (to XOR scepter coords with)&lt;br /&gt;
0xEA3 - 0xEA4   | base leadership&lt;br /&gt;
0xEA5 - 0xEA6   | leadership&lt;br /&gt;
0xEA7 - 0xEA8   | commission&lt;br /&gt;
0xEA9 -	0xEAA   | followers killed&lt;br /&gt;
0xEAB - 0xEB4   | hero army numbers&lt;br /&gt;
0xEB5 - 0xFB8   | garrison numbers &lt;br /&gt;
0xFB9 - 0xFBA   | time stop (&amp;quot;free&amp;quot; steps left)&lt;br /&gt;
0xFBB - 0xFBC   | days left&lt;br /&gt;
0xFBD - 0xFBE   | score (never actually used)&lt;br /&gt;
0xFBF           | ? // unknown1, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC0           | ? // unknown2, always &amp;quot;00&amp;quot;&lt;br /&gt;
0xFC1 - 0xFC4   | gold&lt;br /&gt;
0xFC5 - END     | map dump&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- TODO: proper mediawiki table --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Player name is padded with spaces&lt;br /&gt;
* There are 26 castles, 26 towns, 17 villains, 25 troops, 14 spells and 4 continents in the game.&lt;br /&gt;
* Coordinates always take 2 bytes and always go in X, Y order.&lt;br /&gt;
* Scepter coordinates are XORed with &#039;&#039;scepter key&#039;&#039; upon load/save.&lt;br /&gt;
* Troop and villain indexes are in production order (as seen in .CC files).&lt;br /&gt;
* Dwelling populations are kept in [[BYTE]]s, 250 being maximum possible value.&lt;br /&gt;
* Hero and castle army numbers are kept in [[UINT16LE]]s, 5 per army.&lt;br /&gt;
* Hostile foes only have 3 troops and their numbers are kept in [[BYTE]]s.&lt;br /&gt;
* The &#039;&#039;mount mode&#039;&#039; is also an offset into hero&#039;s sprite-sheet.&lt;br /&gt;
* The map is a complete dump in [[King&#039;s Bounty Map Format]].&lt;br /&gt;
&lt;br /&gt;
=== Coordinates ===&lt;br /&gt;
&lt;br /&gt;
The game is consistent with it&#039;s map coordinate system, which goes in the &#039;&#039;&#039;bottom-to-top&#039;&#039;&#039;, left-to-right order. That means top left corner has coordinate X=0, Y=63.&lt;br /&gt;
&lt;br /&gt;
== Credits ==&lt;br /&gt;
&lt;br /&gt;
Originally devised by the [http://sourceforge.net/p/openkb/wiki/Home/ openkb project], with best regards to the modding community.  If you find this information helpful in a project you&#039;re working on, please give credit where credit is due.  (A link back to this wiki would be nice too!)&lt;/div&gt;</summary>
		<author><name>Treeswift</name></author>
	</entry>
</feed>