setCommanderLimit() and setConstructorLimit()

For AI and campaign script related discussions and questions
Post Reply
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

setCommanderLimit() and setConstructorLimit()

Post by aubergine »

It's good to see these constants unhardcoded and moved to rules.js.

However, I wonder if it would be better to have a generic setDroidLimit(player, limit[, droidType]) function?

EDIT: Just realised there is already a setDroidLimit() function, but it doesn't have a param to define droid type.

With such a function, it would be possible to set limits for DROID_SENSOR, DROID_SUPERTRANSPORTER, etc. And, if DROID_ANY constant is used (also the default for droidType param if it's not specified), it would set the max number of droids that the player could have (irrespective of type).

Example use: In a campaign mission or challenge game, this could be used to create a mission whereby a player can research a certain type of droid (eg. super transport) but not build any until they've destroyed enemy AA defences at which point the limit for super transport is increased from 0 to 10 or whatever, thus allowing them to actually produce transports.

I think having a single function will be much cleaner - single point of access to setting droid limits, it would also tie up nicely with the existing getDroidLimit(player, droidType) function, and it would be less documentation for script devs to wade through ;)

The C++ code could then have a 2D array:

Code: Select all

droidLimits[player][droidType] = limit
...and one of the droidType records would be for DROID_ANY = max number of droids that the player can have.

I imagine having something similar for structures would be worthwhile, keeping everything consistent and centralised wherever possible.

EDIT: Also it would be useful if the function returned the limit that's been set (eg. if DROID_ANY is limited to 40 and I try setting DROID_SENSOR to 50, I assume DROID_SENSOR will get limited down to 40, but without the return value my script won't know that). Also I believe there's max number of commanders the UI can deal with - something like 5 or 10 on the factory settings panel, so I guess trying to set more than that number of commanders should limit down to whatever the UI can deal with (and js needs to know that extra limiting has been applied via the function return val).
Last edited by aubergine on 02 Dec 2012, 20:23, edited 4 times in total.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by aubergine »

In fact, you could probably have a slightly more elaborate array to keep track of both limits and current numbers:

(using JS notation because I don't know C++ notation heh...)

Code: Select all

droidLimits[player][droidType] = {limit: whatever, count: whatever}
Then everything is in the one place. As part of doing this, I imagine lots of other C++ code would get cleaned up - for example, currently there are only counts for construct / commander / all droids IIRC. Rather than singling out a few specific types, could it not be set-up so that on droid produced the relevant count gets incremented, and on droid destroy it gets decremented? (also inc/dec the DROID_ANY count, prolly also need to deal with droid transfers - eg. nexus assimilation or ally transfer).
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
felipe
Trained
Trained
Posts: 63
Joined: 05 Jun 2012, 20:19

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by felipe »

auber,
I'm not shure to understand you correctly :?
BTW, the functions setDroidLimit and getDroidLimit were introduced by per, not me.
Isn't getDroidLimit solving (part) of your problem ?
You need this function anyway, if you have to check the value before making changes.
And:

Code: Select all

//-- \subsection{getDroidLimit([player[, unit type]])}
//-- Return maximum number of droids that this player can produce. This limit is usually
//-- fixed throughout a game and the same for all players. If no arguments are passed,
//-- returns general unit limit for the current player. If a second, unit type argument 
//-- is passed, the limit for this unit type is returned, which may be different from
//-- the general unit limit (eg for commanders and construction droids).
this function already permit the selection of the type of droid but not the setDroidLimit that:

Code: Select all

//-- \subsection{setDroidLimit(player, value)}
Only set the global limit of droids (before hardcoded to 150)

Making a single function (as you said) that set the droid limits for all type of droid is even better.

There is no need to create arrays and so.
Also, there are no other limits (AFAIK), if you use setDroidLimit you are sure that the limit is set, no need to return a value.
Last edited by felipe on 01 Dec 2012, 02:28, edited 1 time in total.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by aubergine »

Well, I was thinking that the more consistent things are made, the better. Currently there are specific limits for commanders and constructors, why not just allow each type to have a limit set and then everything will work the same.

In any case, it's good to see this stuff moving to JS API where it can more easily be edited in future.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
felipe
Trained
Trained
Posts: 63
Joined: 05 Jun 2012, 20:19

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by felipe »

When the game starts, in rules.js, this functions are called for all players:

Code: Select all

setCommanderLimit(playnum, 10);
setConstructorLimit(playnum, 15);
Setting the same values as before.
When the game is running, JS can call those function again to change the values when needed.
To check the values there is getDroidLimit([player[, unit type]]).

Auber, take a look at the last 2 commit here:
https://github.com/epilef/warzone2100/commits/burn

Waiting for per to approve & merge :wink:
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by aubergine »

Ah, nice new functions :)

In the function comments, can you state what the return values are?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by aubergine »

At what interval is burn damage applied during burn time?

EDIT: I can't wait to start playing with these new functions - for example, when combined with setWeather() the burn time/damage values can be adjusted, so if it's raining burn time is less, if it's snowing burn damage is less, etc.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
felipe
Trained
Trained
Posts: 63
Joined: 05 Jun 2012, 20:19

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by felipe »

aubergine wrote:At what interval is burn damage applied during burn time?
Something like 10 times per second, I saw this during some testing a while ago.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by aubergine »

Hrm, why not just have it applied once per second and apply the full damage? That's 10x less work per object. A human isn't going to notice (1.5 * upgrades) damage being applied every 100ms :s

Also, any news on the return values of the set*() functions?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by aubergine »

Also, can the function be used on scavenger faction?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
felipe
Trained
Trained
Posts: 63
Joined: 05 Jun 2012, 20:19

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by felipe »

aubergine wrote: Hrm, why not just have it applied once per second and apply the full damage? That's 10x less work per object. A human isn't going to notice (1.5 * upgrades) damage being applied every 100ms :s
Burn damage is applied inside the function

Code: Select all

void droidUpdate(DROID *psDroid)
that update lot of things regarding droids and is called 10 times per second (aprox).
What you are proposing have a huge impact on how things work and the changes needed to implement this are quite hard.
IMHO is not worth, but the opinion of developers is welcome :)
aubergine wrote: Also, any news on the return values of the set*() functions?
As I said, the set* functions always succeed, if you set something to 10, then 10 is.
Why returning the same value ?
If I implement what you are sayng, this:

Code: Select all

if (setCostructorLimit(playeraaa, 10) != 10)
will be always false.
Is like doing:

Code: Select all

int i = 10;
if (i !=10) 
   ....
If you have to check the value before making changes, need to use (for example):

Code: Select all

if (getDroidLimit(playerbbb, DROID_CONSTRUCT) < x)
    setCostructorLimit(playerbbb, x);
else 
    ...
Or, maybe, I'm not understanding what you mean ? XD It happens :D
aubergine wrote:Also, can the function be used on scavenger faction?
Scavengers is a player, on game start the functions are called on all players.
Yes, you can :wink:
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by aubergine »

felipe wrote:
aubergine wrote:Also, can the function be used on scavenger faction?
Scavengers is a player, on game start the functions are called on all players.
Yes, you can :wink:
No... Scavengers are not a normal player. Per describes them as a hard-coded "huge hack" - they're not like a normal human or AI player, they even have their own special "S" player id in maps, and their own hard-coded script (scavfact.js) associated with their player id.

In Warzone, both C++ code and JS API, the id of scavengerPlayer is always >= maxPlayers, or -1 if scavengers == false.

In other words, if you've got something working for "all players", that doesn't mean it will work for scavenger player.

For example....

Code: Select all

...
	for (var playnum = 0; playnum < maxPlayers; playnum++)
	{
		setDroidLimit(playnum, 150);
		setCommanderLimit(playnum, 10);
		setConstructorLimit(playnum, 15);

...
The scavenger player does not get initialised by that code. What will their droid, command and constructor limits be considering those functions haven't been called for scav player?
Last edited by aubergine on 01 Dec 2012, 22:47, edited 1 time in total.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by Per »

aubergine wrote:I wonder if it would be better to have a generic setDroidLimit(player, limit[, droidType]) function?
Good idea. I have changed the API to this now, deprecating setCommanderLimit() and setConstructorLimit() - they will be removed before release. So far it only supports DROID_ANY, DROID_COMMAND and DROID_CONSTRUCT.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: @felipe: setCommanderLimit() and setConstructorLimit()

Post by Per »

Concerning the burn damage calculation, I think we need to be able to set that on a per weapon basis. See some discussion in viewtopic.php?f=42&t=8804&p=111081

This requires changes that are bit more extensive, but this is the right way to go, and it will make no sense to be able to set a generic burn damage from scripts afterwards.
Post Reply