build costs 1.02 - updated 21 Sep

build costs 1.02 - updated 21 Sep

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

Moderator: Moderators

User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

build costs 1.02 - updated 21 Sep

Post by BigHead »

Overview
Economy in spring is a bit tricky. You can see how much metal and energy units cost but since spring isn't ordinary strategy this isn't enough. It's more important to know how it affects you income and expense per second. As result you have to build units by intuition. This widget aims to bring light into this area by providing you with (hopefully) all the information you might need.

Features:

Tooltip #1
Image
- shows time and metal&energy per second needed to build chosen unit/building
- also shows how much energy&metal you'll have left after the unit/building is built
- if you don't have enough energy/metal to finish the unit/building, it shows time until stall
- it considers unit's guarding selected constructor/factory e.g.: if your factory is guarded by nano tower it build's faster but also spends more m&e

Tooltip #2
Image
- shows how would time and metal&energy change if you order selected builder(s) to help construct pointed unit
- also shows energy&metal after the unit is finished or time until stall

Tooltip #3
Image
- if no unit is selected and you move the cursor over a constructed unit it shows:
- time until completition
- metal&energy expense
- % of your total expenses spent on this unit

Tooltip #4
Image
- build speed of selected builders/factory
- commanders build speed is always 100

What it can't do
- it doesn't support (and i am not sure it ever will) build queues

TODO
- resizing: the widget is sized for my 1280x800 laptop
i am aware of the fact that it might be too small at higher resolution or too big at smaller resolution
- though it's well optimized, the code is a bit messy and needs some clean-up

Change log:
version 1.02
- lot of bug fixing
- metal makers support - considers the impact of disabling MMs on the amount of energy (and metal) left.
If you don't use any metal controling widget/AI change metalMakersControled to false
- Time left information is now very precise. However the time shown assumes there's enough e&m to finnish the unit/building. Otherwise ??? is displayed next to the time.
- shows amount of m&e left even if inc>exp
- better spectators mode
- optimization and code clean-up

version 1.01
- fixed a typo that made the widget crash in certain situation (i am surprised noone complained)
- you can now adjust horizontal position of the widget - useful only for ppl who don't use default 3 column menu

version 1.00
- initial release

Download
http://spring.unknown-files.net/file/36 ... osts_1.02/
Last edited by BigHead on 21 Sep 2007, 14:44, edited 6 times in total.
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Post by BrainDamage »

first thing: good job & great idea :-)

just a small suggestion:

the bottom left box (tool tip ) is already showing infos like metal & energy cost, ecc, do you think your widgets could be integrated in such area, or would it would end up bloated?
Tim-the-maniac
Posts: 250
Joined: 22 Jul 2006, 19:58

Post by Tim-the-maniac »

Why does it mess around with unit guarding? It disables guarding something which cant guard back?

Also I have a 4 colunm build menu and when I hover over the forth colunm it shows the info where it shows the buildspeed usually. When I hover over the first 3 columns it works as in your screen shot

great widget tho :)
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

Post by BigHead »

Brain Damage: I agree, there should be an option for that. It would require me to remove the default tooltip and replace it with my own. However most people who use lua also (i think) use IceUI and it's own tooltip would replace my tooltip. So if comments show that people really want it I'll contact meltrax about it.
Btw early version of this widget showed info in the bottom area (where you want it) but when I tested it in battle I didn't use it. I simply didn't have the time to look at it. The way it works now you just can't miss the fact that (for example) you don't have enough energy to build that LLT, or that sumo takes 4mins to build if you don't assist your factory.

Tim-the-maniac: The fact that unit A can't guard unit B if unit B is already guarding unit A (A->B->A) is a simple fix that would otherwise require a lot of what i call "ugly" programming. Do you really do that (A->B->A)? I see no point in doing so. You can still let 2 cons repair each other. However if you can tell me why would you do that i'll fix it.

I know it only works well for default 3 column menu. I can't get any information about your menu in lua. In next version I'll add tweak mode setting where you set tooltip's position according to your menu width.
Edit: Done - new version is on UF
However I saw a picture of someone having the menu at the bottom of the screen. In that case it would still work as if you had left-sided menu. If there's anyone reading this using mentioned menu configuration please send it to me so I can fix it.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

tbh when my resolution goes up I want these sorts of tool tips to get smaller. I dont want to up my resolution to find everything looks identical.
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

Post by BigHead »

it's in my todo list already
Tim-the-maniac
Posts: 250
Joined: 22 Jul 2006, 19:58

Post by Tim-the-maniac »

I dont really mind it disabling 2 things guarding each other but it also does some wierd stuff like I cant guard units or defences with cons and normal units cant guard each other.
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Re: build costs 1.01

Post by BrainDamage »

BigHead wrote: - fixed a typo that made the widget crash in certain situation (i am surprised noone complained)
i was about to today :P

i noticed another problem:

when you use metalmakers widgets/AI you create a sort of "energy pool" made by metalmakers who are gonna be shut sown, thus the income-outcome changes dynamically with the "primary usage"

you could either start poking TheFatController (the improved metalmaker widget author) to create a sort of API to check how much energy is used by metal makers, ecc or either check manually the real income/outcome/metalmaker usage and correct the prevision accordingly

EDIT: the new version is unusable for me, every time i turn it on i do get the following error message
[string "gui_build_costs.lua"]:81: attempt to perform arithmetic on local 'y' (a nil value)
Removed widget: Build costs
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

Post by BigHead »

Tim-the-maniac: oops ... change line 393: return -> return true
i'm not going to release a new version becouse of that, frist i'll try to fix \/
Brain Damage: After I investigated the code I came to the conclusion that your error can't occur :) However there is one situation that shouldn't happen (widget:ViewResize called before widget:DrawScreen) which could cause it. In short try to put this line

Code: Select all

local commandsPanelHeight = 0
somewhere in the declarations (eg: above "width = 240")

I'll make it consider energy used by metal extractors as "possibly free" in next version. Thanks for suggestion.
Crampman
Posts: 117
Joined: 22 Dec 2005, 12:17

Post by Crampman »

I got the same error than Brain Damage, but it's fixed with your trick.

But now, I've another error :

Code: Select all

[string "LuaUI\Widgets\gui_build_costs.lua"]:196: attempt to perform arithmetic on local 'inc' (a nil value)
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Post by BrainDamage »

the declaration seems to have fixed my previous problem, i found another problem tho:
[string "gui_build_costs.lua"]:197: attempt to perform arithmetic on local 'inc' (a nil value)
this appears the first time i hover with my mouse on the build pics, but when i reactivate the widget after the crash, it works corrrectly :?

btw thanks for the help :)
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

Post by BigHead »

I don't get that error at all. There was a similar error in previous version but it happened when you hovered above a building under construction. It's so strange that you keep getting errors I don't ... aren't you using linux or something? (Note: this question wasn't meant to start a flame)
Anyway put this code above the trouble-making line:

Code: Select all

  
if not inc then
  Spring.Echo("ERROR", teamID, type)
  return
end
... and tell me if ERROR messages start poping in your console (the widget shouldn't crash anymore)
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Post by BrainDamage »

i'm running linux, yes

i took a quick glance at your code & did more exetensive tests:

all my previous tests with the version 1.01 were only offline, by launching directly spring using the script "commanders"; i tested again in a "real" battle and it worked fine

apparently the huge amounts of starting metal/energy you have in such mode seems to generate the error, i think you can reproduce yourself by launching spring directly & selecting the commanders mode

btw, i also added your checking function & in commanders it spammed my console with
ERROR, 1, metal
ERROR, 1, energy
wich partically confirmed my suspect about data size
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

Post by BigHead »

Your team is 0 not 1 that causes the error. For some reason commanders script causes Spring.GetMyTeamID() return wrong value first time it's called. If you reload it returns 0 correctly. This is commanders bug, not build costs. :)
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

Post by BigHead »

A new version is out!

I know this widget was quite buggy. It's my first widget and I rushed it's release. However there's a new version which has been tested a lot and shouldn't contain any bugs.

Modified version of the newest CustomFormations is included. CF didn't trigger the CommandNotify call-in which is used in build costs. This bugfix modification will be included in the new release of CF when it comes out.

1.01 -> 1.02
- lot of bug fixing
- metal makers support - considers the impact of disabling MMs on the amount of energy (and metal) left.
If you don't use any metal controling widget/AI change metalMakersControled to false
- Time left information is now very precise. However the time shown assumes there's enough e&m to finnish the unit/building. Otherwise ??? is displayed next to the time.
- shows amount of m&e left even if inc>exp
- better spectators mode
- optimization and code clean-up

Todo:
- Resizing

Download:
http://spring.unknown-files.net/file/36 ... osts_1.02/
Lefty
Posts: 27
Joined: 26 Jun 2007, 22:00

Re: build costs 1.02 - updated 21 Sep

Post by Lefty »

Hi, your widget always crashes with:

Code: Select all

Error in DrawScreen(): [string "/home/oggy/.spring/LuaUI/Widgets/gui_build_..."]:318: attempt to perform arithmetic on local 'currentChange' (a nil value)
Removed widget: Build costs 1.02
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: build costs 1.02 - updated 21 Sep

Post by KDR_11k »

For me it always crashes when a unit changes teams(in UnitGiven), attempt to index "builder", a nil value.
Lupus
Posts: 37
Joined: 18 Jan 2008, 22:23

Re: build costs 1.02 - updated 21 Sep

Post by Lupus »

I got this error every time I hover my mouse over buildings pics in my constructor (or in factory):

Code: Select all

Error in DrawScreen(): [string ".../LuaUI/Widgets/gui_build_..."]:218: attempt to perform arithmetic on local 'buidTime' (a nil value)
Removed widget: Build costs 1.02
Last edited by Lupus on 04 Feb 2008, 03:36, edited 2 times in total.
Lupus
Posts: 37
Joined: 18 Jan 2008, 22:23

Re: build costs 1.02 - updated 21 Sep

Post by Lupus »

I found the reason for this error:
it occurs every time you hover your mouse over an icon of building, which is binded to a key.

I mean, if you've bound a key to build a vehicle factory, then if you hover your mouse over a vehicle factory icon in commanders' or constructors' control panel, then the widget crashes with error mentioned in previous posts.

EDIT:

I've found a solution.

Open the source code of the widget (/LuaUI/Widgets/gui_build_costs.lua) and replace the code:

Code: Select all

function getBuildTime(tooltip)
    local start = string.find(tooltip, "Build time %d*") + 11
    return tonumber(string.sub(tooltip, start))
end
with:

Code: Select all

function getBuildTime(tooltip)
    local s, e = string.find(tooltip, "Build time %d*")
    return tonumber(string.sub(tooltip, s + 11, e))
end
I include fixed file.
Attachments
gui_build_costs.zip
fixed "buid cost 1.02"
(5.9 KiB) Downloaded 81 times
User avatar
BigHead
Posts: 145
Joined: 12 Jul 2007, 18:55

Re: build costs 1.02 - updated 21 Sep

Post by BigHead »

Feel free to upload it as build costs by bighead fixed by lupus.
Post Reply

Return to “Lua Scripts”