Skip to content

Commit

Permalink
Heretic|Definitions: Defining ammo per shot with Values
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 3, 2019
1 parent 6b3c9b5 commit d254182
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
1 change: 1 addition & 0 deletions doomsday/apps/plugins/heretic/include/h_main.h
Expand Up @@ -30,6 +30,7 @@
DENG_EXTERN_C gamemode_t gameMode;
DENG_EXTERN_C int gameModeBits;

DENG_EXTERN_C const char *ammoName[NUM_AMMO_TYPES];
DENG_EXTERN_C char const *borderGraphics[];

DENG_EXTERN_C float const defFontRGB[];
Expand Down
38 changes: 32 additions & 6 deletions doomsday/apps/plugins/heretic/src/h_items.cpp
Expand Up @@ -474,18 +474,44 @@ AmmoDef const *P_AmmoDef(ammotype_t type)
*/
void P_InitWeaponInfo()
{
for(auto i = int( WT_FIRST ); i < NUM_WEAPON_TYPES; ++i)
for (auto i = int(WT_FIRST); i < NUM_WEAPON_TYPES; ++i)
{
auto const id = String::number(i);
const String id = String::number(i);

for(int k = 0; k < 2; ++k) // Each firing mode.
for (int k = 0; k < 2; ++k) // Each firing mode.
{
// Firing modes other than @c 0 use a sublevel.
const String mode = (k == 0 ? "" : "|" + String::number(k + 1));
const String key = "Weapon Info|" + id + mode + "|";

weaponmodeinfo_t *wminfo = WEAPON_INFO(i, PCLASS_PLAYER, k);
DENG2_ASSERT(wminfo);

// Firing modes other than @c 0 use a sublevel.
String const mode = (k == 0 ? "" : "|" + String::number(k + 1));
if(ded_value_t const *staticSwitch = Defs().getValueById("Weapon Info|" + id + mode + "|Static"))
// Per shot ammo.
{
int definedAmmoTypes = 0;
for (int a = AT_FIRST; a < NUM_AMMO_TYPES; ++a)
{
if (const ded_value_t *perShot = Defs().getValueById(key + "Per shot|" + ammoName[a]))
{
wminfo->perShot[a] = String(perShot->text).toInt();
definedAmmoTypes |= 1 << a;
}
}
if (definedAmmoTypes)
{
// Clear the other ammo amounts.
for (int a = AT_FIRST; a < NUM_AMMO_TYPES; ++a)
{
if ((definedAmmoTypes & (1 << a)) == 0)
{
wminfo->perShot[a] = 0;
}
}
}
}

if (const ded_value_t *staticSwitch = Defs().getValueById(key + "Static"))
{
wminfo->staticSwitch = String(staticSwitch->text).toInt();
}
Expand Down
18 changes: 9 additions & 9 deletions doomsday/apps/plugins/heretic/src/h_main.cpp
Expand Up @@ -43,6 +43,15 @@ using namespace common;
gamemode_t gameMode;
int gameModeBits;

const char *ammoName[NUM_AMMO_TYPES] = {
"Crystal",
"Arrow",
"Orb",
"Rune",
"FireOrb",
"MSphere",
};

// Default font colours.
float const defFontRGB[] = { .425f, .986f, .378f };
float const defFontRGB2[] = { 1, .65f, .275f };
Expand Down Expand Up @@ -324,15 +333,6 @@ static void initAmmoInfo()
{
static const int defaultMaxAmmo[NUM_AMMO_TYPES] = {100, 50, 200, 200, 20, 150};

static const char *ammoName[NUM_AMMO_TYPES] = {
"Crystal",
"Arrow",
"Orb",
"Rune",
"FireOrb",
"MSphere",
};

for (int i = AT_FIRST; i < NUM_AMMO_TYPES; ++i)
{
const String name = ammoName[i];
Expand Down

0 comments on commit d254182

Please sign in to comment.