Page 3 of 4
Re: Tech Requirements
Posted: 09 Mar 2010, 10:50
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.
Re: Tech Requirements
Posted: 06 Apr 2010, 23:26
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.
Re: Tech Requirements
Posted: 09 Dec 2010, 07:31
by kalda341
How would I apply the advanced tech tree in a lua unitdef?
Re: Tech Requirements
Posted: 09 Dec 2010, 10:34
by zwzsg
Try something like:
Code: Select all
CustomParams = {
RequireTech = "2 SomeTech, AnotherTech",
ProvideTech = "NewTech, 10 OtherNewTech",
},
Re: Tech Requirements
Posted: 09 Dec 2010, 19:20
by kalda341
Thanks.
Re: Tech Requirements
Posted: 14 Mar 2011, 20:45
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?
Re: Tech Requirements
Posted: 14 Mar 2011, 20:52
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.
Re: Tech Requirements
Posted: 17 May 2012, 08:12
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?
Re: Tech Requirements
Posted: 18 May 2012, 06:56
by Forboding Angel
Yes Alex, I'd like to buy a vowel.
Re: Tech Requirements
Posted: 18 May 2012, 16:41
by Google_Frog
Try turning the factory script into lua. At least you should receive a useful crash report.
Re: Tech Requirements
Posted: 18 May 2012, 20:21
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?
Re: Tech Requirements
Posted: 18 May 2012, 23:01
by SinbadEV
zwzsg wrote:Who is Alex?
Alex Trebek
Re: Tech Requirements
Posted: 18 May 2012, 23:05
by smoth
who was only the host of wheel of fortune as a gag.
Re: Tech Requirements
Posted: 19 May 2012, 03:04
by Forboding Angel
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.
Re: Tech Requirements
Posted: 19 May 2012, 03:59
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!
Re: Tech Requirements
Posted: 19 May 2012, 04:25
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.
Re: Tech Requirements
Posted: 19 May 2012, 04:55
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.
Re: Tech Requirements
Posted: 19 May 2012, 06:58
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;
}
Re: Tech Requirements
Posted: 19 May 2012, 16:48
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!
Re: Tech Requirements
Posted: 19 May 2012, 18:58
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.