componentAvailable()

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:

componentAvailable()

Post by aubergine »

I'm struggling to understand the docs for this function -- what is a component type? (I couldn't find any constants relating to component types)

Also, how would we check if a component is available for a specific player?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: componentAvailable()

Post by NoQ »

Component type constants are unavailable (forgotten, i think), that's why i re-define them manually all across NullBot (:

Code: Select all

_global.iHaveHover = function() {
	const COMP_PROPULSION=3; 
	for (var i = 0; i < propulsionStats.hover.length; ++i)
		if (componentAvailable(COMP_PROPULSION, propulsionStats.hover[i].stat))
			return true;
	return false;
}
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: componentAvailable()

Post by aubergine »

Any idea where those constants are defined in C++ code? I looked in component.cpp and component.h but they don't appear to be defined there... :s
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: componentAvailable()

Post by NoQ »

User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: componentAvailable()

Post by aubergine »

Awesome, tvm.

I created a ticket regarding the missing constants: http://developer.wz2100.net/ticket/3898
"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: componentAvailable()

Post by Per »

I've changed componentAvailable(), it can now take a single parameter containing the component name - specifying the component type is deprecated.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: componentAvailable()

Post by aubergine »

Excellent! :D
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: componentAvailable()

Post by NoQ »

Per wrote:I've changed componentAvailable(), it can now take a single parameter containing the component name - specifying the component type is deprecated.
Aha, backwards compatibility is there. Thanks (:
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: componentAvailable()

Post by NoQ »

NoQ wrote:Aha, backwards compatibility is there. Thanks (:
And then we run into a funny riddle.

Suppose we have something like var weapons = [ "MG1Mk1", "MG2Mk1" ].
What will happen if we try to evaluate weapons.filter(componentAvailable)? (:
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: componentAvailable()

Post by aubergine »

Ah, good point. Same would happen for weapons.some(componentAvailable)

Maybe we should break backwards compatibility, I think it would be worth it in this instance.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: componentAvailable()

Post by NoQ »

aubergine wrote:Maybe we should break backwards compatibility
I'd have to re-make my challenge maps :oops:

Maybe just add this to the "gotchas" section of the docs?
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: componentAvailable()

Post by aubergine »

An alternative would be to do this:

Code: Select all

function toAvailableComponents = function(component) {
   // still has all three params passed in from .filter(), but only passes first one on to the JS API fn
   return componentAvailable(component);
}

var availableWeapons = weapons.filter(toAvailableComponents);
But it would be so much nicer if the native function could be used...
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Post Reply