Skip to content

Commit

Permalink
Crafting: give exp points for crafting new item for the first time
Browse files Browse the repository at this point in the history
- Amount is based on maximum required skill (for sum requirements the average is used).
- Multiplied by configurable value and rounded up.
  • Loading branch information
phobos2077 committed May 12, 2024
1 parent de577a6 commit 82dc14d
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 4 deletions.
3 changes: 0 additions & 3 deletions docs/todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ for 0.9.*:
for "future":
- add early game Flamerthrower (Incinerator)
- Stimpak & Healing powder heal amt to depend upon First Aid skill
- Crafting: use items from party members inventory
- Crafting: read config from INI file and texts from game/craft.msg
- Crafting: add small XP rewards for crafting
- add tie-ins to barter "demand" feature, have some trader explain it in dialog (and maybe also boost your barter skill)
- replace "handmade grenade" sprite
- replace Throwing Axe sprite
Expand Down
4 changes: 4 additions & 0 deletions root/data/config/pbs_craft.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ categories=2
use_gvars=1
; Crafting shortcut: Ctrl+C
hotkey=29+46
; craft exp multiplier (base is maximum of all averages of required skills)
exp_skill_mult=2.0
; experience points granted are rounded up to this number (e.g. 1 becomes 5, 13 becomes 15, etc.)
exp_round_to=5



Expand Down
2 changes: 2 additions & 0 deletions root/data/text/english/game/pbs_craft.msg
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@
{403}{}{ unit(s)). }
{404}{}{ h. }
{405}{}{ m. passed.}

{420}{}{You gain %d experience points for creating a new item.}
2 changes: 2 additions & 0 deletions root/data/text/russian/game/pbs_craft.msg
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@
{403}{}{ �������(��)). }
{404}{}{ �. }
{405}{}{ �. ������.}

{420}{}{�� ��������� ���� ����� (+%d) �� �������� ������ ������ ��������.}
4 changes: 4 additions & 0 deletions scripts_src/_pbs_craft/craft_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "../sfall/sfall.h"
#include "../sfall/lib.arrays.h"
#include "../sfall/lib.math.h"
#include "../sfall/lib.strings.h"

variable
Expand Down Expand Up @@ -56,6 +57,7 @@ end
#define cfg_item_qty(itemData) (itemData / 0x10000)

#define cfg_parse_int_def(cfg, ini, name, def) cfg.name := atoi(ini.name) if ini.name else def
#define cfg_parse_def_clamp(parseFn, cfg, ini, name, def, min, max) cfg.name := math_clamp(parseFn(ini.name) if ini.name else def, min, max)

procedure load_crafting_config begin
variable
Expand All @@ -66,6 +68,8 @@ procedure load_crafting_config begin
cfg_parse_int_def(cfg, iniMain, use_party, 0);
cfg_parse_int_def(cfg, iniMain, categories, 0);
cfg_parse_int_def(cfg, iniMain, use_gvars, 0);
cfg_parse_def_clamp(atof, cfg, iniMain, exp_skill_mult, 0.0, 0.0, 10.0);
cfg_parse_def_clamp(atoi, cfg, iniMain, exp_round_to, 1, 1, 100);

craft_debug("crafting cfg main: " + debug_array_str(cfg));

Expand Down
14 changes: 14 additions & 0 deletions scripts_src/_pbs_craft/craft_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ pure procedure skill_names(variable skills) begin
return str;
end

procedure recipe_max_average_skill(variable recipe) begin
variable list, skill, skillAvg, numSkills, i,
maxAvg := 0;
if (len_array(recipe.skills) > 0) then foreach (list in (recipe.skills)) begin
numSkills := len_array(list) - 1;
if (numSkills >= 1) then begin
skillAvg := list[numSkills] / numSkills;
if (skillAvg > maxAvg) then
maxAvg = skillAvg;
end
end
return maxAvg;
end

procedure obj_name_proc(variable obj) begin
return obj_name(obj) if obj else "(null)";
end
Expand Down
22 changes: 21 additions & 1 deletion scripts_src/_pbs_craft/crafting.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
#define MAX_CATEGORIES (ITEMS_PER_SCREEN + 2)

#define EXTRA_MSG_NAME "pbs_craft.msg"
#define EXP_MAP_NAME "pbs_craft_exp"
#define pcx_path(name) "pcx\\" #name ".pcx"


variable begin
craft_msg_id;
craft_ui_mode;
use_categories := false;
craft_exp_map; // maps output item PID to 1 if exp was granted for crafting

cur_recipe;
cur_category;
Expand Down Expand Up @@ -114,6 +116,7 @@ procedure init_crafting begin
craft_msg_id := add_extra_msg_file(EXTRA_MSG_NAME);
craft_ui_mode := MODE_EXIT;
craft_raw_cfg := load_raw_crafting_config;
craft_exp_map := load_create_array_map(EXP_MAP_NAME);
end


Expand All @@ -138,6 +141,22 @@ procedure cur_recipe_batch_size begin
return cur_recipe.qty * item_pid_pack_size(cur_recipe.pid);
end

procedure gain_exp_for_crafting begin
variable
skillMult := craft_cfg.exp_skill_mult,
pid := cur_recipe.pid;
if (skillMult <= 0 or craft_exp_map[pid] > 0) then return;

variable
skillMaxAvg := recipe_max_average_skill(cur_recipe),
roundTo := craft_cfg.exp_round_to,
exp := ceil(skillMaxAvg * skillMult * 1.0 / roundTo) * roundTo;

give_exp_points(exp);
display_msg(sprintf(mstr_craft(420), exp));
craft_exp_map[pid] := 1;
end

procedure do_cancel_on begin
end

Expand All @@ -158,7 +177,6 @@ procedure do_cancel_up begin
play_sfx("IB1LU1X1");
call exit_mode;
SayQuit;
//tap_key(DIK_ESCAPE); // a hack to close the dialog without actually clicking on any reply options
end

procedure show_cancel_button(variable winName) begin
Expand Down Expand Up @@ -522,6 +540,8 @@ procedure batch_item(variable num) begin
mins := cur_recipe.time * num % 60;
display_msg(string_format(mstr_craft(400), proto_data(cur_recipe.pid, it_name), (num * cur_recipe_batch_size))
+ string_format(mstr_craft(402), hours, mins));

call gain_exp_for_crafting;
call batch_ok_mode;
end

Expand Down

0 comments on commit 82dc14d

Please sign in to comment.