Tech Requirements

Tech Requirements

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

Moderator: Moderators

User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Tech Requirements

Post by zwzsg »

Here are five gadgets to handle tech levels, ranging from simplest to most complicated.

Choose one, download, stick into the \LuaRules\Gadgets\ of your mod, and edit the lines at the top to suit your mod.
  • 1) Automatic version: You edit the two conditions and the number at the top, and then it automatically find the unit matching them and manage the prerequisite relationship. The provided makes it mandatory to have built 3 radars before getting access to defense turret. Lower down that thread is a similar one locking out factories until three mexxes are built. The beauty of it is that you don't have to list out all the name or ID of all defense, mexx or factories you want the gadget to be applied to, which makes it indepent from the mod. For instance, to lock out ressurectors until you have constructors, change the top of it to:

    Code: Select all

    local n = 2 -- Including the commander
    
    local function isUnlocker(ud)
    	return UnitDefs[ud].isBuilder
    end
    
    local function isLocked(ud)
    	return UnitDefs[ud].canResurrect
    end
    
    function gadget:GetInfo()
    	return {
    		name = "Rez requires "..n.." cons",
    		desc = "Lock resurrector from build menu until you have "..n.." constructors",
  • 2) Simple Tech: One single "research lab", unlock a batch of units. It's a one shot upgrade, that you keep even after the "research lab" is destroyed. Make sure to edit the top of it to make it match your own unitnames.
  • 3) Single Tech, with count: Many unit act as "research lab", but they all unlock the same tech, the same batch of units. As soon as N are completed, and as long as you have them. As an exemple, I lock out all heavy laser defense until you have 5 light laser tower, but of course you should edit the unitname at the top of the gadget to suit your own unitset. Comes with automatic tooltip edition of the locked out unit. It act opposite of the the previous reguarding giving units to another team.
  • 4) Intermediate version: A whole range of tech level, from 0 to as high as you want. You can have different units enabling the same tech level. When a tech level is reached, every unit of that level and of below levels are unlocked. It's the act of building and completing the specified structures (or mobile units, if you fancy) that grants the tech level: There's no research button, you just build the research lab the way you'd build any other building.

    The tooltips of lockeds and unlockers are edited by the gadget, but I should have chosen another name than "tech level", for Spring already calculate its own "tech level" and show it in tooltip, and it is confusing to see two different kinf of "tech level" in tooltips.

    You can tie not only units builbuttons, but also any commands, to a tech level. Like, D-Gun locked out until you build a tech 3 research center. Though there's likely a bug with enqueued orders staying after you lose the tech level.

    Losing research lab of course make you lose the associated tech level, unless you have other labs. When you lose a tech, units already under construction can be finished, but enqueued units won't get built.

    Skipping tech level is possible, if you build a tech 10 lab right away you'll jump straight from tech 0 to tech 10. And having tech 10 automatically enable all the lower tech 1,2,3,4,5,6,7,8,9.

    It's limited to a mono-dimensional ladder, cannot do branching trees.
  • 5) Advanced version: The tech are not labelled by a simple number, but can bear any name. It is no more one dimensionnal, you can have all the branching out you like, even self-sustaining tech or tech pathes looping back on themselves. The gadget does not need to be changed to suit a mod. The technology name, the units that grant or require a tech, are defined in FBI. More precisely, by a RequireTech=..; and a ProvideTech=..; tag in the [CustomParams] section of [UnitInfo] in a FBI. A single unit can provide multiple tech (comma separated), or require multiple tech (comma separated). Advanced user can use lua hook to slave any command to a tech from a different gadget. Though it has the same bug as previous gadget with already queued commands not deleted when tech is lost. And as for the two others gadgets, read the comment at top of the .lua file for details.
  • 6) Ultimate version: Like multi tech, but with the addition of count and range. So, as many named "tech" as you want. Each "tech" has a level. Building more "research lab" increase that level. A given "research lab" unit can increase several "tech" at once, and each by a different amount. "research lab" optionnaly have a limited area of effect. Negative providetech can be used to implement shared unitlimits. All doable via custom FBI tags, if you want ease of use. Or can also be done by calling hooks from other gadgets, if you prefer a more dynamic approach. Some more info about it some posts below.


Yeah, I know many other mods have research already, and some done more prettily. So there's nothing new or grounbreaking here. But I was asked to code some simple research system, then got carried away and felt a sudden urge to write up three research gadgets showing the progression from a quick one up to a full fledged one. But since I don't feel like building three whole mods just to showcase them, I decided to just post here. Hopefully, one or two modders looking for a tech system will find them useful. While you could use every five of those gadget in this mod (but not 5 and 6 together), there will be conflict if two of them try to handle a lock on the same unit. For instance, (1) and (3) don't play well together because (1) unlock the heavy laser tower despite (3) wanting them still locked. Anyway, (6) can do everything the others do, and more.
Attachments
defenses_require_radars.lua
defenses_require_radars.lua
- Mod agnostic
- Only one technogy managed
- Every unit meeting condition Y is locked
- Every unit meeting condition X is an unlocker
- Needs N number of them to unlock the tech
- Once gained, the tech cannot be lost even when unlockers are lost
- No changes to tooltip. Have to guess how to unlock the greyed buttons.
(2 KiB) Downloaded 190 times
Simple_Tech.lua
Simple_Tech.lua
- Configured in the .lua file
- Only one technogy managed
- Several units or commands locked
- Only one unlocking unit
- A single instance of it unlock the tech
- Once gained, the tech cannot be lost even when unlocker is lost.
- Factory/builder can keep on building the new tech after being given another team.
- Giving an unlocker doesn't unlock tech to the team it was given.
- Tooltip of locked automatically edited to display the list of unlockers. Tooltip of unlocker unchanged.
(2.37 KiB) Downloaded 182 times
Single_Tech_Counted.lua
Single_Tech_Counted.lua
- Configured in the .lua file
- In the exemple, I made 5 armllt or corllt required for armhlt, corhlt, corvipe, ....
- Only one technogy managed
- Several units or commands locked
- Several unlocking units, all unlocking the same tech
- Needs N unlockers to unlock the tech
- Losing them relock the tech
- Handle giving unlockers or lockees to other team.
- Tooltip of locked automatically edited to display the list of unlockers. Tooltip of unlocker unchanged.
- Display a message to the team when the tech is gained or lost.
(3.92 KiB) Downloaded 158 times
Last edited by zwzsg on 06 Apr 2010, 22:57, edited 14 times in total.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: Tech Ladder

Post by AF »

You've been talking to Senna =p
LordMuffe
Posts: 286
Joined: 13 Mar 2005, 15:39

Re: Tech Ladder

Post by LordMuffe »

is it possible to unlock a tech level not by a single unit, but n units of the same type?

like you would have to build three metal extractors to unlock the first lab?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

wow O_O, nice work z!
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Tech Requirements

Post by zwzsg »

Attachments
Tech_Ladder.lua
Tech_Ladder.lua
- Configured in the .lua file
- A whole tech ladder managed, from 0 to as high as you want. So more than one tech level, but it's still one dimensionnal: There is no branching: It's a ladder, not a tree.
- Several locked units or commands for each tech level
- Several unlocking units for each tech level
- Getting a tech level automatically unlock all lower levels
- Losing unlockers relock the tech
- Handle giving unlockers or lockee to other team.
- Automatic tooltip edition of lockeds and unlockers.
(7.89 KiB) Downloaded 154 times
Multi_Tech.lua
Multi_Tech.lua
- Configured in FBI of units, no change needed to the .lua
- Provides hooks to other .lua, for advanced usage.
- Manage any number of technology, each refered to by its own name.
- More than a tech tree, it's a tech bush: handles every topology of tech path: branching, looping back, etc...
- Losing unlockers relock the tech
- Handle giving unlockers or lockee to other team.
- Automatic tooltip edition.
(12.48 KiB) Downloaded 181 times
Last edited by zwzsg on 16 Oct 2009, 00:09, edited 1 time in total.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

Request for the tech ladder...

Could you make it so that there is a range limiter for the unit in question? That is to say that tech is unlocked for units inside the range of the unlocker?

Edit: addendum to former request...

Can it be made that said range would affect allies tech as well? If so, that would be pretty rad! ;p
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Tech Requirements

Post by zwzsg »

LordMuffe wrote:have to build three metal extractors to unlock the first lab
A crude way would use:

Code: Select all

	if #Spring.GetTeamUnitsByDefs(team,{UnitDefNames.armmex.id,UnitDefNames.cormex.id})<3 then
		-- Lock
	else
		-- Unlock
	end

An elegant way is attached here:
Attachments
factories_require_mexxes.lua
Mod agnostic gadget locking out factories until 3 mexes are built.
(1.95 KiB) Downloaded 160 times
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

Comment about tech ladder. After reading the file/code, I have to say that the power of this thing is 100% genius. Very nicely done!
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Tech Requirements

Post by zwzsg »

I like factories_require_mexxes.lua better. It's so small yet so smart! Carrying all those unitnames in Tech_Ladder.lua feels clunky, and is a maintenance hell, compared to the beauty of using the .isMetalExtractor and .isFactory properties. But if you plan on using tech requirement alot in your mod, go with Multi_Tech.lua as it's the most powerful and versatile (ok, it lacks counting but I think I can add that), and remains easy to maintain since the tech tree description is moved to the FBIs of units themselves. Multi_Tech.lua can do the same as Tech_Ladder.lua, just add RequireTech=T1; to all T1 units, RequireTech=T2; to all T2 units, etc... and ProvideTech=T1,T2,T3; to T3 research centers.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

Can my range request things be added to the multi deal?
LordMuffe
Posts: 286
Joined: 13 Mar 2005, 15:39

Re: Tech Requirements

Post by LordMuffe »

thank you very much zwzsg :)

this is of great use for me
User avatar
PTSnoop
Posts: 97
Joined: 09 Sep 2009, 19:05

Re: Tech Requirements

Post by PTSnoop »

Wow, these are really useful! Thank you very much!
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Tech Requirements

Post by zwzsg »

Forboding Angel wrote:Could you make it so that there is a range limiter for the unit in question? That is to say that tech is unlocked for units inside the range of the unlocker?
Forboding Angel wrote:Can my range request things be added to the multi deal?
Okay, done.
Forboding Angel wrote:Can it be made that said range would affect allies tech as well? If so, that would be pretty rad! ;p
I don't really feel like coding that. Bah, it wouldn't change things much anyway.



I made an uber-version, starting from 5) Multi_Tech.lua, and adding both count and range. The (FBI) syntax is as follow:

Code: Select all

[UNITINFO]
	{
	Name=Depollution Facility;
	Unitname=deppool;
	Description=Process waste into energy;
	[CustomParams]
	{
		// You need at least one unit providing "advtech",
		// and two units providing "chemical"
		// (or only one if it provides 2 or more)
		// to unlock the build button to Depollution Facility
		RequireTech=AdvTech, 2 Chemical;

		// Once completed, the Depollution Facility will
		// augment the local level of "powergen" by 20
		// and decrease the local level of "pollution" by 2,
		// enabling or disabling the build buttons, or other commands,
		// of nearby units requiring either accordingly
		ProvideTech=20 PowerGen,-Pollution;
		ProvideTechRange=240;
	}
A limitation of the current implementation is that range doesn't handle moving units. Neither the unit providing the tech, nor the unit which can build the unit requiring the tech must be mobile. Or else the buttons won't be updated when unit comes into or move into range (though tech-check is still performed when order is issued or build initiated.). Maybe I'll add something code tracking mobile units, but it feels like an uncessary effort for now.

I plan to make negative amount in ProvideTech taken into account even when provider is under construction, and positive ones only after it's completed, but then I realised I'd risk introducing more bugs in the code and I already didn't test enough, so I'll leave that for next version.

You'll notice there is a ProvideTechRange tag, but no RequireTechRange tag. That's because I was not sure how to handle the case where a tech is provided in range by some units, required in range by other units, and provided with no range by thirds. Also, all the techs provided by the same unit use the same range. I hope you can live with those limitations for now. :)



Edit: Now, it handle unlocking buttons on moving unit (but still not mobile tech provider), and now, negative ProvideTech are taken into account as soon as unit spawn even when under construction.

Though having build button that lock and unlock on mobile unit when they approach or move away from a ranged tech provider feels kinda stupid, since the position the cons is when build order is issued often as nothing to do with position where to build. For instance, the cons might be away from a tech pylon, and thus have its buildbutton greyed, preventing you to tell it to build something inside a far away pylon radius. Or the cons might be in a pylon radius, and the interface let you queue an order to build something far away, and that order will be cancelled as soon as it starts because the unit creating would be forbidden so far from pylon. I guess that when a tech has a ranged provider, then I shouldn't grey out build buttons on mobile construction units, and leave only the AllowUnitCreation check. Also, showing the circles of all the provider of the tech required for the building the player is currently placing would be a plus, I guess. Lastly, the tooltip looks kinda silly now that there are negative req and tech you lose just by moving away, I shall redo it.

This gadget can do more than tech requirement: It can do shared heroes unitlimit, population cap, force some buildings to be near others, ... all via FBI tags. Though if you can prefer, you can do the same by calling the provided .lua hooks from another gadget.

.FBI exemple to have two mutually exclusive unique units:

Code: Select all

[UNITINFO]
	{
	Name=Mega Shark;
	Unitname=megashark;
	[CustomParams]
	{
		RequireTech=0 Magnus;
		ProvideTech=-Magnus;
	}
	...
}

Code: Select all

[UNITINFO]
	{
	Name=Giant Octopus;
	Unitname=giantoctopus;
	[CustomParams]
	{
		RequireTech=0 Magnus;
		ProvideTech=-Magnus;
	}
	...
}

.lua exemple to only allow static defenses in radar covered areas, in a mod agnostic way. Ok, this one not very readable :?

Code: Select all

-- In another .lua file, but one with a positive layer
if (gadgetHandler:IsSyncedCode()) then
	function gadget:Initialize()
		GG.TechAddDependency(
			function (ud) return UnitDefs[ud].radarRadius>0 and UnitDefs[ud].isBuilding end,
			function (ud) return UnitDefs[ud].speed==0 and #UnitDefs[ud].weapons>0 end,
			"radar coverage",
			function (ud) return UnitDefs[ud].radarRadius end)
	end
end



Edit: Now with better tooltip and better rings.
Image
In the world:
- The pulsating black and white circle are the range of the units providing the tech you need for what you are placing.
- The thin blue circle is the range of the currently selected units.
- There would be a larger and pulsating circle if the unit currently placed provided a ranged tech.
In the tooltip:
- Requirements that are met are green, requirement that are not met here but could be met elsewhere are yellow, those that can't be met without building some tech providers are red.
- Provided techs are light blue, save negative ones which are purple (sign omitted since it's implied by the word "consume").




Read the comments at the beginning of the .lua for more info.
Attachments
Better_Ranged_Counted_Multi_Tech.lua
Updated version of Better_Ranged_Counted_Multi_Tech.lua:
(so like the one below, but better)
- When a unit requiring tech meet or stop meeting the tech condition, then it calls the COB functions TechLost and TechGranted (if they exists).
- Fixes bug of the unsynced part of the gadget crashing when trying to display the range ring of an un-ranged provider of a synched range (it used to assume that because one provider was ranged, all were).
- Fixed a typo that would make AllowCommand not forbid commands like expected.
(31.15 KiB) Downloaded 196 times
Better_Ranged_Counted_Multi_Tech.lua
Better_Ranged_Counted_Multi_Tech.lua
- Configured in FBI of units, no change needed to the .lua
- Provides powerful hooks to other .lua, for advanced usage.
- Manage any number of technology, each refered to by its own name.
- More than a tech tree, it's a tech bush: handles every topology of tech path: branching, looping back, etc...
- Losing unlockers relock the tech
- Handle giving unlockers or lockee to other team.
- Automatic tooltip edition.
- Each tech has its own level, that can be increased by building more of the same "research center", or better "research center". And then the unlocked button can require different levels in different tech.
- The "research center" can provide tech mapwide, or optionnaly only in a limited range.
- Range indicated in blue when placing "research lab".
- Negative ProvideTech can be used to implement shared unitlimit (heroes, population cap, ...)
(29.96 KiB) Downloaded 157 times
Last edited by zwzsg on 06 Apr 2010, 22:56, edited 4 times in total.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

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

Re: Tech Requirements

Post by Forboding Angel »

Ok, I've hit a snag here.

[ 1989] Bad call to Check Tech: No position provided while TechName="tech1" is ranged

What does that mean?

the unit providing the tech has this:
customParams = {
ProvideTech = "tech1",
ProvideTechRange = "500",
},

the unit needing the tech has this:
customParams = {
RequireTech = "tech1",
},

What happens is... lemmie do this in pictures.
screen044.jpg
(432.62 KiB) Downloaded 15 times
Here you see the unit in the build list greyed out as it should be because it's out of range.
screen045.jpg
(458.31 KiB) Downloaded 12 times
but for some reason, the same buildpic slot is greyed out on the builder too... that unit on the builder's list has no requirements.
screen046.jpg
(471.09 KiB) Downloaded 10 times
Here I am placing a building that will provide tech1 which the tank in the factory requires.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

screen047.jpg
(424.97 KiB) Downloaded 12 times
now I have the ranged tech provider built, so I select the factory to find that the unit is still darkened, and when I click on it I get an error message.

So two bugs here:
First is the fact that once you select a unit that has a buildlist where one of the slots is darkened, every other unit you select with a buildlist will have that same position darkened regardless of the unit in question.

Second, is the error message once you have built the structure needed to provide the tech, the unit stays darkened and throws an error.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Tech Requirements

Post by zwzsg »

Forboding Angel wrote:Ok, I've hit a snag here.

[ 1989] Bad call to Check Tech: No position provided while TechName="tech1" is ranged

What does that mean?
When a technogy is ranged, my function that determine if something is allowed needs to know where that something is taking place. Well, my code was supposed to pass around the position or at least the unitid that does that something, but, the problem is in:

Code: Select all

function gadget:AllowUnitCreation(ud,builder,team,x,y,z)
		return CheckCmd(-ud,team,x,y,z)
	end
The value x,y,z are not provided when the unit is being built by a factory. I tested my code with mobile cons building structure, and not with factory building units, so I missed that. The fix is to replace the quoted code by

Code: Select all

	function gadget:AllowUnitCreation(ud,builder,team,x,y,z)
		if x and z then
			return CheckCmd(-ud,team,x,y,z)
		else
			return CheckCmd(-ud,team,builder)
		end
	end
I'll post an updated version after I have investigated the other bugs you mentionned. Thanks for reporting them by the way.

Edit: I cannot replicate the other bugs. :? Can I get your mod?
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

Yep can do: http://evolutionrts.info/random/evoluti ... rzwzsg.sd7

The only unit providing tech is the lightturret
The only unit limited is the lighttank

The lighttank can be built from the hover factory or the minifac

unit names needed to make things faster

eengineer4
ebasefactory
eminifac
elightturret

DO this

go ingame and /give 1 eengineer4
build a minifac
select the minifac and note that hte lighttank buildpic is darkened
then select the engineer and note that now the amphib factory is now also darkened
build a lightturret
select minifac and try to build a lighttank (note that the buildpic is still darkened)
the lighttank will build but everything with a build list will have that same position darkened.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Tech Requirements

Post by zwzsg »

Forboding Angel wrote:So two bugs here
First is the fact that once you select a unit that has a buildlist where one of the slots is darkened, every other unit you select with a buildlist will have that same position darkened regardless of the unit in question.
This is a bug with Red UI, not with my gadget.

I disabled Red Build / Order Menu in widget list and the real menu doesn't have this bug. I also checked which units I issue EditUnitCmdDesc on, only "Lightning Rod" and "Hovertank Factory" get their buttons modified. The buttons being wrongly greyed doesn't prevent you from using it, and if you turn off and on the widget Red Build / Order Menu it get ungreyed. And anyway everything but the ring drawing in my gadget is synced, and by design synced code couldn't even know a unit got selected. So see with Regret.
Second, is the error message once you have built the structure needed to provide the tech, the unit stays darkened and throws an error.
This was a bug in my gadget, now corrected.
Last edited by zwzsg on 23 Oct 2009, 02:13, edited 1 time in total.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Tech Requirements

Post by Forboding Angel »

Roger, thanks z :-)
Post Reply

Return to “Lua Scripts”