Tech Requirements - Page 3

Tech Requirements

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

Would it be possible to add an ability to make units who are no longer in range of the tech giver to completely stop working? By that I mean, fusions stop producing, mexes stop producing, factories stop working, defenses stop firing, etc.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Tech Requirements

Post by zwzsg »

Yes.

You already have them now in EvoRTS, but, I'm posting to say I updated the Better_Ranged_Counted_Multi_Tech.lua on page 1 to fix some bugs, and to make it call the cob functions TechLost and TechGranted, so you can just implement whatever deactivation code you need through those BOS/COB custom call-ins.



Here's an exemple turret script making use of them to deactivate turret if they lose the tech that was necessary to build them:

Code: Select all

piece base, turret, barrel, flare;

static-var CanFire;

#define SIG_AIM 2


Create()
{
	CanFire=FALSE;
}


AimWeapon1(heading, pitch)
{
	signal SIG_AIM;
	set-signal-mask SIG_AIM;
	while(!CanFire)
		sleep 200;
	turn turret to y-axis heading speed <225>;
	turn barrel to x-axis <0> - pitch speed <150>;
	wait-for-turn turret around y-axis;
	wait-for-turn barrel around x-axis;
	return (1);
}


AimFromWeapon1(piecenum)
{
	piecenum = barrel;
}

QueryWeapon1(piecenum)
{
	piecenum = flare;
}

TechLost()
{
	CanFire=FALSE;
	signal SIG_AIM;
	stop-spin turret around y-axis decelerate <10>;
	stop-spin barrel around x-axis decelerate <10>;
}

TechGranted()
{
	CanFire=TRUE;
}





Here's an exemple of a factory getting deactivated when the teach necessary to build it is lost. I didn't clean it from the EvoRTS unit I took from, but the basic idea is to set HasTech to 0 in TechLost and to 1 in TechGranted, and then in the Activate, to not set INBUILDSTANCE to 1 if HasTech is not true. Plus some smoke effect to show the factory state of disability.
http://pastebin.org/139379









Note that disabling unit that lose tech was already possible with the previous version, by having an intermediary gadget implementing a registered function that check for a specific tech:

Code: Select all

if (gadgetHandler:IsSyncedCode()) then

	local function CheckUnitPower(u, ud, team, level)
		return GG.TechCheck("power",team,level,u) -- change "power" by the name of your tech
	end

	function gadget:Initialize()
		gadgetHandler:RegisterGlobal("CheckUnitPower", CheckUnitPower)
	end

end
And then having the BOS/COB calls it regularly:

Code: Select all

piece	base, turret, barrel, flare;

static-var power;

#define SIG_AIM 2

#ifndef LUA1
#define LUA1 111
#endif

lua_CheckUnitPower()
{
	return 0;
}

KeepAnEyeOnPower()
{
	while(TRUE)
	{
		call-script lua_CheckUnitPower();
		if(get LUA1)
			power=TRUE;
		else
			power=FALSE;
		sleep 500;
	}
}

Create()
{
	power=FALSE;
	start-script KeepAnEyeOnPower();
}

AimWeapon1(heading, pitch)
{
	signal SIG_AIM;
	set-signal-mask SIG_AIM;
	while(!power)
		sleep 200;
	turn turret to y-axis heading speed <225>;
	turn barrel to x-axis <0> - pitch speed <150>;
	wait-for-turn turret around y-axis;
	wait-for-turn barrel around x-axis;
	return (1);
}


AimFromWeapon1(piecenum) 
{
	piecenum = barrel;
}

QueryWeapon1(piecenum)
{
	piecenum = flare;
}
That method has the advantage of not requiring the tech to build the turret, but only to fire. But it's less flexible since you have to explicitly write and register a short Lua function for each tech you want COB/LUA scripts to be able to check.
kalda341
Posts: 101
Joined: 19 Nov 2010, 09:44

Re: Tech Requirements

Post by kalda341 »

How would I apply the advanced tech tree in a lua unitdef?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Tech Requirements

Post by zwzsg »

Try something like:

Code: Select all

CustomParams = {
      RequireTech = "2 SomeTech, AnotherTech",
      ProvideTech = "NewTech, 10 OtherNewTech",
   },
kalda341
Posts: 101
Joined: 19 Nov 2010, 09:44

Re: Tech Requirements

Post by kalda341 »

Thanks.
kalda341
Posts: 101
Joined: 19 Nov 2010, 09:44

Re: Tech Requirements

Post by kalda341 »

Would there be a way to modify the advanced tech tree so it works like normal until you get a choice to build two units, after building one you unlock the following tech, but you lock out building the other one and all the following tech?
User avatar
bobthedinosaur
Blood & Steel Developer
Posts: 2700
Joined: 25 Aug 2004, 13:31

Re: Tech Requirements

Post by bobthedinosaur »

Yeah. It is all in the read me isn't it? Look at the one with the heros. Make the new tech use up the old tech, just be sure to set it really high.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

Calling techlost and techgranted via cob in a factory script results in a access violation spring crash (without stacktrace) when the unit providing the tech is destroyed.

Any ideas on what might be wrong?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

Yes Alex, I'd like to buy a vowel.
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Tech Requirements

Post by Google_Frog »

Try turning the factory script into lua. At least you should receive a useful crash report.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Tech Requirements

Post by zwzsg »

Who is Alex?

Can you make me an Evo mutator and spell me the unitnames to spawn and to self D so that I have an easier time reproducing?
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Re: Tech Requirements

Post by SinbadEV »

zwzsg wrote:Who is Alex?
Alex Trebek
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Tech Requirements

Post by smoth »

who was only the host of wheel of fortune as a gag.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

Evolution_RTS-TechCrashDemo.sdz
(2.42 KiB) Downloaded 19 times
Make 2 fusions (hotkey b, n)
Make a hover factory (hotkey b, z)

Tell the factory to make engineers or somethign on repeat, then self d the powerplants.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Tech Requirements

Post by zwzsg »

Thanks. I replicated it.

The problem is not in the tech gadget, it is in the factory animation script.
Specifically, ebasefactory.bos line 53:

Code: Select all

      while(!Maya)
      {
         // Activated animation when needing tech
      }
Add at least a sleep there!
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

Thanks :-)

All that was originally stuff added by you to provide me with an example on how to add requirements to factories, but I have never actually used it, so news to me.

I might have accidentally nuked the sleep at one point (I doubt it but it is certainly possible). I dunno O_o You did that a really long time ago and I haven't really messed with it (the factory script) much since.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Tech Requirements

Post by zwzsg »

Yep, it was you: r220 by forbodingangel on Feb 8, 2012 Diff

Let's hope it will server you as a reminder that:
while(1){} // HANG your computer!
while(1){sleep 666;} // okay

This applies to other languages, outside of Spring, as well.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

I probably wouldn't have caught that without any decent error reporting from spring.

Other languages tell you in various ways (though I've never actually caused an infinite loop in any other language). Moreover, other languages don't require sleeps in the loop (least, not the ones I work with).

Code: Select all

for ($i = 1; $i <= 10; $i++) {
    echo $i;
}
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Tech Requirements

Post by zwzsg »

Other languages tell you in various ways
Most other language/environment hang your computer as well. You were lucky Spring has hang detection.
Forboding Angel wrote:Moreover, other languages don't require sleeps in the loop (least, not the ones I work with).

Code: Select all

for ($i = 1; $i <= 10; $i++) {
    echo $i;
}
This is a finite loop!

Just try with for ($i = 1; $i <= 10; $i += 0) I dare you!
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

Code: Select all

for ($i = 1; $i <= 10; $i++) {
    echo $i;
}
Loops until it reaches the end, z (In this case, the number 10). Doesn't repeat. However, usage is obviously completely different from a while loop in bos.

http://us.php.net/manual/en/control-structures.for.php

But even so:

http://us.php.net/manual/en/control-str ... .while.php

Different language, different structure.
Post Reply

Return to “Lua Scripts”