Jump to content

Default aggressiveness for units?


Sidi
 Share

Recommended Posts

Hi everyone,

I've made a map where the AI starts with a solid 300 troops, but for some reason, it seems the AI is refusing to move them. They are all stuck in a "defensive" setting, attacking on sight and then returning to their spot. No attacks, no resource gathering, etc.

Is there a way to revert those units' initial behaviour back to normal?

Link to comment
Share on other sites

The initial behaviour is aggressive for all units, but the AI likes to set its units to defensive unless it's attacking or gets attacked.

Changing the stance is possible through trigger scripts, but it's quite likely that the AI will change it back to defensive rather soon.

Maybe you should develop your map to work with triggers instead of relying on the AI?

Link to comment
Share on other sites

2 minutes ago, sanderd17 said:

The initial behaviour is aggressive for all units, but the AI likes to set its units to defensive unless it's attacking or gets attacked.

Changing the stance is possible through trigger scripts, but it's quite likely that the AI will change it back to defensive rather soon.

Maybe you should develop your map to work with triggers instead of relying on the AI?

I'm not familiar with triggers at all. Having a look at the documentation now. How far can I go with triggers? Can I implement any form of AI I want, e.g. make the AI manage small units and make each unit perform a set of tasks? This map is sort of a siege map, so playing on the defensive side, this map kinda requires you to use the same troops for resource production and defence, and to anticipate enemy breaches to relocate behind the next line of defence.

But first things first. Right now I'd just like my opponent to not slack off and to attempt to kill me. Can I force specific units to stay aggressive / keep them moving around?

Link to comment
Share on other sites

Triggers can execute regular commands that players can also give to their units. But triggers have the extra advantage that they can also alter the simulation directly, even in ways that wouldn't be allowed by player commands (f.e. spawning units directly, altering the health of units, ...)

So yes, you can make your entire AI with triggers, but you have to watch out that the map is still balanced.

EDIT: I do have to warn you that triggers are to be experimented with, so if you go for that route, you should expect to test quite a few things out.

Link to comment
Share on other sites

Thanks, that sounds interesting! So I could technically implement a "siege" victory condition with regular reinforcements via triggers... Interesting :-)

Can I alter the health of my units? And, can I prevent units from doing specific actions (building farmland)? I'd then be able to script attrition when food runs out!

  • Like 1
Link to comment
Share on other sites

I'll first try to implement a siege victory condition directly in C++ (will look up the ceasefire code and the conquest gameType for timing handling), I'm way better at that than JS. And I suppose C++ code runs much faster than JS triggers?

Edit: ehm, I feel like I'm missing something, looking at the source code. So if I understand, the CPP code provides libraries, does rendering, and runs a JS engine, and the whole game simulation is JS?

Edit 2: found the JS files.

Edited by Sidi
Link to comment
Share on other sites

Implementing some victory condition in C++ will be very hard. The C++ side isn't able to see a lot of data in the game. F.e. it knows where a certain entity is, and what its obstruction size is, but it has no info on what classes the entity has (is it a wall, a unit, a siege engine, ...).

And JS is easy to learn if you know C++. The main thing you need to know is that it has dynamic types, and you can f.e. add random attributes to any object and work with those, without specifying a class for that object. Classes in JS are called prototypes (although the latest spec has some class keyword but that's just syntactic sugar for prototypes), and these prototypes add default attributes and methods to objects, so you can work easier with it.

If you know how to program in a C-style language, just keeping a good reference next to you (like https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference ) will get you a long way.

Link to comment
Share on other sites

Thanks. I've set up a Siege victory condition which basically just announces reinforcements on a timer, with different messages for the attacking and defending teams.

I'll look at the regicide code to find out how to spawn troops. Might use some in-game actors to define spawn points in the way regicide spawns heroes at set locations.

Currently what I'm trying to figure out is how do I read custom parameters from the map's XML. I want to use that to define what troops and resources are sent at reinforcements, how often, how many times, and to whom.

Link to comment
Share on other sites

Most often, you don't need to read from the map XML, but you can read from the game state. The map is loaded to the game state anyway.

All data should be available in the game state, with the exception of the ground texture used (as that falls under graphical data, and thus isn't available in the simulation runtime, but this should become available in some way in the future). What data do you want exactly? Entities can be found through RangeManager calls and further filters. Terrain elevation can be found from the terrain component or from the position component. Or do you want something else?

Link to comment
Share on other sites

6 hours ago, sanderd17 said:

Most often, you don't need to read from the map XML, but you can read from the game state. The map is loaded to the game state anyway.

All data should be available in the game state, with the exception of the ground texture used (as that falls under graphical data, and thus isn't available in the simulation runtime, but this should become available in some way in the future). What data do you want exactly? Entities can be found through RangeManager calls and further filters. Terrain elevation can be found from the terrain component or from the position component. Or do you want something else?

I want to add custom options. Basically, it would make sense to have siege maps in e.g. Gaul with regular small groups of units (e.g. ~30-50 naked fanatics) spawning in random locations when a Gaul is besegied by Romans. But in some other maps (specifically historical battles, let's say Alesia to stay on the Gaul example) you might want one very large wave of reinforcement that takes an hour to arrive. So, I want to set some default values for wave size / duration between waves / wave count in the map XML directly.

Link to comment
Share on other sites

Well, every map has some JSON data (for scenarios in the xml, fit random maps in a separate file), and that would allow custom data.

But currently the custom data doesn't get passed on to the rest of the simulation, and there may also still be a problem with persistent map settings (when you play a map that doesn't define these custom keys, it can still have them because they persisted from the previous map).

It it's planned however to fix that.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...