PDA

View Full Version : Getting Computer Players to attack



YourMaster
September 10th, 2014, 22:56
Has anybody managed to get the rival keepers to attack the player through a level script?

As far as I can tell, non of the computer processes have any effect. The computer player will not tunnel towards your dungeon, and CTA does not work properly.

YourMaster
September 11th, 2014, 11:21
In case people are wondering, this is the result of setting the 'Attack Plan 1' that is available for computer players:
1518

As you can see, it consists of just random digging.

Metal Gear Rex
September 11th, 2014, 11:49
As you can see, it consists of just random digging.

Makes for some neat tunnels though.

YourMaster
September 11th, 2014, 12:25
Yes. Notice the tunnels are all neatly fortified, reducing the risk of an actual attack.

Woudo
September 12th, 2014, 19:11
Is it possible to change an AI's behavior type with an IF command?

Say you set them up as type 4 (defensive) but swap it to type 0 (aggressive) after the player has 15 creatures. Would that work?

YourMaster
September 12th, 2014, 19:28
I was simply playing around with type 0, and trying to get that one do a direct attack. Without success. The two things mostly resembling an attack where digging long tunnels all over, or the computer playing using the wall-hug algorithm and just keep digging a long tunnel.

Both methods are not even close to launching an actual attack against the player.

dayokay
September 12th, 2014, 19:34
Is it possible to change an AI's behavior type with an IF command?

Say you set them up as type 4 (defensive) but swap it to type 0 (aggressive) after the player has 15 creatures. Would that work?

NO. I asked the same question a while back, and Mefisto was very clear that this wouldn't work. Don't think he elaborated more than that. It would certainly be useful if you could switch keepers between defensive and aggressive during a map.

YourMaster
September 12th, 2014, 20:10
NO. I asked the same question a while back, and Mefisto was very clear that this wouldn't work. Don't think he elaborated more than that. It would certainly be useful if you could switch keepers between defensive and aggressive during a map.

I'm not sure,... it would be more convenient, but the difference between the different computer players is the different processes they have assigned, and different orders of the processes. You could at a specific point assign the offensive process (Attack plan 1) to the computer player with high priority. That has basically the same effect.

However, my issue is, that even the aggressive processes (Attack plan 1 and Safe Attack) do not result in an effective or guided attack. Not for me anyhow, but perhaps somebody has figured out how to tweak the values to get results. Or has some alternative idea.

0etelaer
April 26th, 2016, 09:19
If you want a computer player to attack, best use the Blue one.
That is the most aggressive or intelligent computer player.
The Green one will also attack, but is a bit more defensive.
The Yellow keeper is the weakest, or most stupid, AI keeper.

Usually it takes time to attack, because all rooms have to be build.
So give it lots of imps, maybe also give it all the rooms it needs.
And not to much Gold to dig. You can script the Gold of the AI.
The more imps the AI keeper has, the sooner it will attack, so you might give him some extra imps level 3 or higher.

The attacks with creatures, and Call to Arms, begin once the dungeon of player0 has been breached.
Not before. Once the dungeon is breached, they will put Call to Arms on the Heart, Treasure or the Prison.
The AI Keepers sometimes dig corridors, but once they have all reinforced, they dig along rock and lava.
The AI Keepers are not very persistent in attack, unless they can claim the ground of player0, that they will defend once claimed.

Not sure how helpful this is, I never had that problem. Contrary, I often try to slow down their attacks.
The AI Keepers will become really aggressive, if they don't have enough room to build lairs and workshops.
They can throw all creatures at once, use spells much quicker than player0, but also do a lot of stupid things that wear them out.
U can use a Tunneller to breach the dungeon, or put the AI Keeper close enough to Player0 that is will dig a breach.
The script doesn't do much, the AI is already scripted to attack, therefor arranging the map should be able to solve the problem.
Most aggressive are the AI Keepers, sometimes, once all rock and lava around their dungeon already is dug out.

YourMaster
April 26th, 2016, 09:27
Thanks for the reply. I'm sorry to break it to you, but the color of the player doesn't change the behavior of it at all. There are several AI's to choose from, and you can assign each to every color.

And I know it's possible to create the proper conditions in which the computer player attacks, which is not what my question is about. I want to directly manipulate the computer processes to tell the computer 'attack now'. Take a look here (http://keeper.lubiki.pl/dk1_docs/dk_scripting_ref.htm#scrpt_group_compluter) to see what I mean.

0etelaer
April 26th, 2016, 10:56
Thanks for the reply. I'm sorry to break it to you, but the color of the player doesn't change the behavior of it at all. There are several AI's to choose from, and you can assign each to every color.
I've noticed the AI players acting the in the way I described.
Both from playing, as from maps that I had build myself.

Color is not the only difference, the colors also decide what place the AI Computer_Player gets in the tab.
Blue is the one on top, and is used in the original game always as the default AI opponent.
Yellow is only used if there are three AI keepers, and is very much less developed in it's behavior.
The difference between green en blue is less than the difference between yellow and the other two, but there is a difference in AI.

Maybe I don't understand your question, because all AI Keepers attack me quickly when I play.
The computer process scripts, I used it to let the computer build other sized rooms, and that worked, but never noticed any other AI behavioral changes from using it in scripts. It is used in level 20, but the behavior of the AI in level 20 is rather default, and looks to me more decided by the way the map is designed, than by the computer process commands. Whatever it does in behavior, it will be a detail activity, is any effect, rather than any decisive strategy.

Reading the commands (http://keeper.lubiki.pl/dk1_docs/dk_scripting_ref.htm#scrpt_group_compluter), DIG TO GREEDY GOLD2 would be the command you may want to try to make the AI attack.

As I said, I tested the room size commands in that list, they worked fine, just saw a temple 5*5 instead of the 3*3 as default today, and other rooms I scripted from that list, but for using commands for AI behavior means that you must understand the AI first and test a lot for it to make it work.
DIG TO GREEDY GOLD or DIG TO GREEDY GOLD2 could work to start an attack with a timer, but what is meant by "attack" will depend on many things. Attack by imps, or attack by Call to Arms? I would guess it would be an attack by imps, because generally Dungeon Keeper calls attack taking tiles. Like building a bridge. For visible effect, a breach will be needed.

YourMaster
April 26th, 2016, 14:06
Yes, player colors determine the place in the interface, player0 (you) is red, player1 is blue, player2 is green, player3 is yellow and player_good is white, see here (http://keeper.lubiki.pl/dk1_docs/dk_scripting_ref.htm#scrpt_players). However, when you make a map you have to define the players (http://keeper.lubiki.pl/dk1_docs/dk_scripting_ref.htm#scrpt_cmd_computer_player) to make them do anything, and in that command you assign which AI you want, the best one or one that is only defensive or just build small rooms or whatever. If you define two players on a map it is easily possible to make player1 very weak and player 3 good.

And yes, I've read the commands there and they work, but you'll also notice a lot is not documented yet. The DIG_TO_GREEDY gold command can be used to make the player dig further and hopefully run into the player, but it might just as well dig the other way and it also depends on how much gold it has.
What I want is to trigger one of the attack plan processes, based on a condition of my choosing. For example make both blue and green attack the player the moment he converts the knight.

And yes, everything the computer players do is determined by the defined processes, and I've played around with it a bit, but have not managed to trigger an attack the moment of my choosing, while this is possible as the AI sometimes actively decides to do an attack.
If you're interested to play around with it as well, in KeeperFX you can use the 'compuchat' command line option (https://github.com/dkfans/keeperfx/wiki/Command-Line-Options) to make the Computer Players tell you whatever they decide to do.

0etelaer
April 28th, 2016, 00:37
There are tricks possible, to make an AI Keeper to attack when you want.
For as far the Computer_Player goes, these are much more different in behavior that the colors. Most levels I made where with several AI Keepers, I have lots of experience with tuning AI Keepers. The map Alcatraz you played last week, I originally had the blue Keeper thee, but tested the Green keeper later, redid the script, in order to notice any difference. I noticed not much difference on that map, but noticed differences on other maps. Very small, and these differences can be for many reasons, since the routines the DK engine walks through, are connected to the speed of the computer that it is played on.

But back on topic:
A trick one may try to start an AI Keeper attack on a certain timing, is throwing a creature in the color of the AI Keeper, at the imps that enter that AI Keeper door from an action point. Because once one creature is attacked, the AI Keeper will throw all his creatures there, and place a CTA there. This creature can be anything. An imp or a dragon level 2 or above. But such a trick should be tested and tuned.

This SET_COMPUTER_PROCESS will define tiles being taken, and it is hard to figure out what it does in level 20.
I've been thinking about it, it will make the AI Keeper there dig the Gold south of the map.
I remember playing that level, where the AI would attack the gems in the south, which is very far away from it's dungeon.
It would also place lots or traps there, and imps would attack that gold and gems.
This may have been what that command did.

As said, Dungeon Keeper defines attack as taking tiles and digging, not throwing creatures.
The Vampires and Mistresses that attack the player0's dungeon in level 20, this is done default in all maps.

I presume you want to have the AI Keeper throw creatures at player0, I gave you a trick to achieve that effect.
ADD_CREATURE_TO_LEVEL, player1-2or3, at the action point that gets hit by player0, in order to make that Keeper throw all it's creatures there an set up an CTA. You will have to be sure that the player0 imp taking that tile is there also, in order to start a fight there. This will also work is the dungeon is not breached, but only if there is a claimed tile there where the AI Keeper can throw its creatures.

YourMaster
April 28th, 2016, 00:59
No, I want to AI to start digging towards the red dungeon to attack.

And yes, lvl20 has some of those scripts, I have not played around with that level to see how it works. One of them has some comments there,....
But this is the direction I'm interested in, using those commands to get the AI to do directly what I want when I want it.

Maxwell
April 28th, 2016, 06:04
Hey, what 'bout this, you create gold tiles which lead the AI dungeon to the Player's dungeon?

YourMaster
April 28th, 2016, 07:09
That works in leading to an attack eventually, but you cannot control the timing of the confrontation based on player actions. If I want the attack to occur as soon as the torture room is researched, and some players research quickly others slowly, this doesn't help.

The thing is, by using the script to modify the computer process, this is possible. We just haven't figured out how to use these script commands properly, which is a shame.

Woudo
April 28th, 2016, 13:58
Hey, what 'bout this, you create gold tiles which lead the AI dungeon to the Player's dungeon?

Unfortunately that's what you need to do. A combination of open path, gold and water leading from one dungeon to the other. It can't be just a single tile either as the AI doesn't handle locked doors so well.

If you want the player to be constantly threatened by the AI, you either build their majority army out of explorers (Flies/Hounds explore early, Mistress/Vampire/Reapers explore after max level) or you have 2-tile dirt path connecting both hearts. The imps will fight over territory which will make the AI drop their creatures at the 'frontlines' repeatedly.

YourMaster
July 18th, 2016, 01:42
I ran into this piece of code in file player_comptask.c:


TbBool create_task_dig_to_attack(struct Computer2 *comp, const struct Coord3d startpos, const struct Coord3d endpos, PlayerNumber victim_plyr_idx, long parent_cproc_idx)
{
struct ComputerTask *ctask;
SYNCDBG(7,"Starting");
ctask = get_free_task(comp, 0);
if (computer_task_invalid(ctask)) {
return false;
}
if ((gameadd.computer_chat_flags & CChat_TasksScarce) != 0) {
message_add_fmt(comp->dungeon->owner, "Player %d looks like he need a kick.",(int)victim_plyr_idx);
}
ctask->ttype = CTT_DigToAttack;
ctask->dig_somewhere.startpos.x.val = startpos.x.val;
ctask->dig_somewhere.startpos.y.val = startpos.y.val;
ctask->dig_somewhere.startpos.z.val = startpos.z.val;
ctask->dig_somewhere.endpos.x.val = endpos.x.val;
ctask->dig_somewhere.endpos.y.val = endpos.y.val;
ctask->dig_somewhere.endpos.z.val = endpos.z.val;
ctask->field_8C = parent_cproc_idx;
ctask->dig_somewhere.target_plyr_idx = victim_plyr_idx;
ctask->lastrun_turn = 0;
ctask->flags |= 0x04;
// Setup the digging
setup_dig_to(&ctask->dig, startpos, endpos);
return true;
}

My best guess is we should use this command to get the computer player to attack: SET_COMPUTER_GLOBALS(PLAYER1,7,7,7,7,7,7)
This command should make the CP dig a tunnel from one location to another, exactly what you'd want. Now just figure out what number to use instead of '7'.

watler253
July 18th, 2016, 21:16
SET_COMPUTER_GLOBALS(PLAYER1,startpos.x,startpos.y ,startpos.z,endpos.x,endpos.y,endpos.z)

Is this what you mean ?

To be sure I don't misunderstand
X is Horizontal axis and Y Vertical axis
Z is used for ?

YourMaster
July 18th, 2016, 22:15
I don't know how it works yet, but that isn't it. Still have to play around with it, but shared it yesterday in the hopes that anybody else found out how to use it overnight. You can see the complete file here (https://github.com/dkfans/keeperfx-stable/blob/master/src/player_comptask.c).

This command isn't documented at all yet, see here (http://keeper.lubiki.pl/dk1_docs/dk_scripting_ref.htm#scrpt_cmd_compctrlparam). But somehow we need to set 'Computer dig to attack' which is listed there. The computer globals command however only allows numbers (http://keeper.lubiki.pl/dk1_docs/dk_scripting_ref.htm#scrpt_cmd_set_computer_global s), and does not allow to specify the process by name (Computer dig to attack) so you have to indicate the index of it. My first guess was '7' because it was number 7 here (https://github.com/dkfans/keeperfx-stable/blob/master/src/player_comptask.c#L116), but that doesn't seem right.

The command does not seem to leave much room for both x, y and z coordinates, but when it would the game usually means the subtile. (x,y give the tile on the map, and each tile has 9 subtiles which is z)

watler253
July 18th, 2016, 22:48
(x,y give the tile on the map, and each tile has 9 subtiles which is z)
So Z is either 1, 2, 3, 4, 5, 6, 7, 8 or 9 ?

You probably aware of this but this is used in the script map00014.txt

SET_COMPUTER_GLOBALS(PLAYER1,60,1,1,1,1900,1)
SET_COMPUTER_GLOBALS(PLAYER2,70,1,2,1,1700,1)
(I was 100% wrong since 1700 or 1900 can't be a position value)

One time I tried to change these value (something like this: 80,1,2,1,1800,1) but noticed nothing ingame.
Maybe these value are near the default value and it doesn't make any difference?
One thing I didn't try yet is remove it from the script and look if the AI in level 14 is different but you might have already tried. :S

YourMaster
July 18th, 2016, 23:09
You're forgetting you actually need to somehow indicate the process/task. The SET_COMPUTER_GLOBALS is just the command that you want to tweak a certain process, and you have 6 numbers that have to indicate WHICH process and how. The same command can also be used to make the computer player place a certain room in a certain size, or dig to gold when he has just a certain amount left.

EDIT:
On lvl14, and I don't know why, that command causes the CP to start with a delay. To clearly see the difference change the script and remove the command for one of the players, and for the other one change it to 6000 or something, and you'll see that the one will start right away while the other one will wait quite a while.

watler253
July 18th, 2016, 23:26
I don't get it, the script for level 14 only has these commands:


SET_COMPUTER_GLOBALS(PLAYER1,60,1,1,1,1900,1)
SET_COMPUTER_GLOBALS(PLAYER2,70,1,2,1,1700,1)

SET_COMPUTER_CHECKS(PLAYER1,"CHECK FOR NEUTRAL PLACES",1000,0,0,0,30000)
REM SET_COMPUTER_CHECKS(PLAYER2,"CHECK FOR NEUTRAL PLACES",1000,0,0,0,30000)

Nothing else, and for whatever reason one command is REMoved.

Well, I'll follow your result if you got some, manipulating AI behaviors is something I'm interested in and I would like to help.

YourMaster
July 19th, 2016, 00:10
Well, I've played around with it a bit, and I've given up again for now. Especially because they are unable to be used within conditional blocks, but also because I feel like I just do random stuff to see what sticks.

In Level 14, change the script to this:


REM SET_COMPUTER_GLOBALS(PLAYER1,60,1,1,1,1900,1)
SET_COMPUTER_GLOBALS(PLAYER2,70,1,2,1,6000,1)

You'll find that Blue will start building rooms and digging for rooms almost straight away, while green will wait for quite a while before starting to do anything. This command seems to be included on this level to give the player a bit of a head start over his rivals.