My next focus is the NPC battles. As I found a month or so ago, the client contains no information regarding the rival drivers. Only the rival team name and member names are stored in the client. This is only used for the “Data” dialog to see the rival statuses. When spawning an NPC the name and team name is is provided in the spawn packet along with the car stats.
As I don’t have this information I’ll be leaning on TXR0 rival car data, which I’ve extracted. However any teams with cars not in the game don’t exist in the team list. To make up for this they have made each rival team have 8 members instead of the 6 in TXR0. There are also 2 additional teams similar to Rolling Guys. Rolling Kids and “Rowing” Guy. I assume these are also teams of AE86’s. These Rolling and Rowing teams also are only meant to appear in the beginners course only.
I want the rivals to be instanced to the client. From what I’ve been told from players of the game, Genki had rivals that the whole course shared. So would like to change that, and is how I’ve coded it for the moment. I’ve added a rival structure to the client class which can have upto 16 NPC’s. So the first 16 ID’s of the course are reserved for NPC’s. Real players will get ID’s assigned from 16.
For testing I used a Wanderer member “Devil Driver” from the TXR0 data. It turns out that many of the Wanderers cars aren’t in the game so settled for a standard s15 and passed the parts and colours to the car structure for the rival.
Once a rival is spawned they need a regular brief position packet sent otherwise they will move a short distance and warp back to where they started. So to test, I just used the position of the player to use for the NPC. This means it pretty much follows the player.
Now that the NPC is moving reliably I can work on the battle packets. NPC’s use different packets to the PvP battle packets: 0x580 Battle start, 0x581 Battle Abort, 0x582 battle ready, 0x583 battle finish. NPC use 0x584 battle start, 0x585 battle abort and 0x586 battle finish. The battle start packet differ from the PvP version. For NPC it expects 0x38 more bytes. This is a structure of 12 floats and 8 bytes. Adjusting the floats alters the aggression of the NPC and crash recovery. I’m not able to see what the affect is of the bytes. Although the client does check for the bytes at 0x2F and 0x31 in that structure if set. I’ll look into what the values affect more later.
With the battle start packet correctly formatted the battle starts. During the battle unlike the PvP version the SP isn’t sent to the server until the battle ends. Once ended the client sends 0x505 which contains the reason for the end, distance of the battle and the SP of NPC and Player. As 0x585 is the battle abort packet. Much like with the PvP battles the correct response to this packet is battle finish which for NPC’s is 0x586. Which unlike the PvP version contains the CP winnings and Item along with EXP. However as EXP isn’t to be earned during NPC battles I’ll leave this as 0.
So for me to implement NPC’s I’m going to have to implement some method to navigate them around the course. My solution is to record placement of my car in auto pilot driving around C1 Inner and Outer. Then add this data to a table then have the NPC use this data to position themselves. I just need to randomize their start position. Which is just a matter of using an RNG to pick the index in that table. Then have the NPC’s evenly space from that point. The result is the NPC following my path around the C1. During battles the NPC ignore their position packets and take on the AI values sent on battle start. So I don’t need to worry about the NPC’s position during battles.
So far this is the best method I have to control the NPC’s. I will have a route table for each area of the course and junction points that will allow me to navigate them back to their route should they be forced off during a battle. This data doesn’t actually take up too much memory on the server. Only around 150KB per route. So maybe a few MB’s of route data is needed.
I now need to look at which NPC’s should spawn and their rewards. So there will be another few tables of data created manually.