Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
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.
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:
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:
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
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.
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?
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
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.
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
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.
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
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).
Joined: 17 Nov 2005, 02:43 Location: Raegquitting Spring on 04/24/12
Code:
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.
Users browsing this forum: No registered users and 0 guests
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum