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)
!!CA0/#:XXXX; Town with  town number of # on the map list (see U option below).
(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 number in Building list)
B2/$; Demolish the $ structure (see number in Building list)
B3/$; Check if the $ structure built (in flag 1) (see number in Building list)
B4/$; Enable to build the $ structure (see number in Building list)
B5/$; Disable to build the $ structure (see number in Building list)
B6/$; Build in town using an internal function (see number in 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.
If you have an upgraded building, the $3 is used, otherwise $2.
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 :-)