Skip to content

Commit 259455d

Browse files
committed
tournament: Implement new tournament winnings calculations
Should be closer to the original than the previous were.
1 parent 4a9118a commit 259455d

File tree

5 files changed

+76
-41
lines changed

5 files changed

+76
-41
lines changed

src/game/scenes/arena.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "game/objects/scrap.h"
2626
#include "game/protos/object.h"
2727
#include "game/scenes/arena.h"
28+
#include "game/scenes/mechlab/har_economy.h"
2829
#include "game/scenes/mechlab/lab_menu_customize.h"
2930
#include "game/utils/score.h"
3031
#include "game/utils/settings.h"
@@ -267,16 +268,6 @@ static void arena_end(scene *sc) {
267268

268269
// if tournament player won
269270
if(is_tournament(gs) && local->winner == 0) {
270-
// TODO The repair costs formula here is completely bogus
271-
int trade_value = calculate_trade_value(player_winner->pilot) / 100;
272-
float hp_percentage = (float)winner_har->health / (float)winner_har->health_max;
273-
fight_stats->repair_cost = (1.0f - hp_percentage) * trade_value;
274-
275-
float winnings_multiplier = player_winner->chr->winnings_multiplier;
276-
fight_stats->winnings =
277-
winnings_multiplier * (calculate_winnings(player_winner->pilot, false) +
278-
calculate_winnings(player_loser->pilot, true) + player_loser->pilot->winnings);
279-
280271
// secret players have no rank, and don't increase your own ranking
281272
if(!gs->match_settings.sim && player_loser->pilot->rank > 0) {
282273
player_winner->pilot->rank--;
@@ -290,6 +281,14 @@ static void arena_end(scene *sc) {
290281
}
291282
}
292283
}
284+
285+
// TODO: The repair costs formula here is completely bogus
286+
int trade_value = calculate_trade_value(player_winner->pilot) / 100;
287+
float hp_percentage = (float)winner_har->health / (float)winner_har->health_max;
288+
fight_stats->repair_cost = (1.0f - hp_percentage) * trade_value;
289+
290+
fight_stats->winnings =
291+
calculate_winnings(player_winner->pilot, player_loser->pilot, player_winner->chr->winnings_multiplier);
293292
}
294293
// if tournament player lost
295294
else if(is_tournament(gs) && local->winner == 1) {

src/game/scenes/mechlab/har_economy.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "game/scenes/mechlab/har_economy.h"
22
#include "formats/pilot.h"
3+
#include "utils/c_array_util.h"
34
#include "utils/log.h"
45
#include "utils/random.h"
56

@@ -113,3 +114,68 @@ void upgrade_har(sd_pilot *pilot, enum HAR_UPGRADE upgrade) {
113114
abort();
114115
}
115116
}
117+
118+
static void update_total_value(sd_pilot *pilot) {
119+
int value = har_prices[pilot->har_id];
120+
for(int i = 1; i < pilot->arm_power; i++) {
121+
value += har_upgrade_price[pilot->har_id] * upgrade_level_multiplier[i] * arm_leg_multiplier;
122+
}
123+
124+
for(int i = 1; i < pilot->arm_speed; i++) {
125+
value += har_upgrade_price[pilot->har_id] * upgrade_level_multiplier[i] * arm_leg_multiplier;
126+
}
127+
128+
for(int i = 1; i < pilot->leg_power; i++) {
129+
value += har_upgrade_price[pilot->har_id] * upgrade_level_multiplier[i] * arm_leg_multiplier;
130+
}
131+
132+
for(int i = 1; i < pilot->leg_speed; i++) {
133+
value += har_upgrade_price[pilot->har_id] * upgrade_level_multiplier[i] * arm_leg_multiplier;
134+
}
135+
136+
for(int i = 1; i < pilot->armor; i++) {
137+
value += har_upgrade_price[pilot->har_id] * upgrade_level_multiplier[i] * armor_multiplier;
138+
}
139+
140+
for(int i = 1; i < pilot->stun_resistance; i++) {
141+
value += har_upgrade_price[pilot->har_id] * upgrade_level_multiplier[i] * stun_res_multiplier;
142+
}
143+
144+
pilot->total_value = (value * 70) / 100;
145+
}
146+
147+
static int rank_additions[] = {
148+
500, 200, 160, 120, 100, 90, 80, 70, 60, 55, 50, 45, 40, 35, 30, 25, 20,
149+
17, 15, 14, 13, 12, 11, 11, 10, 9, 8, 8, 7, 7, 6, 6, 5, 0,
150+
};
151+
152+
static float rank_scale(unsigned rank) {
153+
assert(rank >= 1);
154+
rank -= 1;
155+
float a = rank * 0.1 + 1.0;
156+
float b = rank * 0.2 + 1.0;
157+
return b * a * a;
158+
}
159+
160+
static float rank_bonus(unsigned rank) {
161+
assert(rank >= 1);
162+
rank -= 1;
163+
if(rank < N_ELEMENTS(rank_additions)) {
164+
return rank_additions[rank];
165+
}
166+
return 5.0;
167+
}
168+
169+
float calculate_winnings(sd_pilot *winner, sd_pilot *loser, float winnings_multiplier) {
170+
update_total_value(winner);
171+
update_total_value(loser);
172+
173+
int adjusted_value = winner->total_value - (har_prices[0] * 85) / 100 - 500;
174+
float loser_value = (loser->total_value + loser->money) / 45.0 + (int)loser->winnings;
175+
float winnings = loser_value + (adjusted_value / rank_scale(winner->rank) / 30.0);
176+
177+
winnings += winner->trn_rank_money * rank_bonus(winner->rank);
178+
winnings *= 0.7f;
179+
winnings *= winnings_multiplier;
180+
return winnings;
181+
}

src/game/scenes/mechlab/har_economy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static const int32_t arm_leg_multiplier = 2;
2929
static const int32_t stun_res_multiplier = 3;
3030
static const int32_t armor_multiplier = 5;
3131

32+
float calculate_winnings(sd_pilot *winner, sd_pilot *loser, float winnings_multiplier);
3233
bool har_can_upgrade(sd_pilot *pilot, enum HAR_UPGRADE upgrade);
3334
void purchase_random_har(sd_pilot *pilot);
3435
void purchase_random_har_upgrades(sd_pilot *pilot);

src/game/scenes/mechlab/lab_menu_customize.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,6 @@ int calculate_trade_value(sd_pilot *pilot) {
5454
return trade_value * 0.85;
5555
}
5656

57-
static const int32_t arm_leg_value[10] = {0, 9, 34, 94, 197, 351, 606, 1034, 1675, 2700};
58-
static const int32_t armor_value[10] = {0, 22, 86, 235, 492, 876, 1516, 2584, 4186, 6748};
59-
static const int32_t stun_value[10] = {0, 13, 51, 141, 294, 526, 910, 1551, 2511, 4463};
60-
61-
int calculate_winnings(sd_pilot *pilot, bool add_har_base) {
62-
int winnings = 0;
63-
if(add_har_base) {
64-
winnings = (har_prices[pilot->har_id] + 29000) / 89;
65-
}
66-
for(int i = 1; i <= pilot->arm_power; i++) {
67-
winnings += arm_leg_value[i];
68-
}
69-
for(int i = 1; i <= pilot->arm_speed; i++) {
70-
winnings += arm_leg_value[i];
71-
}
72-
for(int i = 1; i <= pilot->leg_power; i++) {
73-
winnings += arm_leg_value[i];
74-
}
75-
for(int i = 1; i <= pilot->leg_speed; i++) {
76-
winnings += arm_leg_value[i];
77-
}
78-
for(int i = 1; i <= pilot->armor; i++) {
79-
winnings += armor_value[i];
80-
}
81-
for(int i = 1; i <= pilot->stun_resistance; i++) {
82-
winnings += stun_value[i];
83-
}
84-
return winnings;
85-
}
86-
8757
int har_price(int har_id) {
8858
return har_prices[har_id];
8959
}

src/game/scenes/mechlab/lab_menu_customize.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
component *lab_menu_customize_create(scene *s);
88
int calculate_trade_value(sd_pilot *pilot);
9-
int calculate_winnings(sd_pilot *pilot, bool add_har_base);
109
int sell_highest_value_upgrade(sd_pilot *pilot, char *sold);
1110
int har_price(int har_id);
1211

0 commit comments

Comments
 (0)