Need help expanding mex placement to more than one mex

Need help expanding mex placement to more than one mex

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

Moderator: Moderators

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

Need help expanding mex placement to more than one mex

Post by Forboding Angel »

Google_Frog wrote: Gadgets

mex_spot_finder

Broadly this does three things:
  • Determines the metal spot layout of the map
  • Puts this layout in GG
  • Is able to send this layout to widget land.
To determines the metal spot layout it tries these things in order and stops when one of them works.
  • Include a legal config from "LuaRules/Configs/MetalSpots/" .. (Game.mapName or "") .. ".lua"
  • Include a legal config from "mapconfig/map_metal_layout.lua"
  • Generate a metal spot layout from the metal map image.
This gadget just determines and broadcasts a layout.

If it receives a synced lua message "RequestMetalSpots" it has a SyncAction wrap to LuaUI which sends the metalspots table to a widget.


mex_placement

This gadget limits the placement of the metal extractor unit to the spots in GG.metalSpots. It does AllowCommand to cancel construction commands to illegal spots. It SetUnitRulesParams mexes detected in UnitCreated with the value of the spot they were built on, this will be their income.

This is a gadget which implements game specific behaviour and without it mex_spot_finder would do absolutely nothing to the game.

unit_mex_overdrive

This gadget does most of the economy system and much of it isn't relevant here. In short it GetUnitRulesParams mexes for their income, does things and eventually adds some metal to the storage of each teamID.

Widgets

wg_mexspot_fetcher

A small widget which simply asks mex_placement for the metal spot layout. Upon receiving this it puts the layout in WG and removes itself.

cmd_mex_placement

This is the entire mex placement UI. It draws the mex spots on the ground, snaps attempts to place mexes to legal mex spots and implements area mex.

****************
The snapping is currently only usable for one unit. That sucks, because I have a ground mex and an underwater mex.

http://evolutionrts.googlecode.com/svn/ ... cement.lua

http://evolutionrts.googlecode.com/svn/ ... cement.lua

It appears that zk hasn't really considered the fact that at some point they may have more than one extractor. Either that or adding in more unitdefs is simple as pie and I just don't know how. << More likely.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Need help expanding mex placement to more than one mex

Post by Silentwings »

The version in BA handles all mexes, try that. http://imolarpg.dyndns.org/trac/balates ... x_snap.lua.

It has different functionality to the zk one, but I guess the code you want is something like this bit:

[quote]local isMex = {}
for uDefID, uDef in pairs(UnitDefs) do
if uDef.extractsMetal > 0 then
isMex[uDefID] = true
end
end [/quote]
Google_Frog
Moderator
Posts: 2464
Joined: 12 Oct 2007, 09:24

Re: Need help expanding mex placement to more than one mex

Post by Google_Frog »

You'll only have to change a few lines in mex_placement.lua. mexDefID should become a table such that mexDefID[unitDefID] is true iff unitDefID is something that you want to treat as a mex.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Need help expanding mex placement to more than one mex

Post by Forboding Angel »

Actually it took a lot more than that, but smoth sorted it out for me.

https://code.google.com/p/evolutionrts/ ... cement.lua

https://code.google.com/p/evolutionrts/ ... cement.lua

Good thing too, because it was so over my head I never would have gotten it sorted.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Need help expanding mex placement to more than one mex

Post by knorke »

https://code.google.com/p/evolutionrts/ ... cement.lua
:arrow: line 397

Code: Select all

 if unitID and mexDefIDs[unitID] and spGetUnitAllyTeam(unitID) == myAlly then
mexDefIDs is a table defined like

Code: Select all

local mexUnitDef = UnitDefNames["emetalextractor"]
local referenceLandMexId = mexUnitDef.id
local referenceUnderWaterMexId = UnitDefNames["euwmetalextractor"].id

local mexDefIDs = {
  referenceLandMexId] = referenceLandMexId,
  [referenceUnderWaterMexId] = referenceUnderWaterMexId,
 }
so it is about UnitDefIDs. But then you index it with a unitID
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Need help expanding mex placement to more than one mex

Post by Forboding Angel »

Lets just say that from what I understand, this widget was coded... eh, not well.

Nor was it ever designed to be more extensible. The problem with making statements like that though is that without intending to, you end up accidentally dumping on other developers.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Need help expanding mex placement to more than one mex

Post by smoth »

knorke wrote:https://code.google.com/p/evolutionrts/ ... cement.lua
:arrow: line 397

Code: Select all

 if unitID and mexDefIDs[unitID] and spGetUnitAllyTeam(unitID) == myAlly then
mexDefIDs is a table defined like

Code: Select all

local mexUnitDef = UnitDefNames["emetalextractor"]
local referenceLandMexId = mexUnitDef.id
local referenceUnderWaterMexId = UnitDefNames["euwmetalextractor"].id

local mexDefIDs = {
  referenceLandMexId] = referenceLandMexId,
  [referenceUnderWaterMexId] = referenceUnderWaterMexId,
 }
so it is about UnitDefIDs. But then you index it with a unitID
Forb, this is why you I told you if you post it to say very clearly that I just threw a kludge in and left the code largely as it was.

Knorke did I use a unitid or unitdefid?
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Need help expanding mex placement to more than one mex

Post by knorke »

Knorke did I use a unitid or unitdefid?
You compared unitid vs unitdefid when you should have been comparing unitdefid vs unitdefid.
You changed

Code: Select all

local unitDefID = Spring.GetUnitDefID(unitID)
if unitDefID and mexDefID == unitDefID and spGetUnitAllyTeam(unitID) == myAlly then
into

Code: Select all

----why would you even?!?
--local unitDefID = Spring.GetUnitDefID(unitID)
if unitID and mexDefIDs[unitID] and spGetUnitAllyTeam(unitID) == myAlly 
unitdefID = what type of unit (like flash, corecommander, mex, lasertower)
unitID = that unique unit
mexDefIDs[unitID] = makes no sense
The purpose of the line that you commentated out was to get the unittype of a certain unit. The unittype was then compared with table to see if it is a mex unittype.

make like

Code: Select all

local unitDefID = Spring.GetUnitDefID(unitID)
if unitDefID and mexDefIDs[unitDefID] and spGetUnitAllyTeam(unitID) == myAlly
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Need help expanding mex placement to more than one mex

Post by smoth »

Dunno, like I said, wasn't really paying attention, just got the shit working. You could just update the section right quick for forb and be done.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Need help expanding mex placement to more than one mex

Post by knorke »

this kills the lua!
too lazy for svn commit etc
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Need help expanding mex placement to more than one mex

Post by Forboding Angel »

Look, all squabbles aside, it's working, and it's working well. For that, I thank everyone, especially smoth because he's the one that spent tons of time looking into it for me when he was on a time crunch in the first place.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Need help expanding mex placement to more than one mex

Post by smoth »

knorke wrote:this kills the lua!
too lazy for svn commit etc
I am not sure if you have a bone to pick with me and this is some passive aggressive bullshit

Or

you are just trolling and seeing how much you can try and manipulate me to command my behaviors.

Either way, the script works for forb, he tested it made sure the functionality he wanted is present. If you can prove that the script is in fact broken. Detail how and submit a fix to forb, otherwise get off my dick.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Need help expanding mex placement to more than one mex

Post by knorke »

If you can prove that the script is in fact broken. Detail how and submit a fix to forb, otherwise get off my dick.
see previous post where i already wrote what is wrong and how to fix it.
as said i cba/too lazy to find login details (if i have acess to svn?) just for commiting 1 line.
Post Reply

Return to “Lua Scripts”