Okay, so I've worked out a simple skeleton of a battle system I'd like to use in my game. It all starts when the player enters the attack command:
command <attack #@enemy#> {
if type <#enemy#; enemy> then {
flag off <battleOver>
do <battle>
}
if type <#enemy#; ally> then msg <Attacking is not one of your brighter ideas.>
}
That starts off the procedure...
define procedure <battle>
repeat while not flag <battleOver> for each object in <#quest.currentroom#> {
if flag <playerGone> and flag <monsterGone> then {
flag off <playerGone>
flag off <monsterGone>
}
if type <#enemy#; enemy> and ( #player:spd# < #enemy:spd# ) or flag <playerGone> then {
do <monsterAttack>
wait <Press any key to continue...>
flag on <monsterGone>
}
else {
do <playerAttack>
wait <Press any key to continue...>
flag on <playerGone>
}
}
end define
Now, it works like dream... against one enemy at a time. I want to be able to have the player be able to battle up to five different enemies at once, and have the option of choosing which enemy to attack. How the heck would I go about adapting my current code to handle that?
Here are the playerAttack and monsterAttack procedures if you want to see them for whatever reason.
define procedure <monsterAttack>
if ( $objectproperty(#enemy#; hp)$ <= 0 ) then {
doaction <#enemy#; die>
flag on <battleOver>
hide <#enemy#>
}
else {
set numeric <dam; $objectproperty(#enemy#; str)$ - #player:def#>
if ( %dam% < 0 ) then set numeric <dam; 1>
set numeric <newPlayerHp; #player:hp# - %dam%>
property <player; hp=%newPlayerHp%>
doaction <#enemy#; flavortext>
}
end define
define procedure <playerAttack>
set numeric <dam; #player:str# - $objectproperty(#enemy#; def)$>
if ( %dam% <= 0 ) then set numeric <dam; 1>
set numeric <newEnemyHp; $objectproperty(#enemy#; hp)$ - %dam%>
property <#enemy#; hp=%newEnemyHp%>
doaction <player; flavortext>
end define