CardConquest Unity Multiplayer GameDev Blog #25: Reinforcements

First, I want to say that this is now just a “GameDev” blog and not a “GameDev and Tutorial” blog post. I enjoyed writing out my prior posts as “tutorials” and going through all the code and Unity editor stuff step by step, but those posts took a very, very long time for me to write and they only ever got like 30 page views each.

So, since the tutorial posts got to a complete game, I have decided instead to just make this a “GameDev” only blog series. I will make posts that discuss new stuff I’m adding to the CardConquest game, like new game play features, at a high level, but I won’t get into the code or anything of how it works. I will post everything to GitHub so the code will be available for anyone to review and to tell me that my code “smells” or whatever. About the github thing, though. Before, I had maintained a separate “BlogVersion” repository and had a separate, private repository for my main game development. I won’t be updating the blog version anymore, and will instead only be updating the main repository which should now be public. That repository can be found here. There should be publicly available release for the game as well, which you can find in the releases page of the github repo.

Now, on to what was added!

Battle Reinforcements

After getting CardConquest to a state where players can actually play to the end of a game, I outline a few “features” that I wanted to add in the future. The first feature was for reinforcements, which I described as: let players choose if they want units from an adjacent land tile to reinforce their armies and increase their player army score.

So, before a battle is “fought” by the players, the game should try and detect if there are any units within 1 land tile of the battle site. If any units are within 1 tile of the battle site, the players will then be prompted to select reinforcements. To illustrate this somewhat, consider the below battle scenario:

In the above screenshot, all the units surrounded by a black box would be eligible to be selected by reinforcements. The green player could select up to 1 tank and 1 infantry as reinforcements. The blue player could select up to 2 tanks and 4 infantry as reinforcements. The reinforcements the players select–which could be all the eligible units, none of the eligible units, or a limited selection of the eligible units–would then be added to each player’s battle score. If the green player selected the 1 tank and 1 infantry as reinforcements, their battle score would be 10 (2 main army tanks, 1 reinforcing tank. 3 main army infantry, 1 reinforcing infantry). If the blue player selected all eligible reinforcements, their battle score would be 12 (2 main army tanks, 2 reinforcement tanks. 0 main army infantry, 4 reinforcing infantry).

The reinforcements check and then selection would happen before every battle. A unit would be eligible to be a reinforcement if they are within 1 tile of the battle site, AND if they are not already part of a battle, AND if they were not already used as a reinforcement during that battle “phase.” The battle phase starts at the “Battles Detected” phase and continues until all of the detected battles (and new battles from units in a draw retreating to the same tile) are completed. When the game loops back to the Unit Movement phase, the battle phase has ended and units will again be allowed to reinforce in any new series of battles.

How it Looks

When players have eligible reinforcements, they will see all of the eligible units they can select expanded around the battle site. They will also see all eligible enemy units so that the player can figure out what their opponent can possibly select for their reinforcements. The screenshot below shows what it looks like.

To select a unit for reinforcements, you simply click on the units and then click on “submit.” There is no limit to the number of reinforcements you can select for any given battle. In the above screenshot, the blue player can select all 7 units for reinforcements. Select all 7 would look like this:

You can then click on “Unready” to select different units. When you unready, there is also a “clear reinforcements” button to unselect any reinforcements

Reinforcements in the Battle

During the battle, if a player has reinforcements, a new field in the battle panel called “reinforcements” will show the score value of their reinforcements. You can see it above the “Power of Army” value for both players below:

There is also a new “Show Reinforcements” button in battles that will reveal all units selected by players for reinforcements. Below is an example of showing reinforcements:

Reinforcements Can Die

At the end of a normal battle, “units lost” was calculated based on the cards selected by players. If the winner’s attack value was greater than the losers defense value, some number of units would be killed. Before, only units in your “army” would be killed. Now, it’s possible for a reinforcing unit to also be killed. This would only happen if the number of units to be killed in a battle, based on the winner’s attack value, is greater than the number of units in the loser’s main army. If that is the case, and the loser had reinforcements, the game will go through their reinforcements and kill a number of units equal to the amount of attack value remaining. Below is an example:

In the above battle, the winner had an attack value of 3 and the loser a defense value of 0. The loser’s army was only 2 units (1 tank and 1 infantry). So, there was 1 attack value remaining and the loser used reinforcements for this battle. The game then looks at all the reinforcing units and starts kill them, starting with the tanks and then the infantry. Because of this, the loser also lost 1 tank from their reinforcements.

When can a unit reinforce?

Any unit not in a battle during the “battle phase” can reinforce. Once a unit has been selected as a reinforcement for a battle, that unit CANNOT reinforce again until the battle phase ends. Additionally, any unit that had fought in a previous battle during the battle phase cannot reinforce. Basically, during any given set of battles, a unit can only fight in one of those battles.

Is there a video?

Yes! So glad you asked! Here you go!

I hope this works for anyone who tries to play. Good luck! If you have issues, you can post them as a GitHub issue on the games GitHub repository page. I’m sure there is a lot of ui stuff that will break. Hopefully nothing that breaks the game entirely though!