--- a/src/GameSrc/hkeyfunc.c +++ b/src/GameSrc/hkeyfunc.c @@ -1465,3 +1465,71 @@ #pragma enable_message(202) #endif // NOT_YET + +#ifdef __ANDROID__ +// Tops up parts of the player's state; android/app/src/main/cpp/qs_config.c +// calls it once per frame with the "unlimited" cheats that are switched on. +// `what` is a bitmask: 1 health, 2 energy, 4 ammo, 8 items (the same values as +// QS_CHEAT_MASK_* in qs_config.c). Only conventional guns use ammo: beam and +// melee weapons keep heat in the same field, so they are left alone (beams draw +// on energy). Spare ammo clips, grenades and drugs are only refilled for kinds +// the player already holds, so the cheat never creates items. +void qs_cheat_refill(int what) { + const int kAmmoFloor = 99; + const int kItemFloor = 99; + uchar vitalsChanged = FALSE; + uchar inventoryChanged = FALSE; + + if (player_struct.dead) + return; + if ((what & 1) && player_struct.hit_points < PLAYER_MAX_HP) { + player_struct.hit_points = PLAYER_MAX_HP; + vitalsChanged = TRUE; + } + if ((what & 1) && player_struct.cspace_hp < PLAYER_MAX_HP) { + player_struct.cspace_hp = PLAYER_MAX_HP; + vitalsChanged = TRUE; + } + if ((what & 2) && player_struct.energy < 255) { + player_struct.energy = 255; + vitalsChanged = TRUE; + } + if (vitalsChanged) + chg_set_flg(VITALS_UPDATE); + + if (what & 4) { + for (int i = 0; i < NUM_WEAPON_SLOTS; i++) { + weapon_slot *slot = &player_struct.weapons[i]; + if (slot->type != EMPTY_WEAPON_SLOT && slot->type <= GUN_SUBCLASS_SPECIAL && + slot->ammo < kAmmoFloor) { + slot->ammo = kAmmoFloor; + inventoryChanged = TRUE; + } + } + for (int i = 0; i < NUM_AMMO_TYPES; i++) { + if (player_struct.cartridges[i] > 0 && player_struct.cartridges[i] < kItemFloor) { + player_struct.cartridges[i] = kItemFloor; + inventoryChanged = TRUE; + } + } + } + if (what & 8) { + for (int i = 0; i < NUM_GRENADEZ; i++) { + if (player_struct.grenades[i] > 0 && player_struct.grenades[i] < kItemFloor) { + player_struct.grenades[i] = kItemFloor; + inventoryChanged = TRUE; + } + } + for (int i = 0; i < NUM_DRUGZ; i++) { + if (player_struct.drugs[i] > 0 && player_struct.drugs[i] < kItemFloor) { + player_struct.drugs[i] = kItemFloor; + inventoryChanged = TRUE; + } + } + } + if (inventoryChanged) { + chg_set_flg(INVENTORY_UPDATE); + mfd_force_update(); + } +} +#endif