Hi,
I’m fairly new to PHP but am working on a game half as a way to test things in a way where they can all be relevant to one another, half because if I succeed at making this game then cool! Anyways, I’m working on the combat system, and have come across a problem where I cant find an answer because I’m not even sure where to start looking. I have 3 types of units, in sort of a rock paper scissors configuration where each one gets a type advantage or disadvantage. Im using if / elseif to have them target the units they have an advantage on first, then themselves, then the one theyre weak to. The Owned == 1 is a true false Im using, but later am also going to potentially more values such as 2, 3 etc for slightly different circumstances, which is why I chose to use numbers. In this case it just means true, so there are units of each of the type involved in the given battle.
[php]
if (( $MyLVL1MeleeOwned == 1 ) and ( $TheirLVL1ArchersOwned == 1 ))
{
echo floor (($TheirLVL1ArcherHP - ($MyLVL1MeleeATT * 1.5 )) / $TheirLVL1HPBaseline) . “
”;
echo floor (($MyLVL1MeleeHP - $TheirLVL1ArcherATT) / $MyLVL1HPBaseline) . “
”;
}
[/php]
The floor is so that the decimals are ignored since they can’t kill a fraction of a unit. I’m making it so the base units have more HP than attack, but that can be modified with items, enchantments etc. However just running 1,000 units through as a test, I wind up with 250 archers left over, and 500 melee left over, and what I want to do is run those remainders through that equation again, until one side or the other has reached 0 units. Essentially keep them fighting until one side wins. Is there some way I can reference these equations multiple times? As I add different levels of units, I.E. archers level 1, so level 1 and 2 archers could be fighting level 1 melee, I’m not sure how many times might be necessary to get me down to 0 units on one side or the other, so cant see how manually coding each equation in would work for this situation.
Thanks,
Max