Page 1 of 1

droids - .armed and .group properties

Posted: 11 Feb 2012, 20:05
by aubergine
Currently the .armed and .group props only get added if applicable to the droid. However, this means that in JS there's often going to be additional checks (regardless of how simple they are) to accommodate these transient properties.

Could the https://github.com/Warzone2100/warzone2 ... tfuncs.cpp be updated to something like this:

Code: Select all

	if (isVtolDroid(psDroid))
	{
		value.setProperty("armed", 100.0 / (double)asWeaponStats[psDroid->asWeaps[0].nStat].numRounds
		                  * (double)psDroid->asWeaps[0].ammo);
		// why doesn't the above property have a "QScriptValue::ReadOnly" setting?
	}
	else
	{
		value.setProperty("armed", -1, QScriptValue::ReadOnly);
	}
	if (psDroid->psGroup)
	{
		value.setProperty("group", (int)psDroid->psGroup->id, QScriptValue::ReadOnly);
	}
	else
	{
		value.setProperty("group", -1, QScriptValue::ReadOnly);
	}
This way the .armed and .group properties always exist so when scripts are checking those props they won't need to first check to see if they exist.

Re: droids - .armed and .group properties

Posted: 16 Feb 2012, 19:54
by Per
Would it be better if they returned null?

Re: droids - .armed and .group properties

Posted: 16 Feb 2012, 21:30
by aubergine
yes, null is fine.

Re: droids - .armed and .group properties

Posted: 16 Feb 2012, 22:52
by Per
Done. (for 3.2)

Re: droids - .armed and .group properties

Posted: 18 Feb 2012, 04:20
by aubergine
Could structureObj.modules be set to null (rather than property not existing) if the structure doesn't have modules, in a similar way to .armed and .group properties on droids?

Re: droids - .armed and .group properties

Posted: 18 Feb 2012, 04:25
by aubergine
Also, .range is defaulting to -1 if the structure or droid doesn't have a weapon - could it default to null for consistency with other props mentioned above?

Also, does range apply to sensors? From the code it looks like just weapons, but I don't know enough about the C++ objects being used to work out whether psStruct->asWeaps.nStat could contain a sensor?

Re: droids - .armed and .group properties

Posted: 18 Feb 2012, 11:01
by Per
Ok, modules and range are now null. Not sure about sensors and range.