project-navigation
Personal tools

Author Topic: Smooth encumbrance system  (Read 17884 times)

Offline Norby

  • Rookie
  • ***
  • Posts: 43
    • View Profile
Smooth encumbrance system
« on: March 01, 2017, 12:49:09 pm »
In Ufoai 2.5 soliders suffered -12TU over 50% of the maximum weight of equipments and this is the same up to 100%. Imho not the best that a 40kg pack allow the same speed than 20.1kg.

The simplest solution would be a new highest level of encumbrance, for example -24TU over 80% weight. In this case the kg could be red in the inventory screen.

The encumbrance modifier of strength skill could be the same as now (0.4) to prevent faster improvement, or anything what developers like, I will accept the decision. :)

Update: I attached the solution of the smooth encumbrance system discussed below in a zip file to this post. I also uploaded a patch into the issue tracker.
« Last Edit: March 28, 2017, 11:45:28 am by Norby »

Offline Rodmar

  • Squad Leader
  • ****
  • Posts: 239
    • View Profile
Re: "Red" encumbrance level over 80% weight
« Reply #1 on: March 05, 2017, 02:11:13 pm »
If a new level of encumbrance was to be implemented, I'd rather be for a much higher penalty.

Given a new recruit with 24 TUs is reduced down to 12 TUs, with current system, I'd have a faster soldier with say 36 TUs reduced to about 12 TUs as well when 80% encumbered. That would mean a -24 TUs penalty. That would also mean that slow recruits would be unable to move before reaching 100% encumbrance.

Offline Norby

  • Rookie
  • ***
  • Posts: 43
    • View Profile
Re: "Red" encumbrance level over 80% weight
« Reply #2 on: March 05, 2017, 02:53:46 pm »
Right, -24TU sounds better, especially when 100% weight mean the man can not make any steps. If I calculate well a rookie with 15 speed (I never seen less) keep 3 TU only and a superman with 100 speed still get 23TU.

Offline Sandro

  • Squad Leader
  • ****
  • Posts: 240
  • Maintenance guy for UFO:AI 3D engine
    • View Profile
Re: "Red" encumbrance level over 80% weight
« Reply #3 on: March 06, 2017, 07:26:51 pm »
IMHO, the best version could be a smooth encumbrance increase instead of increasing in steps.

Offline Norby

  • Rookie
  • ***
  • Posts: 43
    • View Profile
Re: "Red" encumbrance level over 80% weight
« Reply #4 on: March 06, 2017, 08:49:06 pm »
A smooth solution mean more steps where each cause 1 TU change. If we keep the effect of 50% weight at +0TU and 20% at +12TU then each 2.5% change should result an 1TU change. This mean +20TU at 0% and -20TU at 100%.

Alternatively if a step happen at every 2% then 0% mean +25TU and 100% is -25TU. This is closer to Rodmar's notice.

My problem is anything over the +12TU bonus looks unfair when I use experienced soliders.

How about this:
- below 50% weight give +1TU after every -4%, up to +12TU in 0%-2%,
- 0 TU between 46.01%-50%,
- 50.01%-52% give -1TU, then -1TU for each +2%, down to -25TU in 98.01%-100%.

You can test this formula if you replace the similar line in ufoai/src/game/q_shared.h to this:
Code: [Select]
#define GET_ENCUMBRANCE_PENALTY(weight, max)    (1.0f - ((weight) > (max) * WEIGHT_FACTOR * WEIGHT_HEAVY ? 12.0f/MIN_TU+(((weight/(max*WEIGHT_FACTOR))-0.5f)/0.02f)/MIN_TU : 12.0f/MIN_TU-((0.5f-(weight/(max*WEIGHT_FACTOR)))/0.04f)/MIN_TU ))Now this is working in my machine. :)

The following change show TU next to the kg. Better than always using the popup on weight to know the bonus or penalty.
File: ufoai/src/client/cl_inventory_callbacks.cpp
Code: [Select]
Com_sprintf(label, sizeof(label), "%g/%i %s  %i %s (%+i)", invWeight / WEIGHT_FACTOR, maxWeight, _("Kg"), tus, _("TU"), tuPenalty);
The red color still could be added over 80% but just as a spice.
« Last Edit: March 07, 2017, 04:09:43 am by Norby »

Offline Norby

  • Rookie
  • ***
  • Posts: 43
    • View Profile
Re: Smooth encumbrance system
« Reply #5 on: March 07, 2017, 03:51:48 pm »
Here is the completion of the smooth encumbrance system. All changes are available in the zip file at the end of this post.
 
  I applied a maximum in ufoai/src/game/g_match.cpp to limit the skill bonus at the usual level:
Code: [Select]
const float penalty = std::min(0.4f, GET_ENCUMBRANCE_PENALTY(weight, chr->score.skills[ABILITY_POWER]));   
  This will limit the skill improvement multiplier at 2.5x. Without this the smooth formula in my previous post resulted 20x at 100%. :o
 
  Using this limit the ideal point of strength training is at -12TU. Over this only the mass increase is counted, exactly as in Ufoai 2.5. So 100% weight give only a bit more strength than 75%.

  To indicate this I suggest to change the kg to red when penalty is more than -12TU (at almost 75% weight).
  In ufoai/base/ufos/ui/inv_stat.ufo replace the line "if (penalty > 0) then" with these 3 lines:
Code: [Select]
if (penalty < -12) then
  sender:root():child("bt_load"):set_color(1, 0, 0, 1)
elseif (penalty > 0) then
  Then change these lines also (make room to TU next to kg):
Code: [Select]
  name = "bt_load",
class = "button",
pos = {65, 35},
contentalign = ufo.ALIGN_CR,
text = "_0/0 Kg  0 TU (+0)",
color = {0.56, 0.81, 0.76, 1},
flashcolor = {1, 0.5, 0.5, 1},
size = {306, 25},
  Also in ufoai/base/ufos/ui/equipment.ufo below confunc equip_actorload replace the line start with "if ( <3> > 0 )" to these:
Code: [Select]
if ( <3> < -12 ) { *node:parent.bt_load@color = "1 0 0 1" }
elif ( <3> > 0 ) { *node:parent.bt_load@color = "0 1 0 1" }
  Below "bt_load" need to change these:
Code: [Select]
pos "210 30"
flashcolor = {1, 0.5, 0.5, 1},
  Then change the similar lines in ufoai/src/client/battlescape/cl_hud.cpp to these:
Code: [Select]
Com_sprintf(label, sizeof(label), "%g/%i %s  %i %s (%+i)", invWeight / WEIGHT_FACTOR, maxWeight, _("Kg"), tus, _("TU"), tuPenalty);
        int weight_percent = (int)((invWeight/maxWeight)/10.0f);
        float skill_multiplier = std::min(2.5f, ((int)((1/penalty)*10))/10.0f);
Com_sprintf(tooltip, sizeof(tooltip), "%i%%  %.1fx", weight_percent, skill_multiplier);
UI_ExecuteConfunc("inv_actorload \"%s\" \"%s\" %i %i", label, tooltip, tuPenalty, count);
  Also change in ufoai/src/client/cl_inventory_callbacks.cpp to these:
Code: [Select]
Com_sprintf(label, sizeof(label), "%g/%i %s  %i %s (%+i)", invWeight / WEIGHT_FACTOR, maxWeight, _("Kg"), tus, _("TU"), tuPenalty);
        int weight_percent = (int)((invWeight/maxWeight)/10.0f);
        float skill_multiplier = std::min(2.5f, ((int)((1/penalty)*10))/10.0f);
Com_sprintf(tooltip, sizeof(tooltip), "%i%%  %.1fx", weight_percent, skill_multiplier);
UI_ExecuteConfunc("%s \"%s\" \"%s\" %i %i", Cmd_Argv(1), label, tooltip, tuPenalty, count);


I tested and I like the result. Please get the zip file below this post, test and comment here.

I do not know how to commit changes into github, if somebody tell me the preferred way and I will be allowed then I will send in.

 
Another thing that I cleared the ufoai/base/pics/ui/screen.png file, which is drawn over all ui items, causing "blur" in most screens. I disliked this so I asked my 3 sons separatedly, all said that the ui in 2.5 is more nice, mainly due to the blur in 2.6. This file should be drawn in the background _below_ others or if this is not possible then better if simply left out. Now the game looks better with the "renewed" sharp ui. :)
« Last Edit: March 07, 2017, 06:27:51 pm by Norby »

Offline geever

  • Project Coder
  • PHALANX Commander
  • ***
  • Posts: 2561
    • View Profile
Re: Smooth encumbrance system
« Reply #6 on: March 08, 2017, 07:36:58 am »
Hi,

We use GitHub as a mirror only yet. Patches can be uploaded to our Issue Tracker at: http://ufoai.org/bugs/ (First you need to create a Patch ticket, then you can add attachments)

Thx!
-geever

Offline Norby

  • Rookie
  • ***
  • Posts: 43
    • View Profile
Re: Smooth encumbrance system
« Reply #7 on: March 08, 2017, 12:53:33 pm »
you need to create a Patch ticket, then you can add attachments
Thank you, I uploaded a patch file what I created in this way:
Code: [Select]
git diff > Smooth_Encumbrance.patch
This command excavated my addition of some missing video modes what I added for my monitor. I guess you will forgive me if I do not make another issue ticket just for this so I left in this patch.

About the smooth system I like the possibility of optimizing equipment to the borders, like adding more grenades while it is possible without TU change. Now I have big freedom to select the border: worth to try getting a few extra TU or at least one more in the green area when equip soliders.

Moreover I like that the optimal point of body building is not at 100% weight but at 73%. Here the skill multiplier reach the maximal 2.5x value, as now shown in tooltip over kg. I was always in trouble to train the strength of my best soliders further: simply was not enough room and enough heavy items to reach 100% weigth over 60 strength. Now the optimal point (-12TU) is reachable up to 80 skill points.
« Last Edit: March 08, 2017, 12:55:08 pm by Norby »

Offline Norby

  • Rookie
  • ***
  • Posts: 43
    • View Profile
Re: Smooth encumbrance system
« Reply #8 on: March 08, 2017, 05:54:50 pm »
I improved the formula in red and yellow areas to balance the high speed bonus of experienced soliders.
Start from 50% as before but fall down to only 2TU in total regardless of the speed skill. The change in q_shared.h:
Code: [Select]
#define GET_TU( ab, md ) (MIN_TU * (md) + (ab) * 20 / MAX_SKILL * std::min( 1.0f, (md) * 1.45f ))
This returns the original values up to 50% weigth, over this the bonus of speed ability (ab) is reduced by the weight penalty (md), which leave only 2TU at 100%.

I updated the zip and patch files, please test it.
« Last Edit: March 09, 2017, 01:17:22 am by Norby »

Offline Norby

  • Rookie
  • ***
  • Posts: 43
    • View Profile
Re: Smooth encumbrance system
« Reply #9 on: March 09, 2017, 03:28:01 pm »
I made smoother color changes:
-Orange label color from -13TU up to the border of the optimal strength training.
-Red color now start from 73% weight, indicating which area should be avoided, where the encumbrance modifier is not increasing further.
-Green and Yellow colors got lighter and darker parts after 4 TU changes.

I also tried very smooth color changes after each TU but it was almost unnoticeable so now use less, more distinguishable colors.

See in the attached zip file or the updated patch.

Offline Norby

  • Rookie
  • ***
  • Posts: 43
    • View Profile
Re: Smooth encumbrance system
« Reply #10 on: March 17, 2017, 11:55:56 am »
I realized that high encumbrance should reduce movement much more than aiming, first aid or other actions.
So now I softed the TU formula: -1TU comes after each +4% weight only in the whole range up to 100% weight, but I added a feature which increasing the TU cost of movement over 50% weight. Colors are refined also:

- Green color is appear in 0-46% weight (bonus TU),
- Skyblue at +0TU (46-50% weight),
- Yellow from -1 TU to -4 TU (51-65%), movement need 3 TU for each step,
- Orange from -5 TU to -6 TU (66%-73%), a step need 4 TU,
- Dark Orange from -7 TU to -8 TU (74%-81%), a step is 5 TU,
- Red  from -9 TU  to -10 TU (82%-89% weight), a step is 6 TU,
- Dark Red at -11 TU (90%-93%), a step is 7 TU,
- Darker Red at -12 TU (94%-97%), a step is 8 TU,
- Darkest Red at -13 TU (98%-100%), moreover every step consume 9 TU.

A "Move" label after the kg in inventory screen show the number of squares what the solider can reach in a turn. This is calculated by dividing the max. TU with the movement cost of a step at the current weight and wounds, then rounded down.

The exact TU cost of a single move is displayed at the end of the tooltip.

This way looks more real, soliders now able to pull the trigger even at 100% weight. :)
A good side effect is a big reduction in the appearance of "Not enough TU" popups in the inventory screen.

Please test this system in the attached zip or in the updated patch.
« Last Edit: March 17, 2017, 12:58:06 pm by Norby »

Offline Norby

  • Rookie
  • ***
  • Posts: 43
    • View Profile
Re: Smooth encumbrance system
« Reply #11 on: March 23, 2017, 07:46:43 pm »
Changes in Smooth encumbrance system v1.3:
- Encumbrance modifier is more close to the original, reach the top at 69% weight (2.5x at -5TU).
- Size of skill labels is increased in inv_stat.ufo to do not cut long labels (highly proficient).
- If a solider drop some weight then moveTU change instantly.

Now if a solider is penalized due to encumbrance so a step need 3TU and in the middle of a turn there is not enough TU left to reach safety then possible to drop his weapon to fall below 50% weight and his movement will be instantly boosted to 2TU/move. This could be enough to run into a safe place.

Max. TU will increase in the next turn only as always, this is not changed.



Offline Norby

  • Rookie
  • ***
  • Posts: 43
    • View Profile
Re: Smooth encumbrance system
« Reply #12 on: March 25, 2017, 12:45:23 am »
In v1.4:
- The highest difficulty level need at least 3TU for each move, 4-10TU when encumbered.
- MaxTU increase/decrease instantly when some weight is raised/dropped.
- Mouse wheel up/down in inventory window change the focus to the previous/next solider during battle.
« Last Edit: March 28, 2017, 11:45:51 am by Norby »

Offline Sandro

  • Squad Leader
  • ****
  • Posts: 240
  • Maintenance guy for UFO:AI 3D engine
    • View Profile
Re: Smooth encumbrance system
« Reply #13 on: April 16, 2017, 12:49:51 am »
Skyblue is obviously way off the color ramp chosen. Is it meant to be an eye-catching indicator that your soldier just begins to slow down under the load?

Offline Norby

  • Rookie
  • ***
  • Posts: 43
    • View Profile
Re: Smooth encumbrance system
« Reply #14 on: April 16, 2017, 08:49:14 am »
It is the default color for +0TU in ufoai 2.6 during combat. In the base it was white, but white is also the hover color when the mouse is over the label so I unified to the light blue.
It mean the optimal load near 50% where no movement penalty.
« Last Edit: April 16, 2017, 08:52:30 am by Norby »