Name: Anonymous 2020-02-10 7:57
; brain.gs ; sets wandering monsters to do stuff that makes sense...
/brain
{
/dummy begin
/my_army championbrainarmyunit pop def
my_army 0 lt
{
% "brain died" print ; ***
getalarmself removechampionbrain
}
{
my_army ARMY_LOCATION getarmydata
xy_to_x_y buildingat dup -1 gt
{
;;; BUILDING_LEVEL 0 setbuildingdata
;;;THANH 12/5/97 0 setbuildinglevel ; mrg 11-5-97 note: this is a network message
dup
BUILDING_TYPE getbuildingdata LIBRARY ne
{
0 setbuildinglevel ; mrg 11-5-97 note: this is a network message
}
{
pop
} ifelse
}
{
pop
}ifelse
my_army getnearestscrollingtarget
/target_type exch def
/target exch def
/dummy2 target_type get exec
; target -1 gt
; { ;
; my_army ARMY_DESTINATION_ARMY getarmydata
; target eq not
;
; /dummy2 target_type get
; if
; } if
} ifelse
end
}
/dummy 10 dict replace
/dummy2
<<
/army
{
my_army
target
-1
longmoveattack
} bind
/city
{
my_army
-1
target
longmovetosprite
} bind
/dungeon
{
my_army
-1
target
longmovetosprite
} bind
/building
{
my_army
-1
target
longmovetosprite
} bind
>>
replace
bind def
20 dict begin
/getnearestscrollingtarget ; <army> getnearestscrollingtarget <id> </army,/city,/building,/dungeon>
{
/dummy begin
/startarmy exch def
/startlocation startarmy ARMY_LOCATION getarmydata def
/nearestvaliddistance 1000 def
/nearestvalidtarget -1 def
/targettype -1 def
/nearestcity
startlocation getclosestcity
def
nearestcity hasarmy? not nearestcity -1 gt and
{
nearestcity CURRENT CITY_LOCATION getcitydata
startlocation
realgriddistance dup
nearestvaliddistance lt
{
/nearestvaliddistance exch def
/nearestvalidtarget nearestcity def
/targettype /city def
}
{
pop
} ifelse
}if
/nearestbuilding
startlocation getclosestbuilding
def
nearestbuilding hasarmy? not nearestbuilding -1 gt and
{
nearestbuilding BUILDING_LOCATION getbuildingdata
startlocation
realgriddistance dup
nearestvaliddistance lt
{
/nearestvaliddistance exch def
/nearestvalidtarget nearestbuilding def
/targettype /building def
}
{
pop
} ifelse
}if
/nearestdungeon
startlocation getclosestplayerdungeon
def
nearestdungeon hasarmy? not nearestdungeon -1 gt and nearestdungeon isconquered? and
{
nearestdungeon getterrainspritelocation
startlocation
realgriddistance dup
nearestvaliddistance lt
{
/nearestvaliddistance exch def
/nearestvalidtarget nearestdungeon def
/targettype /dungeon def
}
{
pop
} ifelse
}if
/nearestarmy
startarmy getnearestenemy
def
nearestarmy -1 gt
{
nearestarmy ARMY_LOCATION getarmydata startlocation
realgriddistance
nearestvaliddistance lt
{
/nearestvaliddistance
nearestarmy ARMY_LOCATION getarmydata startlocation
realgriddistance
def
/nearestvalidtarget nearestarmy def
/targettype /army def
} if
} if
; default value in case nothing else is around for attacking
nearestvalidtarget -1 gt not
{
/nearestvalidtarget
startlocation getclosestplayerdungeon
def
/targettype /dungeon def
} if
; return values
nearestvalidtarget
targettype
end
}
/dummy currentdict replace
userdict begin
bind def
end
/getclosestbuilding ; <loc> getclosestbuilding <building_id>
{
/dummy begin
/location exch def
/closestbuilding -1 def
/closestbuildingdistance 1000 def
{
/currbuilding exch def
currbuilding BUILDING_PARENT getbuildingdata
dup iscity?
currbuilding BUILDING_OWNER getbuildingdata
dup 0 7 between
{ getplayeraistatus not and}
{ pop false and } ; wandering monster or unowned building
ifelse
{
CURRENT CITY_LEVEL getcitydata 0 gt ; do not destroy buildings that are attached to level 0 cities
}
{
pop true ; if parent is other than city it is always fair game...
}ifelse
currbuilding BUILDING_TYPE getbuildingdata LIBRARY eq not
and
{
currbuilding BUILDING_LOCATION getbuildingdata location realgriddistance
/currbuildingdistance exch def
currbuildingdistance
closestbuildingdistance lt
{
/closestbuildingdistance currbuildingdistance def
/closestbuilding currbuilding def
}if
} if
}enumbuildings
closestbuilding
end
} /dummy 10 dict replace
bind def
/getclosestcity ; <loc> getclosestcity <city_id>
{
/dummy begin
/location exch def
/closestcity -1 def
/closestcitydistance 1000 def
{
/tempcity exch def
tempcity CURRENT CITY_OWNER getcitydata 8 lt tempcity CURRENT CITY_LEVEL getcitydata 0 gt and
{
tempcity CURRENT CITY_LOCATION getcitydata location realgriddistance
closestcitydistance lt
{
/closestcitydistance
tempcity CURRENT CITY_LOCATION getcitydata
location
realgriddistance
def
/closestcity
tempcity
def
} if
}if
}enumcities
closestcity
end
} /dummy 10 dict replace
bind def
/getclosestplayerdungeon ; <loc> getclosestbuilding <building_id>
{
/dummy begin
/location exch def
/closestdungeon -1 def
/closestdungeondistance 1000 def
{
/currtsprite exch def
currtsprite
getterrainspriteprocid
-1 gt
{
currtsprite getterrainspriteowner 8 lt
{
currtsprite getterrainspritelocation location realgriddistance
/tspritedistance exch def
tspritedistance
closestdungeondistance lt
{
/closestdungeondistance tspritedistance def
/closestdungeon currtsprite def
}if
} if
} if
}enumterrainsprites
closestdungeon
end
} /dummy 10 dict replace
bind def
/getclosestdungeon ; <loc> getclosestbuilding <building_id>
{
/dummy begin
/location exch def
/closestdungeon -1 def
/closestdungeondistance 1000 def
{
/currtsprite exch def
currtsprite
getterrainspriteprocid
-1 gt
{
currtsprite getterrainspritelocation location realgriddistance
/tspritedistance exch def
tspritedistance
closestdungeondistance lt
{
/closestdungeondistance tspritedistance def
/closestdungeon currtsprite def
}if
}if
}enumterrainsprites
closestdungeon
end
} /dummy 10 dict replace
bind def
currentdict end ; getnearestdict - end, but leave on stack...
/village_security_brain
{
/dummy2 begin
/dummy begin
/building_id exch def
/my_army championbrainarmyunit pop def
my_army 0 lt
{
% "village_security_brain died" print
getalarmself removechampionbrain
}
{
/need_to_move? true def
my_army isbuilding?
{
my_army BUILDING_TYPE getbuildingdata HUT eq
{
% "village_security_brain - at village" print
/need_to_move? false def
} if
}
{
my_army moving?
{
building_id my_army ARMY_DESTINATION getarmydata xy_to_x_y buildingat eq
{
% "village_security_brain - already moving to city" print
/need_to_move? false def
} if
} if
} ifelse
need_to_move?
{
/attack? false def
building_id 0 lt
{
% "security_brain - no city to guard - removing brain" print
getalarmself removechampionbrain
}
{
building_id hasarmy?
{
building_id ARMY_OWNER getarmydata
my_army ARMY_OWNER getarmydata eq
{
my_army building_id canmerge? not
{
% "village_security_brain - kicking army out of city" print
building_id -1 moveout
} if
}
{
/attack? true def
} ifelse
} if
/good_bits 0 def
my_army
{
/u exch def
my_army 1 u bitshift /village_security_brain cvx findmatchingbrain
-1 gt ; found a match
{
/good_bits good_bits 1 u bitshift or def
} if
} enumunits
attack?
{
; different parameter order than longmovetosprite :-(
my_army building_id good_bits longmoveattack
% { "village_security_brain:" my_army building_id good_bits "longmoveattack" } build_statement print
}
{
my_army good_bits building_id longmovetosprite
% { "security_brain:" my_army good_bits building_id "longmovetosprite" } build_statement print
} ifelse
} ifelse
} if
} ifelse
end
end ; getnearestdict
}
/dummy 10 dict replace
/dummy2 4 -1 roll replace; getnearestdict was left on stack earlier in this file
bind def
/make_village_security_forces
{
/dummy begin
{
/building_id exch def
% "inside enumbuildings" print
building_id BUILDING_TYPE getbuildingdata HUT eq
% dup {"equal to hut"} {"not equal to hut"} ifelse print
{
building_id BUILDING_LOCATION getbuildingdata
UNITTYPELAND
findemptylocation
/temparmylocation exch def
temparmylocation
xy_to_x_y
building_id BUILDING_FAITH getbuildingdata
WANDERING_MONSTER_PLAYER
3 ; army strength of 4
makearmydict begin
createarmyonscrollingmap
end
temparmylocation
xy_to_x_y armyat /temparmy exch def
0 1 temparmy ARMY_NUM_UNITS getarmydata 1 sub
{
/village_security_brain cvx
building_id
temparmy 4 -1 roll UNIT_UNIQUE_ID getunitdata
-1 ; no special response code
setchampionbrain
pop ; pop off brain id
% temparmy ARMY_OWNER getarmydata WANDERING_MONSTER_PLAYER eq not
% {
% "village_security_brain attached to human controlled army" erroroutput
% } if
} for
}if
}enumbuildings
end ; localdictionary
}
/dummy 15 dict replace
bind def
/brain
{
/dummy begin
/my_army championbrainarmyunit pop def
my_army 0 lt
{
% "brain died" print ; ***
getalarmself removechampionbrain
}
{
my_army ARMY_LOCATION getarmydata
xy_to_x_y buildingat dup -1 gt
{
;;; BUILDING_LEVEL 0 setbuildingdata
;;;THANH 12/5/97 0 setbuildinglevel ; mrg 11-5-97 note: this is a network message
dup
BUILDING_TYPE getbuildingdata LIBRARY ne
{
0 setbuildinglevel ; mrg 11-5-97 note: this is a network message
}
{
pop
} ifelse
}
{
pop
}ifelse
my_army getnearestscrollingtarget
/target_type exch def
/target exch def
/dummy2 target_type get exec
; target -1 gt
; { ;
; my_army ARMY_DESTINATION_ARMY getarmydata
; target eq not
;
; /dummy2 target_type get
; if
; } if
} ifelse
end
}
/dummy 10 dict replace
/dummy2
<<
/army
{
my_army
target
-1
longmoveattack
} bind
/city
{
my_army
-1
target
longmovetosprite
} bind
/dungeon
{
my_army
-1
target
longmovetosprite
} bind
/building
{
my_army
-1
target
longmovetosprite
} bind
>>
replace
bind def
20 dict begin
/getnearestscrollingtarget ; <army> getnearestscrollingtarget <id> </army,/city,/building,/dungeon>
{
/dummy begin
/startarmy exch def
/startlocation startarmy ARMY_LOCATION getarmydata def
/nearestvaliddistance 1000 def
/nearestvalidtarget -1 def
/targettype -1 def
/nearestcity
startlocation getclosestcity
def
nearestcity hasarmy? not nearestcity -1 gt and
{
nearestcity CURRENT CITY_LOCATION getcitydata
startlocation
realgriddistance dup
nearestvaliddistance lt
{
/nearestvaliddistance exch def
/nearestvalidtarget nearestcity def
/targettype /city def
}
{
pop
} ifelse
}if
/nearestbuilding
startlocation getclosestbuilding
def
nearestbuilding hasarmy? not nearestbuilding -1 gt and
{
nearestbuilding BUILDING_LOCATION getbuildingdata
startlocation
realgriddistance dup
nearestvaliddistance lt
{
/nearestvaliddistance exch def
/nearestvalidtarget nearestbuilding def
/targettype /building def
}
{
pop
} ifelse
}if
/nearestdungeon
startlocation getclosestplayerdungeon
def
nearestdungeon hasarmy? not nearestdungeon -1 gt and nearestdungeon isconquered? and
{
nearestdungeon getterrainspritelocation
startlocation
realgriddistance dup
nearestvaliddistance lt
{
/nearestvaliddistance exch def
/nearestvalidtarget nearestdungeon def
/targettype /dungeon def
}
{
pop
} ifelse
}if
/nearestarmy
startarmy getnearestenemy
def
nearestarmy -1 gt
{
nearestarmy ARMY_LOCATION getarmydata startlocation
realgriddistance
nearestvaliddistance lt
{
/nearestvaliddistance
nearestarmy ARMY_LOCATION getarmydata startlocation
realgriddistance
def
/nearestvalidtarget nearestarmy def
/targettype /army def
} if
} if
; default value in case nothing else is around for attacking
nearestvalidtarget -1 gt not
{
/nearestvalidtarget
startlocation getclosestplayerdungeon
def
/targettype /dungeon def
} if
; return values
nearestvalidtarget
targettype
end
}
/dummy currentdict replace
userdict begin
bind def
end
/getclosestbuilding ; <loc> getclosestbuilding <building_id>
{
/dummy begin
/location exch def
/closestbuilding -1 def
/closestbuildingdistance 1000 def
{
/currbuilding exch def
currbuilding BUILDING_PARENT getbuildingdata
dup iscity?
currbuilding BUILDING_OWNER getbuildingdata
dup 0 7 between
{ getplayeraistatus not and}
{ pop false and } ; wandering monster or unowned building
ifelse
{
CURRENT CITY_LEVEL getcitydata 0 gt ; do not destroy buildings that are attached to level 0 cities
}
{
pop true ; if parent is other than city it is always fair game...
}ifelse
currbuilding BUILDING_TYPE getbuildingdata LIBRARY eq not
and
{
currbuilding BUILDING_LOCATION getbuildingdata location realgriddistance
/currbuildingdistance exch def
currbuildingdistance
closestbuildingdistance lt
{
/closestbuildingdistance currbuildingdistance def
/closestbuilding currbuilding def
}if
} if
}enumbuildings
closestbuilding
end
} /dummy 10 dict replace
bind def
/getclosestcity ; <loc> getclosestcity <city_id>
{
/dummy begin
/location exch def
/closestcity -1 def
/closestcitydistance 1000 def
{
/tempcity exch def
tempcity CURRENT CITY_OWNER getcitydata 8 lt tempcity CURRENT CITY_LEVEL getcitydata 0 gt and
{
tempcity CURRENT CITY_LOCATION getcitydata location realgriddistance
closestcitydistance lt
{
/closestcitydistance
tempcity CURRENT CITY_LOCATION getcitydata
location
realgriddistance
def
/closestcity
tempcity
def
} if
}if
}enumcities
closestcity
end
} /dummy 10 dict replace
bind def
/getclosestplayerdungeon ; <loc> getclosestbuilding <building_id>
{
/dummy begin
/location exch def
/closestdungeon -1 def
/closestdungeondistance 1000 def
{
/currtsprite exch def
currtsprite
getterrainspriteprocid
-1 gt
{
currtsprite getterrainspriteowner 8 lt
{
currtsprite getterrainspritelocation location realgriddistance
/tspritedistance exch def
tspritedistance
closestdungeondistance lt
{
/closestdungeondistance tspritedistance def
/closestdungeon currtsprite def
}if
} if
} if
}enumterrainsprites
closestdungeon
end
} /dummy 10 dict replace
bind def
/getclosestdungeon ; <loc> getclosestbuilding <building_id>
{
/dummy begin
/location exch def
/closestdungeon -1 def
/closestdungeondistance 1000 def
{
/currtsprite exch def
currtsprite
getterrainspriteprocid
-1 gt
{
currtsprite getterrainspritelocation location realgriddistance
/tspritedistance exch def
tspritedistance
closestdungeondistance lt
{
/closestdungeondistance tspritedistance def
/closestdungeon currtsprite def
}if
}if
}enumterrainsprites
closestdungeon
end
} /dummy 10 dict replace
bind def
currentdict end ; getnearestdict - end, but leave on stack...
/village_security_brain
{
/dummy2 begin
/dummy begin
/building_id exch def
/my_army championbrainarmyunit pop def
my_army 0 lt
{
% "village_security_brain died" print
getalarmself removechampionbrain
}
{
/need_to_move? true def
my_army isbuilding?
{
my_army BUILDING_TYPE getbuildingdata HUT eq
{
% "village_security_brain - at village" print
/need_to_move? false def
} if
}
{
my_army moving?
{
building_id my_army ARMY_DESTINATION getarmydata xy_to_x_y buildingat eq
{
% "village_security_brain - already moving to city" print
/need_to_move? false def
} if
} if
} ifelse
need_to_move?
{
/attack? false def
building_id 0 lt
{
% "security_brain - no city to guard - removing brain" print
getalarmself removechampionbrain
}
{
building_id hasarmy?
{
building_id ARMY_OWNER getarmydata
my_army ARMY_OWNER getarmydata eq
{
my_army building_id canmerge? not
{
% "village_security_brain - kicking army out of city" print
building_id -1 moveout
} if
}
{
/attack? true def
} ifelse
} if
/good_bits 0 def
my_army
{
/u exch def
my_army 1 u bitshift /village_security_brain cvx findmatchingbrain
-1 gt ; found a match
{
/good_bits good_bits 1 u bitshift or def
} if
} enumunits
attack?
{
; different parameter order than longmovetosprite :-(
my_army building_id good_bits longmoveattack
% { "village_security_brain:" my_army building_id good_bits "longmoveattack" } build_statement print
}
{
my_army good_bits building_id longmovetosprite
% { "security_brain:" my_army good_bits building_id "longmovetosprite" } build_statement print
} ifelse
} ifelse
} if
} ifelse
end
end ; getnearestdict
}
/dummy 10 dict replace
/dummy2 4 -1 roll replace; getnearestdict was left on stack earlier in this file
bind def
/make_village_security_forces
{
/dummy begin
{
/building_id exch def
% "inside enumbuildings" print
building_id BUILDING_TYPE getbuildingdata HUT eq
% dup {"equal to hut"} {"not equal to hut"} ifelse print
{
building_id BUILDING_LOCATION getbuildingdata
UNITTYPELAND
findemptylocation
/temparmylocation exch def
temparmylocation
xy_to_x_y
building_id BUILDING_FAITH getbuildingdata
WANDERING_MONSTER_PLAYER
3 ; army strength of 4
makearmydict begin
createarmyonscrollingmap
end
temparmylocation
xy_to_x_y armyat /temparmy exch def
0 1 temparmy ARMY_NUM_UNITS getarmydata 1 sub
{
/village_security_brain cvx
building_id
temparmy 4 -1 roll UNIT_UNIQUE_ID getunitdata
-1 ; no special response code
setchampionbrain
pop ; pop off brain id
% temparmy ARMY_OWNER getarmydata WANDERING_MONSTER_PLAYER eq not
% {
% "village_security_brain attached to human controlled army" erroroutput
% } if
} for
}if
}enumbuildings
end ; localdictionary
}
/dummy 15 dict replace
bind def