Page 1 of 1

metal and energy interceptor

Posted: 24 Jun 2011, 22:35
by sunspot
I'm not sure if this is easly done in the current master code. But can an interceptor (callin ?) be created before metal or energy gets added to the pools ?

example: I don't want , once an incomplete build times out to have it's resources refunded. Then I could do somehting like this

Code: Select all

gadget:unitdestroyed(unitid,....)
  reason = Spring.getReasonOfDestruction(unitId)
  if("BUILDTIMEOUT".equals(reason)) then
    Spring.setReturnMetal(0.0)
    Spring.setReturnEnergy(0.0)
  end 
end
I went a bit overboard maybe with the getREasonOfDestruction method but still something in this line would be great if possible

Re: metal and energy interceptor

Posted: 24 Jun 2011, 23:15
by smoth
Why even used the engine energy and metal? You could lua your own resources

Re: metal and energy interceptor

Posted: 25 Jun 2011, 03:13
by knorke
once an incomplete build times out
did you try something like

Code: Select all

gadget:UnitDestroyed(...)
  health, bla...bla, buildProgress = Spring.GetUnitHealth (unitID)
  if (attackerID==nil and buildProgress < 1) then
    --unit construction was canceld
end

Re: metal and energy interceptor

Posted: 25 Jun 2011, 05:42
by Google_Frog
For this specific application you could instead remove engine build decay and lua construction destruction yourself.

Code: Select all

construction = {
    constructionDecay      = false; -- defaults to true
},
In modrules.lua. Then add some infrequent check on units under construction to check if they have had no build progress since the last check and destroy them.

Re: metal and energy interceptor

Posted: 25 Jun 2011, 09:07
by sunspot
smoth wrote:Why even used the engine energy and metal? You could lua your own resources
Thats something to think about for my next iteration of coding. But if I would do it this way, I believe I would write a generic script that could work on any game then a specific one. Letting people use their own resources seems something you could write in a generic way ... I hope
knorke wrote:
once an incomplete build times out
did you try something like

Code: Select all

gadget:UnitDestroyed(...)
  health, bla...bla, buildProgress = Spring.GetUnitHealth (unitID)
  if (attackerID==nil and buildProgress < 1) then
    --unit construction was canceld
end
This seems that it will work to figure out that the unit got destroyed by timeout, thats great but it won't solve the fact that the resources would just flow back in the metal and/or energy bar
Google_Frog wrote:For this specific application you could instead remove engine build decay and lua construction destruction yourself.

Code: Select all

construction = {
    constructionDecay      = false; -- defaults to true
},
In modrules.lua. Then add some infrequent check on units under construction to check if they have had no build progress since the last check and destroy them.
This is a nice workaround for the problem. I believe I will use this. I'll just never destroy it if the unit is unfinished .... to bad you should have finished it, resources are gone ! :) Although this solves my problem now. It would still be great if this problem could be solved by calling some kind of method that overrides the engines default behaviour :)

Re: metal and energy interceptor

Posted: 25 Jun 2011, 18:28
by knorke
This seems that it will work to figure out that the unit got destroyed by timeout,
Also if you cancel a unit from a factory (by rightclick the buildicon again) actually I thought thats what you meant.
For nano timeout use Google_Frog's idea.
it won't solve the fact that the resources would just flow back in the metal and/or energy bar
You could then do something like

Code: Select all

m = MetalCostOfUnity (unitID)
m = m * buildprogress
TakeMetalFromTeam (teamID, m)
Though there might be ways to cheat around it. (ie the share slider in resource bar, would have to disable that) Hm, there might also be problems with in which frames resources are used/spent.

Maybe it is possible to intercept the "cancel unit" order from the factory and destroy the unit in progress before the engine does it?
It would still be great if this problem could be solved by calling some kind of method that overrides the engines default behaviour :)
There were some threads about that before, I think the plan for the engine resource system is to make it more flexible in every way, ie allow more then 2 resources. Don't know if somebody is working on it.