-
Notifications
You must be signed in to change notification settings - Fork 6
AI Improvements by Ten Graves
Welcome to my in-depth AI tutorial! You'll hopefully find the hacks useful here (contributions are welcome).
Most, if not all hacks should be in control. I'll also assume you have decent experience with java hacking in NFM.
Controlling which car AI attack:
Very easy to do. You should already know about the "attack" variable, where if it is greater than 0 the AI would attack someone (the higher the variable, the longer they attack them for). But who do they attack? It all depends on the "acr" variable.
Example:
The "0x7fffffff" number is actually in hex. Don't worry about what number it actually is (I just use it in place of a really high number). The "j2 = 0" is not really essential; it just affects aggressiveness slightly (you can leave it out if you want). More importantly, the "acr" variable is 0, so this means MAX Revenge (or whatever car you replaced it with) will target you.
The "acr" variable is based on the "car ID." The "ID" of you is 0 (so if acr is 0, you would be the target), and the ID of the boss car is 6 (this may change if you have more than 7 cars in a game).
Improving AI's stunting while they're trying to fix:
Getting the AI to fix properly can be frustrating. It's even more annoying when they miss constantly, which is far from ideal if you want your version to be a challenge. Luckily, there is a fix for this?
First of all, you have to consider the position of the fix in relation to the ramp needed to reach it. Is it high or is it low? Is it slightly off to the side? Once you've done that and you've considered what type of stunts (e.g. backflips, front flips, rollspins, etc.) you normally have to use to reach it, you can make the AI do it too.
The two variables you'll be using for this are "uddirect" and "lrdirect."
-- If uddirect is 1, the AI will focus on foward flips. If it's -1, they will focus on back loops.
-- If lrdirect is 1, the AI will focus on rollspins to the right, and if it's -1, they will focus on them to the left.
You can even utilise the "udstart" and "lrstart" variables too. These variables basically delay when the AI actually start stunting. So if udstart was, say, 15, the AI would wait for about a second before doing any forward or back loops. The same applies to lrstart, which corresponds to left and right rollspins.
Here is an example code used in Stage 16:
So basically this code means that, when trying to fix, the cars will use back loops. EL KING and MASHEEN will stunt as soon as they can, probably because they cannot afford to delay it due to their low stunting capabilities. Radical One on the other hand would wait for about a second before doing a back loop (this is because of his high stunting ability; if it stunted too early it would probably overshoot the fixing hoop), unless it's power is below 30% (which should never happen to be honest). All the other cars would wait for about half a second before stunting.
Making the AI fix as soon as they can:
Have you ever wondered why the AI always seem to complete a checkpoint before fixing? I don't know why Omar made them do this to be honest. Luckily, this is very easy to rectify. Just find this code:
Just add on to that if statement with whatever stage (or whatever conditions) you want them to stop running to the checkpoint before fixing. The "forget" variable basically controls this.
Dodging AI:
First, find this if statement:
if (checkpoints.clear[madness.im] - checkpoints.clear[0] >= 2
&& Utility.py(conto.x / 100, checkpoints.opx[0] / 100, conto.z / 100,
checkpoints.opz[0] / 100) < 1000 + avoidnlev) {
int j4 = conto.xz;
if (zyinv) {
j4 += 180;
}
for (; j4 < 0; j4 += 360) {
}
for (; j4 > 180; j4 -= 360) {
}
char c3 = '\0';
if (checkpoints.opx[0] - conto.x >= 0) {
c3 = '\264';
}
int k7;
for (k7 = (int) (90 + c3 + Math
.atan((double) (checkpoints.opz[0] - conto.z)
/ (double) (checkpoints.opx[0] - conto.x))
/ 0.017453292519943295D); k7 < 0; k7 += 360) {
}
for (; k7 > 180; k7 -= 360) {
}
int j8 = Math.abs(j4 - k7);
if (j8 > 180) {
j8 = Math.abs(j8 - 360);
}
if (j8 < 90) {
wall = 0;
}
}
This is basically the code that make the AI dodge. Note that the AI will only dodge you if they're at least 2 checkpoints ahead of you (so basically if you're wasting or just dirty racing!). Scroll up a bit to find this if statement:
So basically the code for the AI dodging is stuck under the "if(checkpoints.stage == 16)" if statement, meaning the AI would only dodge on that stage. This is easy to fix; just make that if statement ends earlier (just but the end } bracket right before the code for the dodging AI. Now add a new if statement specifically for the dodging AI code, which should be more appropriate, e.g.:
So how do you actually make the AI dodge? It's simple; you use the avoidnlev variable. In a normal NFM 2, it should be 0 for all the stages (so the AI don't dodge) except in Stage 16, as shown in this code (it's at the bottom):
The greater the avoidnlev variable, the further away you have to be for them to try and dodge you. Usually, I set this value at 3000 on stages I want them to dodge on. Here's an example code of it that I used:
And that's it. Have fun!
Changing the AI's aggressiveness:
Very useful and also very simple. Find this bit of code in Control:
float f2 = (checkpoints.pos[madness.im] + 1) * (5 - checkpoints.pos[i4]) / f1;
The "f2" variable basically controls the aggressiveness of a car. If it's 0, the cars wouldn't waste at all. The higher the variable, the more aggressive the AI get.
Example of its use: