Skip to content

Commit 3c396d7

Browse files
committed
MonSca: Implemented support for patch variant 'MonScaPlus'
1 parent ed49ad4 commit 3c396d7

5 files changed

+65
-48
lines changed

src/game_config_game.h

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct Game_ConfigGame {
6363
ConfigParam<int> patch_monsca_item{ "MonSca", "Scales enemy battle stats by variable value. (Gained Item)", "Patch", "MonSca.ItemId", 0 };
6464
ConfigParam<int> patch_monsca_droprate{ "MonSca", "Scales enemy battle stats by variable value. (Item Drop Rate)", "Patch", "MonSca.ItemDropRate", 0 };
6565
ConfigParam<int> patch_monsca_levelscaling{ "MonSca", "Scales enemy battle stats by variable value. (Alternate formula)", "Patch", "MonSca.LevelScaling", 0 };
66+
ConfigParam<int> patch_monsca_plus{ "MonSca", "Scale enemies individually based on troop index", "Patch", "MonSca.Plus", 0 };
6667

6768
ConfigParam<int> patch_explus_var{ "EXPlus", "Boosts party EXP by set percentages", "Patch", "EXPlus.VarExpBoost", 0 };
6869
ConfigParam<int> patch_explusplus_var{ "EXPlus", "Allows for setting party index of given actors to a variable", "Patch", "EXPlus.VarActorInParty", 0 };

src/game_enemy.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -329,37 +329,37 @@ inline int Game_Enemy::GetTroopMemberId() const {
329329

330330
inline int Game_Enemy::GetBaseMaxHp() const {
331331
auto max_hp = enemy->max_hp;
332-
RuntimePatches::MonSca::ModifyMaxHp(max_hp);
332+
RuntimePatches::MonSca::ModifyMaxHp(*this, max_hp);
333333
return max_hp;
334334
}
335335

336336
inline int Game_Enemy::GetBaseMaxSp() const {
337337
auto max_sp = enemy->max_sp;
338-
RuntimePatches::MonSca::ModifyMaxSp(max_sp);
338+
RuntimePatches::MonSca::ModifyMaxSp(*this, max_sp);
339339
return max_sp;
340340
}
341341

342342
inline int Game_Enemy::GetBaseAtk(Weapon) const {
343343
auto attack = enemy->attack;
344-
RuntimePatches::MonSca::ModifyAtk(attack);
344+
RuntimePatches::MonSca::ModifyAtk(*this, attack);
345345
return attack;
346346
}
347347

348348
inline int Game_Enemy::GetBaseDef(Weapon) const {
349349
auto defense = enemy->defense;
350-
RuntimePatches::MonSca::ModifyDef(defense);
350+
RuntimePatches::MonSca::ModifyDef(*this, defense);
351351
return defense;
352352
}
353353

354354
inline int Game_Enemy::GetBaseSpi(Weapon) const {
355355
auto spirit = enemy->spirit;
356-
RuntimePatches::MonSca::ModifySpi(spirit);
356+
RuntimePatches::MonSca::ModifySpi(*this, spirit);
357357
return spirit;
358358
}
359359

360360
inline int Game_Enemy::GetBaseAgi(Weapon) const {
361361
auto agility = enemy->agility;
362-
RuntimePatches::MonSca::ModifyAgi(agility);
362+
RuntimePatches::MonSca::ModifyAgi(*this, agility);
363363
return agility;
364364
}
365365

src/game_enemyparty.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int Game_EnemyParty::GetExp() const {
104104
for (auto& enemy: enemies) {
105105
if (enemy.IsDead()) {
106106
auto exp = enemy.GetExp();
107-
RuntimePatches::MonSca::ModifyExpGained(exp);
107+
RuntimePatches::MonSca::ModifyExpGained(enemy, exp);
108108

109109
sum += exp;
110110
}
@@ -117,7 +117,7 @@ int Game_EnemyParty::GetMoney() const {
117117
for (auto& enemy: enemies) {
118118
if (enemy.IsDead()) {
119119
auto money = enemy.GetMoney();
120-
RuntimePatches::MonSca::ModifyMoneyGained(money);
120+
RuntimePatches::MonSca::ModifyMoneyGained(enemy, money);
121121

122122
sum += money;
123123
}
@@ -129,12 +129,12 @@ void Game_EnemyParty::GenerateDrops(std::vector<int>& out) const {
129129
for (auto& enemy: enemies) {
130130
if (enemy.IsDead()) {
131131
auto drop_id = enemy.GetDropId();
132-
RuntimePatches::MonSca::ModifyItemGained(drop_id);
132+
RuntimePatches::MonSca::ModifyItemGained(enemy, drop_id);
133133

134134
// Only roll if the enemy has something to drop
135135
if (drop_id > 0) {
136136
auto drop_rate = enemy.GetDropProbability();
137-
RuntimePatches::MonSca::ModifyItemDropRate(drop_rate);
137+
RuntimePatches::MonSca::ModifyItemDropRate(enemy, drop_rate);
138138

139139
if (Rand::ChanceOf(drop_rate, 100)) {
140140
out.push_back(drop_id);

src/game_runtime_patches.cpp

+34-25
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "game_variables.h"
2525
#include "game_actor.h"
2626
#include "game_battler.h"
27+
#include "game_enemy.h"
2728
#include "main_data.h"
2829
#include "player.h"
2930
#include "output.h"
@@ -127,7 +128,7 @@ namespace {
127128
void RuntimePatches::LockPatchesAsDiabled() {
128129
#ifndef NO_RUNTIME_PATCHES
129130
LockPatchArguments<2>(EncounterRandomnessAlert::patch_args);
130-
LockPatchArguments<11>(MonSca::patch_args);
131+
LockPatchArguments<12>(MonSca::patch_args);
131132
LockPatchArguments<2>(EXPlus::patch_args);
132133
LockPatchArguments<2>(GuardRevamp::patch_args);
133134
#endif
@@ -140,7 +141,7 @@ bool RuntimePatches::ParseFromCommandLine(CmdlineParser& cp) {
140141
return ParsePatchArguments<2>(cp, arg, EncounterRandomnessAlert::patch_args);
141142
}
142143
if (cp.ParseNext(arg, 1, { "--patch-monsca", "--no-patch-monsca" })) {
143-
return ParsePatchArguments<11>(cp, arg, MonSca::patch_args);
144+
return ParsePatchArguments<12>(cp, arg, MonSca::patch_args);
144145
}
145146
if (cp.ParseNext(arg, 1, { "--patch-explus", "--no-patch-explus" })) {
146147
return ParsePatchArguments<2>(cp, arg, EXPlus::patch_args);
@@ -158,7 +159,7 @@ bool RuntimePatches::ParseFromIni(lcf::INIReader& ini) {
158159
#ifndef NO_RUNTIME_PATCHES
159160
bool patch_override = false;
160161
patch_override |= ParsePatchFromIni<2>(ini, EncounterRandomnessAlert::patch_args);
161-
patch_override |= ParsePatchFromIni<11>(ini, MonSca::patch_args);
162+
patch_override |= ParsePatchFromIni<12>(ini, MonSca::patch_args);
162163
patch_override |= ParsePatchFromIni<2>(ini, EXPlus::patch_args);
163164
patch_override |= ParsePatchFromIni<2>(ini, GuardRevamp::patch_args);
164165
return patch_override;
@@ -171,7 +172,7 @@ bool RuntimePatches::ParseFromIni(lcf::INIReader& ini) {
171172
void RuntimePatches::DetermineActivePatches(std::vector<std::string>& patches) {
172173
#ifndef NO_RUNTIME_PATCHES
173174
PrintPatch<2>(patches, EncounterRandomnessAlert::patch_args);
174-
PrintPatch<11>(patches, MonSca::patch_args);
175+
PrintPatch<12>(patches, MonSca::patch_args);
175176
PrintPatch<2>(patches, EXPlus::patch_args);
176177
PrintPatch<2>(patches, GuardRevamp::patch_args);
177178
#else
@@ -209,7 +210,15 @@ namespace RuntimePatches::MonSca {
209210
return switch_id > 0 && Main_Data::game_switches->Get(switch_id);
210211
}
211212

212-
void ApplyScaling(int& val, int mod) {
213+
int GetVariableId(Game_Enemy const& enemy, int var_id) {
214+
if (Player::game_config.patch_monsca_plus.Get() > 0) {
215+
return var_id + enemy.GetTroopMemberId();
216+
}
217+
return var_id;
218+
}
219+
220+
void ApplyScaling(Game_Enemy const& enemy, int& val, int var_id) {
221+
int mod = Main_Data::game_variables->Get(GetVariableId(enemy, var_id));
213222
if (mod == 0) {
214223
return;
215224
}
@@ -221,113 +230,113 @@ namespace RuntimePatches::MonSca {
221230
}
222231
}
223232

224-
void RuntimePatches::MonSca::ModifyMaxHp(int& val) {
233+
void RuntimePatches::MonSca::ModifyMaxHp(Game_Enemy const& enemy, int& val) {
225234
#ifdef NO_RUNTIME_PATCHES
226235
// no-op
227236
(void)val;
228237
return;
229238
#endif
230239
if (auto var_id = Player::game_config.patch_monsca_maxhp.Get(); var_id > 0) {
231-
ApplyScaling(val, Main_Data::game_variables->Get(var_id));
240+
ApplyScaling(enemy, val, var_id);
232241
}
233242
}
234243

235-
void RuntimePatches::MonSca::ModifyMaxSp(int& val) {
244+
void RuntimePatches::MonSca::ModifyMaxSp(Game_Enemy const& enemy, int& val) {
236245
#ifdef NO_RUNTIME_PATCHES
237246
// no-op
238247
(void)val;
239248
return;
240249
#endif
241250
if (auto var_id = Player::game_config.patch_monsca_maxsp.Get(); var_id > 0) {
242-
ApplyScaling(val, Main_Data::game_variables->Get(var_id));
251+
ApplyScaling(enemy, val, var_id);
243252
}
244253
}
245254

246-
void RuntimePatches::MonSca::ModifyAtk(int& val) {
255+
void RuntimePatches::MonSca::ModifyAtk(Game_Enemy const& enemy, int& val) {
247256
#ifdef NO_RUNTIME_PATCHES
248257
// no-op
249258
(void)val;
250259
return;
251260
#endif
252261
if (auto var_id = Player::game_config.patch_monsca_atk.Get(); var_id > 0) {
253-
ApplyScaling(val, Main_Data::game_variables->Get(var_id));
262+
ApplyScaling(enemy, val, var_id);
254263
}
255264
}
256265

257-
void RuntimePatches::MonSca::ModifyDef(int& val) {
266+
void RuntimePatches::MonSca::ModifyDef(Game_Enemy const& enemy, int& val) {
258267
#ifdef NO_RUNTIME_PATCHES
259268
// no-op
260269
(void)val;
261270
return;
262271
#endif
263272
if (auto var_id = Player::game_config.patch_monsca_def.Get(); var_id > 0) {
264-
ApplyScaling(val, Main_Data::game_variables->Get(var_id));
273+
ApplyScaling(enemy, val, var_id);
265274
}
266275
}
267276

268-
void RuntimePatches::MonSca::ModifySpi(int& val) {
277+
void RuntimePatches::MonSca::ModifySpi(Game_Enemy const& enemy, int& val) {
269278
#ifdef NO_RUNTIME_PATCHES
270279
// no-op
271280
(void)val;
272281
return;
273282
#endif
274283
if (auto var_id = Player::game_config.patch_monsca_spi.Get(); var_id > 0) {
275-
ApplyScaling(val, Main_Data::game_variables->Get(var_id));
284+
ApplyScaling(enemy, val, var_id);
276285
}
277286
}
278287

279-
void RuntimePatches::MonSca::ModifyAgi(int& val) {
288+
void RuntimePatches::MonSca::ModifyAgi(Game_Enemy const& enemy, int& val) {
280289
#ifdef NO_RUNTIME_PATCHES
281290
// no-op
282291
(void)val;
283292
return;
284293
#endif
285294
if (auto var_id = Player::game_config.patch_monsca_agi.Get(); var_id > 0) {
286-
ApplyScaling(val, Main_Data::game_variables->Get(var_id));
295+
ApplyScaling(enemy, val, var_id);
287296
}
288297
}
289298

290-
void RuntimePatches::MonSca::ModifyExpGained(int& val) {
299+
void RuntimePatches::MonSca::ModifyExpGained(Game_Enemy const& enemy, int& val) {
291300
#ifdef NO_RUNTIME_PATCHES
292301
// no-op
293302
(void)val;
294303
return;
295304
#endif
296305
if (auto var_id = Player::game_config.patch_monsca_exp.Get(); var_id > 0) {
297-
ApplyScaling(val, Main_Data::game_variables->Get(var_id));
306+
ApplyScaling(enemy, val, var_id);
298307
}
299308
}
300309

301-
void RuntimePatches::MonSca::ModifyMoneyGained(int& val) {
310+
void RuntimePatches::MonSca::ModifyMoneyGained(Game_Enemy const& enemy, int& val) {
302311
#ifdef NO_RUNTIME_PATCHES
303312
// no-op
304313
(void)val;
305314
return;
306315
#endif
307316
if (auto var_id = Player::game_config.patch_monsca_gold.Get(); var_id > 0) {
308-
ApplyScaling(val, Main_Data::game_variables->Get(var_id));
317+
ApplyScaling(enemy, val, var_id);
309318
}
310319
}
311320

312-
void RuntimePatches::MonSca::ModifyItemGained(int& item_id) {
321+
void RuntimePatches::MonSca::ModifyItemGained(Game_Enemy const& enemy, int& item_id) {
313322
#ifdef NO_RUNTIME_PATCHES
314323
// no-op
315324
(void)item_id;
316325
return;
317326
#endif
318327
if (auto var_id = Player::game_config.patch_monsca_item.Get(); var_id > 0) {
319-
item_id += Main_Data::game_variables->Get(var_id);
328+
item_id += Main_Data::game_variables->Get(GetVariableId(enemy, var_id));
320329
}
321330
}
322331

323-
void RuntimePatches::MonSca::ModifyItemDropRate(int& val) {
332+
void RuntimePatches::MonSca::ModifyItemDropRate(Game_Enemy const& enemy, int& val) {
324333
#ifdef NO_RUNTIME_PATCHES
325334
// no-op
326335
(void)val;
327336
return;
328337
#endif
329338
if (auto var_id = Player::game_config.patch_monsca_droprate.Get(); var_id > 0) {
330-
ApplyScaling(val, Main_Data::game_variables->Get(var_id));
339+
ApplyScaling(enemy, val, var_id);
331340
}
332341
}
333342

src/game_runtime_patches.h

+20-13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
class Game_Actor;
2626
class Game_Battler;
27+
class Game_Enemy;
2728

2829
// When this compile flag is set, all of the evaluation logic for these patches
2930
// will be disabled, by simply voiding any calls to their function hooks.
@@ -72,7 +73,7 @@ namespace RuntimePatches {
7273
}
7374

7475
/**
75-
* Support for RPG_RT patch 'MonSca'.
76+
* Support for RPG_RT patch 'MonSca' & 'MonScaPlus'.
7677
* This patch scales the default battle parameters of an enemy
7778
* based on the contents of some in-game variables.
7879
* (Default: V[1001] - V[1010])
@@ -82,9 +83,14 @@ namespace RuntimePatches {
8283
*
8384
* Default formula: val = val * V[...] / 1000
8485
* Alternative formula: val = val * avg_level * V[...] / 1000
86+
*
87+
* Variant 'MonScaPlus':
88+
* If set, the variable IDs used for scaling will be offset
89+
* by the enemy's troop index.
90+
* -> V[base_var_id + troop_index]
8591
*/
8692
namespace MonSca {
87-
constexpr std::array<PatchArg, 11> patch_args = { {
93+
constexpr std::array<PatchArg, 12> patch_args = { {
8894
{ Player::game_config.patch_monsca_maxhp, "-maxhp", 1001 },
8995
{ Player::game_config.patch_monsca_maxsp, "-maxsp", 1002 },
9096
{ Player::game_config.patch_monsca_atk, "-atk", 1003 },
@@ -95,33 +101,34 @@ namespace RuntimePatches {
95101
{ Player::game_config.patch_monsca_gold, "-gold", 1008 },
96102
{ Player::game_config.patch_monsca_item, "-item", 1009 },
97103
{ Player::game_config.patch_monsca_droprate, "-droprate", 1010 },
98-
{ Player::game_config.patch_monsca_levelscaling, "-lvlscale", 1001 }
104+
{ Player::game_config.patch_monsca_levelscaling, "-lvlscale", 1001 },
105+
{ Player::game_config.patch_monsca_plus, "-plus", 0 }
99106
} };
100107

101108
/** Scales an enemies's maximum HP stat, based on the value of variable V[1001] */
102-
void ModifyMaxHp(int& val);
109+
void ModifyMaxHp(Game_Enemy const& enemy, int& val);
103110
/** Scales an enemies's maximum SP stat, based on the value of variable V[1002] */
104-
void ModifyMaxSp(int& val);
111+
void ModifyMaxSp(Game_Enemy const& enemy, int& val);
105112
/** Scales an enemies's attack stat, based on the value of variable V[1003] */
106-
void ModifyAtk(int& val);
113+
void ModifyAtk(Game_Enemy const& enemy, int& val);
107114
/** Scales an enemies's defense stat, based on the value of variable V[1004] */
108-
void ModifyDef(int& val);
115+
void ModifyDef(Game_Enemy const& enemy, int& val);
109116
/** Scales an enemies's spirit stat, based on the value of variable V[1005] */
110-
void ModifySpi(int& val);
117+
void ModifySpi(Game_Enemy const& enemy, int& val);
111118
/** Scales an enemies's agility stat, based on the value of variable V[1006] */
112-
void ModifyAgi(int& val);
119+
void ModifyAgi(Game_Enemy const& enemy, int& val);
113120
/** Scales the experience points gained by defating an enemy, based on the value of variable V[1007] */
114-
void ModifyExpGained(int& val);
121+
void ModifyExpGained(Game_Enemy const& enemy, int& val);
115122
/** Scales the money gained by defating an enemy, based on the value of variable V[1008] */
116-
void ModifyMoneyGained(int& val);
123+
void ModifyMoneyGained(Game_Enemy const& enemy, int& val);
117124
/**
118125
* Modifies the item dropped by defating an enemy, based on the value of variable V[1009]
119126
* In contrast to other modifers of this patch, this skips the normal formula and just
120127
* adds the variable value to the result.
121128
*/
122-
void ModifyItemGained(int& item_id);
129+
void ModifyItemGained(Game_Enemy const& enemy, int& item_id);
123130
/** Scales the item drop rate of an enemy, based on the value of variable V[1010] */
124-
void ModifyItemDropRate(int& val);
131+
void ModifyItemDropRate(Game_Enemy const& enemy, int& val);
125132
}
126133

127134
/**

0 commit comments

Comments
 (0)