CASTLE ATTRIBUTES (CA)
RECEIVER

Used to check or modify the attributes of a town, including name, owner, available creatures and internal structures.

!!CAx/y/l:XXXX; Town settings for town at x/y/l coordinates.
(Towns are Type 98. See Format T)
!!CA#:XXXX; Indirect reference to town at x=v[#], y=v[#+1], l=v[#+2]
(Towns are Type 98. See Format T)
!!CA-1:XXXX; The current town.
Be careful for you can use it only in Town screen.

OPTIONS

B1/$; Build the $ structure (see Building list)
B2/$; Demolish the $ structure (see Building list)
B3/$; Check if the $ structure built (in flag 1) (see Building list)
B4/$; Enable to build the $ structure (see Building list)
B5/$; Disable to build the $ structure (see Building list)
B6/$; Build in town using an internal function (see Building list)
Builds a building in a town using an internal function. The syntax and the meaning is the same as for CA:B1/# but because it uses an internal function, buildings with multiple levels will be built correctly, and mage guilds will have spells automatically added (although you can still change them).
G$; Set/get/check a level of magic guild (in spells screen)
G$1/$2; Set/get/check a number of available spells ($2) in $1 level
G$1/$2/$3; Set/get/check a specific spell ($3) in slot $2, level $1.
See Format SP.
H#/$; Set/get/check heroes in Town garrison or visitor
   # = 0 - hero in the town garrison
   # = 1 - hero - a town visitor
   $ - the number of hero (-1 = no one). See Format H
You can get/check or set heroes. If you set it, do not forget to
move the previous to somewhere.

Note: one should be careful with the H command, for checking garrison heroes- if there isn't a specific check for whether it returns -1 or not, and just a check on something else on the hero, it will check the current hero, which might not be to good
I$; Set the external appearance of a town
Command Syntax:
!!CA:I# - sets the external town appearance. You can use only set syntax. Others make no sense.

Values for #:
0 = default (synchronizes the look with built structures, e.g., a Fort or Capitol)
-1 = completely destroyed
1 = destroyed a bit
2 = destroyed more
3 = destroyed a lot
M1/$1/$2/$3; Set/get/check a number of available monsters
($2- not upgraded creature and $3- upgraded) of level $1. See Below
M2/$1/$2/$3; Set/get/check a number of guards 
   $1 - Position 
   $2 - Type See Format C
   $3 - Number
N^text^, NzVar Set/get a name of a Town.
O$; Set/get/check an owner.  
See Format E1


Note: that if you want to set/get/use neutral as owner, see that neutral value is -1
To check if the owner is neutral, use
!!CAx/y/l:O?variable;
or
!!CA#:O?variable;

and check if variable is -1 (replace variable with ERM variable type. See Flag&Variable, VR and FU sections.

Note: Please note that if owner is neutral (value for object owner is -1), there is no need to get alliance team.
 If however you do so, the resulted team number is shown as 0 (which in most cases is the same alliance number for human red player)
P?$1/?$2/?$3; Get/check a Town position.
  
$1 = x
   $2 = y
   $3 = Level
R$; Control town building flag.
Check or set if a player can build this turn in a town. !!CA...:R$;
   $ = 0 if player/AI may build this turn
   $ = 1 if player/AI may not build this turn (already did)
Comments:
   You may use R0 any number of times during the turn and thus build any number of buildings in a town.
T$; Set/get/check a type of a Town (only inside).  
See Format T
.
U$; Get/check the number of a Town on the map list (not hero list)
You can also set it but I do not recommend :-)

Comments:
For M1. If you have an upgraded building, the $3 is used, otherwise $2.

 

List of all buildings

byte bit in byte building number building name (town number), clear written if nothing
0 01 0 Mage guild 1
0 02 1 Mage guild 2
0 04 2 Mage guild 3
0 08 3 Mage guild 4
0 10 4 Mage guild 5
0 20 5 tavern
0 40 6 shipyard when it's present:))
0 80 7 fort
1 01 8 citadel
1 02 9 castle
1 04 10 village hall
1 08 11 town hall
1 10 12 city hall
1 20 13 capitol
1 40 14 marketplace
1 80 15 resource silo
2 01 16 blacksmith
2 02 17 lighthouse(0)
mystic pond(1)
artifact merchants(2,5,8)
veil of darkness(4)
escape tunnel(6)
cage of warlords(7)
2 04 18 horde buildings for non-upgraded creatures:
Griffins, dwarves, stone gargoyles, imps, skeletons, troglodytes, goblins, gnolls, pixies.
2 08 19 horde buildings for upgraded creatures
Royal griffins, battle dwarves, obsidian gargoyles, familiars, skeleton warriors, infernal troglodytes, hobgoblins, gnoll marauders, sprites
2 10 20 Ship (when shipyard has it)
2 20 21 stables(0)
fountain
of fortune(1)
lookout tower(2)
brimstone clouds(3)
necromancy amplifier(4)
mana vortex(5)
freelancer's guild(6)
glyphs of fear(7)
magic university(8)
2 40 22 brotherhood of sword(0)
dwarven treasury(1)
library(2)
castle gates(3)
skeleton transformer(4)
portal of summoning(5)
ballista yard(6)
blood obelisk(7)
2 80 23 wall of Knowledge.(2)
order of fire(3)
academy of battle scholars(5)
hall of valhalla(6)
3 01 24 horde buildings for non-upgraded creatures:
dendroid guards, hell hounds
3 02 25 horde buildings for upgraded creatures:
Dendroid soldiers,
Cerberi
3 04 26 Grail
3 08 27 additional houses for town hall
3 10 28 additional houses for city hall
3 20 29 Additional Houses For Capitol
3 40 30 dwelling 1
3 80 31 dwelling 2
4 01 32 dwelling 3
4 02 33 dwelling 4
4 04 34 dwelling 5
4 08 35 dwelling 6
4 10 36 dwelling 7
4 20 37 upgraded dwelling 1
4 40 38 upgraded dwelling 2
4 80 39 upgraded dwelling 3
5 01 40 upgraded dwelling 4
5 02 41 upgraded dwelling 5
5 04 42 upgraded dwelling 6
5 08 43 upgraded dwelling 7