hard-coded constants, ufo2000.ini parameters and LUA

13 views
Skip to first unread message

Fomka

unread,
Aug 14, 2010, 3:53:10 AM8/14/10
to ufo2000
Hello all,

what if we take values for hard-coded constants from ufo2000.ini file
or some LUA script?
(That questions appeared when I work on fix for issue 526 where I
asked them. However, with this mailing list have been appeared, I copy
the questions from the bugtracker here.)
Proper realization will add more flexibility to the game.

Some examples are below

inventory.cpp
Inventory::draw()
textprintf(temp, g_small_font, 128, 140, COLOR_GREEN, "%s",
sel_item->name().c_str());
if (sel_item->is_grenade()) {
if (sel_item->delay_time()) {
textout(temp, g_small_font, _("DELAY"), 272, 64,
COLOR_LT_OLIVE);
textout(temp, g_small_font, _("TIME:"), 272, 72,
COLOR_LT_OLIVE);
textout(temp, g_small_font, _("LEFT="), 272, 80,
COLOR_LT_OLIVE);
textprintf(temp, g_small_font, 299, 80,
COLOR_ORANGE, "%d", sel_item->delay_time() - 1);
rect(temp, 272, 88, 303, 135, COLOR_GRAY08); //
clip
PCK::showpck(temp, sel_item->obdata_pInv(), 272, 88 +
8);
}
}


soldier.cpp
Soldier::initialize()
ud.Morale = 100;

soldier.cpp
Soldier::process_MANDATA()
if (md.TimeUnits < 50) md.TimeUnits = 50;
if (md.TimeUnits > 80) md.TimeUnits = 80;
if (md.Health < 50) md.Health = 50;
...
if (md.Reactions > 80) md.Reactions = 80;

Siarhei Siamashka

unread,
Jan 23, 2011, 6:16:45 PM1/23/11
to ufo...@googlegroups.com, Fomka
On Saturday 14 August 2010 10:53:10 Fomka wrote:
> Hello all,
>
> what if we take values for hard-coded constants from ufo2000.ini file
> or some LUA script?

It surely makes sense. Deciding the usefulness of such changes on case by
case basis.

> (That questions appeared when I work on fix for issue 526 where I
> asked them. However, with this mailing list have been appeared, I copy
> the questions from the bugtracker here.)
> Proper realization will add more flexibility to the game.
>
> Some examples are below
>
> inventory.cpp
> Inventory::draw()
> textprintf(temp, g_small_font, 128, 140, COLOR_GREEN, "%s",
> sel_item->name().c_str());
> if (sel_item->is_grenade()) {
> if (sel_item->delay_time()) {
> textout(temp, g_small_font, _("DELAY"), 272, 64,
> COLOR_LT_OLIVE);
> textout(temp, g_small_font, _("TIME:"), 272, 72,
> COLOR_LT_OLIVE);
> textout(temp, g_small_font, _("LEFT="), 272, 80,
> COLOR_LT_OLIVE);
> textprintf(temp, g_small_font, 299, 80,
> COLOR_ORANGE, "%d", sel_item->delay_time() - 1);
> rect(temp, 272, 88, 303, 135, COLOR_GRAY08); //
> clip
> PCK::showpck(temp, sel_item->obdata_pInv(), 272, 88 +
> 8);
> }
> }

Could you elaborate on this? Are you proposing to tweak colors? Or the
placement of text labels? Or something else?

> soldier.cpp
> Soldier::initialize()
> ud.Morale = 100;
>
> soldier.cpp
> Soldier::process_MANDATA()
> if (md.TimeUnits < 50) md.TimeUnits = 50;
> if (md.TimeUnits > 80) md.TimeUnits = 80;
> if (md.Health < 50) md.Health = 50;
> ...
> if (md.Reactions > 80) md.Reactions = 80;

There is a bug (and a bunch of related bugs) about modding units and
their stats:
http://ufo2000.net/mantisbt/view.php?id=387

Technically, it's not very different from modding weapons or maps. It was just
not implemented yet.

--
Best regards,
Siarhei Siamashka

Fomka

unread,
Jan 31, 2011, 2:10:12 PM1/31/11
to ufo2000
>> inventory.cpp
>> Inventory::draw()
>> textprintf(temp, g_small_font, 128, 140, COLOR_GREEN, "%s",
>> sel_item->name().c_str());
>> if (sel_item->is_grenade()) {
>> if (sel_item->delay_time()) {
>> textout(temp, g_small_font, _("DELAY"), 272, 64,
>> COLOR_LT_OLIVE);
>> textout(temp, g_small_font, _("TIME:"), 272, 72,
>> COLOR_LT_OLIVE);
>> textout(temp, g_small_font, _("LEFT="), 272, 80,
>> COLOR_LT_OLIVE);
>> textprintf(temp, g_small_font, 299, 80,
>> COLOR_ORANGE, "%d", sel_item->delay_time() - 1);
>> rect(temp, 272, 88, 303, 135, COLOR_GRAY08); //
>> clip
>> PCK::showpck(temp, sel_item->obdata_pInv(), 272, 88 +
>> 8);
>> }
>> }

> Could you elaborate on this? Are you proposing to tweak colors? Or the
> placement of text labels? Or something else?

I do not propose to tweak the colors. Firstly, I propose to change all
number constants into named constants, like "272" into
"GRENADE_INFO_LEFT_EDGE_X". Then I propose to have names of named
constants appear in INI or LUA file and to have that "constants"
changeable on game load by editing the file. So, the file could have a
row like that — "GRENADE_INFO_LEFT_EDGE_X = 272".

> There is a bug (and a bunch of related bugs) about modding units and
> their stats:
> http://ufo2000.net/mantisbt/view.php?id=387
So, I think solving that bugs is a good place to start implementing
that externialization of constants.

--
Best regards,
Fomka

Siarhei Siamashka

unread,
Feb 1, 2011, 8:52:22 AM2/1/11
to ufo...@googlegroups.com

I see. Still it may be not the best idea because we are still going to have
the general layout hardcoded in C++, with only labels placement tweakable. We
will get some extra clutter to the code for getting these constants from .lua
or .ini to C++, but still lack complete configurability. This feels somehow
similar to 'soundmap.xml' which I think was not the very best design. Another
headache would come from ufo2000 versions upgrade (we will have to maintain
compatibility with all these externally configurable variables and provide
a sane upgrade path for the users who may tweak them).

If you want to be able to override the whole look of the item description area
from lua scripts, it may be interesting to move the whole drawing code to lua,
adding bindings for the needed functions (somewhat similar to how 'chameleon'
unit animation sequence is fully defined in lua). Though it brings some
challenges for internationalization, because text labels such as "TIME:",
"LEFT=" and the others will need to be translatable. And internationalization
does not work well with lua yet (for example, translation for the names of the
weapons is missing now).

Another thing to consider is support for different screen resolutions. If you
specify some coordinates in configuration files, they may not work equally well
for different resolutions.

Reply all
Reply to author
Forward
0 new messages