Page 1 of 1

AI attack changes in the upcoming release

PostPosted: 06 Jun 2014, 15:28
by Lewin
For the next KaM Remake release the way AI attacks work has been changed to be more like it was in the original game. The Dark Lord noticed that we had implemented AI attacks incorrectly in the KaM Remake, so hopefully this will make the original campaigns work better. But unfortunately it means that any maps with AI that were designed/tested for the KaM Remake might work incorrectly now.

1. Previously AI attacks had a parameter "Soldiers required", which meant the attack would occur when the AI had that many available soldiers. The parameter now means "Number of soldiers to attack" and has been renamed as such. So now this parameter tells the AI how many soldiers in total should go on the attack (before it was only used to trigger it). But the AI won't split groups so even if you set it to 1 the AI will still take a full group.

2. The parameter "Take all" previously meant the AI would attack with his entire available army (backline defence positions and idle soldiers). Now it means the AI will attack with the "Number of soldiers to attack" (see above) and choose that number of soldiers randomly from the available groups. The parameter has been renamed to "choose randomly"

So basically you only need to worry if:
1. You set "Soldiers required" (now "Number of soldiers to attack") to be different than the number of soldiers you actually want to attack (because previously it was only a trigger not the actual number to attack)
2. You used "take all" (now "choose randomly") and expected the AI to send its entire army rather than sending "Number of soldiers to attack" worth of groups

For those who are interested I made a description of AI attacks here, since it's kind of confusing:
https://code.google.com/p/castlesand/wiki/AI
I can add explanations of other AI things to that page if requested.

CASE STUDY: Invasion (aka Zombie Apocalypse) by Skypper

The dynamic script spawns groups around the map, and an AI attack causes them to immediately attack the player. The AI attack looks like this:
Type: Repeating
Soldiers required: 0
Groups: Take all

This worked in the past because "soldiers required" was just the trigger. Also "take all" meant every group would be ordered to attack. The change I would suggest is:
Type: Repeating
Number of soldiers to attack: 1
Groups: Choose randomly

The attack will be triggered whenever the AI has at least 1 idle soldier. The AI will send a group to attack every time the attack is launched (every 1.2 seconds), because it won't split groups in order to have 1 soldier. If Skypper requires the attack to be faster than 1 group every 1.2 seconds he could add the same attack multiple times.

For more information about the upcoming release (and a nightly build to test your changes in) please check this topic:
viewtopic.php?f=5&t=2229

If you have any questions please ask :)

Re: AI attack changes in the upcoming release

PostPosted: 06 Jun 2014, 17:09
by Skypper
I edited Invasion like you said.
It worked good, most players will be happy if they get 1.2 extra time, in the later waves ;)

I have also added a description

Re: AI attack changes in the upcoming release

PostPosted: 06 Jun 2014, 19:25
by The Dark Lord
If Skypper requires the attack to be faster than 1 group every 1.2 seconds he could add the same attack multiple times.
As far as I know, Skypper's script is timed and in that sense not dynamic - the troops need to be created by dynamic script obviously, but it is possible to do the attacks with static scripts. I assume he uses some static scripted attacks to a certain degree; but since he knows when and how many new troops will be spawned, he could easily use a TYPE 1 attack, adjust the 'number of soldiers to attack' parameter to the exact number and add a timer.
Then again, I guess 1.2 seconds delay is not that bad and it will probably prevent lag.

In other words, you can ignore the text above. :P
A question though: why is it 1.2 seconds?

Re: AI attack changes in the upcoming release

PostPosted: 07 Jun 2014, 00:00
by cmowla
I edited Invasion like you said.
It worked good, most players will be happy if they get 1.2 extra time, in the later waves ;)
I can't tell the difference. However, the replay seemed to run faster (maybe it's just me).
Invasion (r6157).zip
What a terrible finish! I guess I let my guard down too early this time, considering that Invasion is easier in this version than r5503! :$

Re: AI attack changes in the upcoming release

PostPosted: 07 Jun 2014, 07:10
by Skypper
It definitly runs smoother :D
I could watch your whole replay 10x speed.

later today I will edit the MP version to, forget that one yesterday

Apparently it works in the Beta Winter version to

Re: AI attack changes in the upcoming release

PostPosted: 07 Jun 2014, 07:39
by Lewin
A question though: why is it 1.2 seconds?
Good question. The game can have a maximum of 12 players. Every tick we run the AI update on one player, in order to spread out the load. So each player gets updated on a different tick, every 1.2 seconds.

Re: AI attack changes in the upcoming release

PostPosted: 07 Jun 2014, 07:51
by Skypper
And that was also the reason that previously 8 players was the maximum, because you didn't want it to be slower?

Re: AI attack changes in the upcoming release

PostPosted: 07 Jun 2014, 09:39
by The Dark Lord
A question though: why is it 1.2 seconds?
Good question. The game can have a maximum of 12 players. Every tick we run the AI update on one player, in order to spread out the load. So each player gets updated on a different tick, every 1.2 seconds.
Ahh that makes sense. However, does that mean that some players 'see everything' one second earlier than some other players? How is it still in synch if everyone gets updated on a different tick? (this might be off-topic but I want to know :P).

Re: AI attack changes in the upcoming release

PostPosted: 07 Jun 2014, 10:32
by Lewin
And that was also the reason that previously 8 players was the maximum, because you didn't want it to be slower?
No, 0.8 seconds vs 1.2 seconds doesn't matter for AI updates, and we could have changed it anyway if we wanted it to update more often. The only real reason for the limit of 8 before was that it was the limit from the original game. Also it's impractical to fit more players into interfaces like the map editor (player selector and alliances for example).
A question though: why is it 1.2 seconds?
Good question. The game can have a maximum of 12 players. Every tick we run the AI update on one player, in order to spread out the load. So each player gets updated on a different tick, every 1.2 seconds.
Ahh that makes sense. However, does that mean that some players 'see everything' one second earlier than some other players? How is it still in synch if everyone gets updated on a different tick? (this might be off-topic but I want to know :P).
We're only talking about the AI update remember. I'm not sure what you mean about players seeing everything. Yes AI's make decisions on different ticks. If you put 12 AIs near each other then their first update (when they place the school) will occur one tick after each other and you should be able to observe that.