[SCRIPTING] Strange TEMPLATE problem ...

Do you need help? Ask here!

Bug reporting belongs here: http://developer.wz2100.net/newticket
User avatar
Goth Zagog-Thou
Regular
Regular
Posts: 1582
Joined: 06 Jan 2007, 08:08
Location: Delta Base

[SCRIPTING] Strange TEMPLATE problem ...

Post by Goth Zagog-Thou »

Normally I'm able to sort this stuff out on my own, but this one has me stumped.

Code: Select all

error   |09:14:45: [droidTemplateShutDown] Static template Heavy Laser Python Tracks in player template list!
error   |09:14:45: [droidTemplateShutDown] Assert in Warzone: ../../../src/droid.c:2435 (!pTemplate->prefab), last script event: 'CheckConditions'
error   |09:14:45: [droidTemplateShutDown] Static template Cyborg Repair Unit in player template list!
error   |09:14:45: [droidTemplateShutDown] Assert in Warzone: ../../../src/droid.c:2435 (!pTemplate->prefab), last script event: 'CheckConditions'
error   |09:14:45: [droidTemplateShutDown] Static template Cyborg Assault Gunner in player template list!
error   |09:14:45: [droidTemplateShutDown] Assert in Warzone: ../../../src/droid.c:2435 (!pTemplate->prefab), last script event: 'CheckConditions'
error   |09:14:45: [droidTemplateShutDown] Static template Cyborg Needle Gunner in player template list!
error   |09:14:45: [droidTemplateShutDown] Assert in Warzone: ../../../src/droid.c:2435 (!pTemplate->prefab), last script event: 'CheckConditions'
error   |09:14:45: [droidTemplateShutDown] Static template Gauss Cannon Python Tracks in player template list!
error   |09:14:45: [droidTemplateShutDown] Assert in Warzone: ../../../src/droid.c:2435 (!pTemplate->prefab), last script event: 'CheckConditions'
The above code is from the debug --script log I use to troubleshoot things going on with my scripts. The script section I'm getting this from is:

Code: Select all

	addTemplate(PythonGauss, player);
	addTemplate(NeedleGunner, player);
	addTemplate(AssaultGunner, player);
	addTemplate(CyborgRepair, player);
	addTemplate(PythonHvLaser, player);
Here's my problem: The player builds a Factory, then a Cyborg factory. The Templates are fine for the Factory (PythonGauss and PythonHvLaser), and appear as they should. The Cyborg Templates, however, don't appear in the Cyborg Factory build list.

Any clue what's going on here? I even spent an hour browsing the Warzone source code, and there doesn't appear to be any distinction between the differing production types.

Thanks in advance. :)
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by Per »

There are two different types of templates - static templates and player templates. Static templates are defined prior to game start in templates.txt, and contains templates for starting trucks, AI units and cyborgs. The player templates contain all player made designs. The addTemplate() function copies a template from one player (irrespective of static or player list) to another player's player template list. However, copying from a static list to a player list is an error, and should not have been possible. I think addTemplate() is a dangerous function that should not be used. I am not sure what you are trying to do, but maybe you could instead dynamically generate templates inside the script? These get added to the correct template list.
User avatar
Goth Zagog-Thou
Regular
Regular
Posts: 1582
Joined: 06 Jan 2007, 08:08
Location: Delta Base

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by Goth Zagog-Thou »

Will try that. So far that's the only use of addTemplate() that I've needed.

So in a way I've found another glitch? Wow. :lol2:
User avatar
Goth Zagog-Thou
Regular
Regular
Posts: 1582
Joined: 06 Jan 2007, 08:08
Location: Delta Base

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by Goth Zagog-Thou »

Well, there doesn't seem to be a way (in the documentation, anyway) to build a template using the script. Anyone have any info on this?
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by Per »

The easiest way is probably to look at how I did it in semperfi, function vtolFactoryBuildVtol(). You use isComponentAvailable() to check if the component is, indeed, available, then call assembleWeaponTemplate() to construct a template with the components you want, and then pass it to buildDroid().

I added the function here, for your convenience, in case you don't have master checked out:

Code: Select all

function void vtolFactoryBuildVtol(STRUCTURE _factory)
{
	local	TEMPLATE	_newTemplate;
	local	BODY		_bestBody;
	local	WEAPON		_bestWeapon;
	local	int		_rand, _idx;

	if (_factory == NULLOBJECT or not structureIdle(_factory))
	{
		return;
	}

	// choose branch: AT, AS or splash
	_rand = random(3);
	_idx = 0;
	_bestWeapon = NULLSTAT;
	if (_rand == 0)	// anti-tank
	{
		_idx = numAtWeapons - 1;
		while (_idx >= 0 and _bestWeapon == NULLSTAT)
		{
			if (isComponentAvailable(me, atWeapon[_idx]))
			{
				_bestWeapon = atWeapon[_idx];
			}
			_idx--;
		}
	}
	if (_rand == 1)	// anti-structure
	{
		_idx = numAsWeapons - 1;
		while (_idx >= 0 and _bestWeapon == NULLSTAT)
		{
			if (isComponentAvailable(me, asWeapon[_idx]))
			{
				_bestWeapon = asWeapon[_idx];
			}
			_idx--;
		}
	}
	if (_rand < 2 and _bestWeapon == NULLSTAT)
	{
		_rand = 2;	// try this instead
	}
	if (_rand == 2)	// indiscriminate mass destruction
	{
		_idx = numMdWeapons - 1;
		while (_idx >= 0 and _bestWeapon == NULLSTAT)
		{
			if (isComponentAvailable(me, mdWeapon[_idx]))
			{
				_bestWeapon = mdWeapon[_idx];
			}
			_idx--;
		}
	}
	if (_bestWeapon == NULLSTAT)
	{
		dbgPlr("Failed to find a weapon for VTOL design");
		return;
	}
	_bestBody = NULLSTAT;
	if (not seenAnyAA)
	{
		// no AA seen, so go for the cheapest bodies -- no need for defense yet!
		if (isComponentAvailable(me, bugBody))
		{
			_bestBody = bugBody;
		}
		else if (isComponentAvailable(me, viperBody))
		{
			_bestBody = viperBody;
		}
	}
	else
	{
		// build sturdiest body available with a decent engine
		if (isComponentAvailable(me, retributionBody))
		{
			_bestBody = retributionBody;
		}
		else
		{
			if (isComponentAvailable(me, scorpionBody))
			{
				_bestBody = scorpionBody;
			}
			else if (isComponentAvailable(me, cobraBody))
			{
				_bestBody = cobraBody;
			}
		}
	}
	if (_bestBody == NULLSTAT or getBodySize(_bestBody) > skGetFactoryCapacity(_factory))
	{
		dbgPlr("Failed to find a viable body for VTOL design");
		return;
	}

	_newTemplate = assembleWeaponTemplate(me, _bestBody, vtolPropulsion, _bestWeapon);

	if (_newTemplate == NULLTEMPLATE or not skCanBuildTemplate(me, _factory, _newTemplate))
	{
		dbgPlr("Failed to construct viable VTOL template");
		return;
	}
	buildDroid(_newTemplate, _factory, me, 1);
}
User avatar
Goth Zagog-Thou
Regular
Regular
Posts: 1582
Joined: 06 Jan 2007, 08:08
Location: Delta Base

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by Goth Zagog-Thou »

Oh sweet, thanks Per. Just what I was looking for. :P

Nice function, btw. I'll simplify it a bit for use in the Campaign (quite a lot, probably :lol2: ), if you don't object.
User avatar
Goth Zagog-Thou
Regular
Regular
Posts: 1582
Joined: 06 Jan 2007, 08:08
Location: Delta Base

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by Goth Zagog-Thou »

The more I think about it, the more I'm thinking we'll have to use Master for the Campaign. I'm running into other technical challenges that I've had to work around for 2.3.8.

For example, I can't get research working in the campaign. At all. And I'm pretty sure I understand what one needs to do to *get* it working. Attempts to get it going in 2.3.x simply crash the game, with no output at all.

Yeah. 3.0 lets ya do a lot more.
User avatar
vexed
Inactive
Inactive
Posts: 2538
Joined: 27 Jul 2010, 02:07

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by vexed »

Goth Zagog-Thou wrote: For example, I can't get research working in the campaign. At all. And I'm pretty sure I understand what one needs to do to *get* it working. Attempts to get it going in 2.3.x simply crash the game, with no output at all.
Attach the crash report file for that one.
/facepalm ...Grinch stole Warzone🙈🙉🙊 contra principia negantem non est disputandum
Super busy, don't expect a timely reply back.
User avatar
Goth Zagog-Thou
Regular
Regular
Posts: 1582
Joined: 06 Jan 2007, 08:08
Location: Delta Base

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by Goth Zagog-Thou »

That's what I'm saying. There's no output, at all. The log and the .rpt files were both blank, other than the usual missing sequence.ogg thing.

It's alright. I'll keep working around that issue for now.
User avatar
vexed
Inactive
Inactive
Posts: 2538
Joined: 27 Jul 2010, 02:07

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by vexed »

Oh, one of those crashes.
Poor stack. :(
/facepalm ...Grinch stole Warzone🙈🙉🙊 contra principia negantem non est disputandum
Super busy, don't expect a timely reply back.
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by milo christiansen »

I know I'm a little late but can't you just declare a TEMPLATE in the vlo and pass that to buildDroid()? :geek:
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
Goth Zagog-Thou
Regular
Regular
Posts: 1582
Joined: 06 Jan 2007, 08:08
Location: Delta Base

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by Goth Zagog-Thou »

Not when it's a TEMPLATE for the human player to use in a Cyborg Factory.

I'm getting this issue figured out slowly. It seems that Cyborgs need to be researched rather than built up. So how do you get a Cyborg when you can't research (because that's still broken)? You enable the weapon AND the body after enabling CyborgLegs. It's spotty though -- sometimes it works, other times it won't. It's hit and miss.

I tried dynamically building the TEMPLATE using the code above -- and it isn't working for Cyborgs. Anything else and it works fine.

There's some finer point I'm missing, somehow. But, the good news is that in working this problem I got Components working in the design screen finally, on both Master AND 2.3.8. So at least there's that.

Milo, is there any chance you are able to get Research fixed? Cam 3's Research will be just fine, and it'll be a good launching point for the new Cam 4 Technologies.
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by milo christiansen »

Sorry, I don't know anything about research. I could probably puzzle it out in time but I'm not sure how long it would take :(
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by NoQ »

assembleWeaponTemplate()
Is it possible to construct multi-turret templates with this ... or just somehow? (:
User avatar
Goth Zagog-Thou
Regular
Regular
Posts: 1582
Joined: 06 Jan 2007, 08:08
Location: Delta Base

Re: [SCRIPTING] Strange TEMPLATE problem ...

Post by Goth Zagog-Thou »

Yes, that's how it's done in Per's AI sample above. The game supports up to three turrets per template.