Skip to content

Commit

Permalink
Add health pickups that exceed max health #71
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Dec 31, 2023
1 parent 9e9b3ad commit 04d6b94
Show file tree
Hide file tree
Showing 31 changed files with 292 additions and 36 deletions.
1 change: 1 addition & 0 deletions missions/custom/techdemo/cyberdogs.cdogscpn/campaign.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"MaxLives": 4,
"PlayerHP": 20,
"PlayerMaxHP": 50,
"PlayerExcessHP": 70,
"Missions": 10
}
9 changes: 9 additions & 0 deletions missions/custom/techdemo/cyberdogs.cdogscpn/characters.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"speed": 256,
"Gun": "Machine gun",
"maxHealth": 40,
"excessHealth": 80,
"flags": 1024,
"probabilityToMove": 50,
"probabilityToTrack": 25,
Expand All @@ -37,6 +38,7 @@
"speed": 256,
"Gun": "Machine gun",
"maxHealth": 40,
"excessHealth": 80,
"flags": 1024,
"probabilityToMove": 50,
"probabilityToTrack": 25,
Expand All @@ -59,6 +61,7 @@
"speed": 256,
"Gun": "Machine gun",
"maxHealth": 40,
"excessHealth": 80,
"flags": 1024,
"probabilityToMove": 50,
"probabilityToTrack": 25,
Expand All @@ -82,6 +85,7 @@
"Gun": "DumbGun",
"Melee": "Fists",
"maxHealth": 15,
"excessHealth": 30,
"flags": 167773184,
"probabilityToMove": 50,
"probabilityToTrack": 50,
Expand All @@ -104,6 +108,7 @@
"Gun": "Lazer",
"Melee": "Fists",
"maxHealth": 12,
"excessHealth": 24,
"flags": 167773184,
"probabilityToMove": 75,
"probabilityToTrack": 75,
Expand All @@ -126,6 +131,7 @@
"Gun": "Gun",
"Melee": "Fists",
"maxHealth": 60,
"excessHealth": 120,
"flags": 167773184,
"probabilityToMove": 75,
"probabilityToTrack": 75,
Expand All @@ -148,6 +154,7 @@
"Gun": "Lazer",
"Melee": "Chainsaw",
"maxHealth": 12,
"excessHealth": 24,
"flags": 167773184,
"probabilityToMove": 75,
"probabilityToTrack": 75,
Expand All @@ -171,6 +178,7 @@
"Gun": "DumbGun",
"Melee": "Fists",
"maxHealth": 15,
"excessHealth": 30,
"flags": 167773184,
"probabilityToMove": 75,
"probabilityToTrack": 75,
Expand All @@ -194,6 +202,7 @@
"Gun": "TurboLazer",
"Melee": "2xChainsaw",
"maxHealth": 60,
"excessHealth": 120,
"flags": 167773184,
"probabilityToMove": 50,
"probabilityToTrack": 50,
Expand Down
3 changes: 2 additions & 1 deletion src/briefing_screens.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,8 @@ static void ApplyBonuses(PlayerData *p, const int bonus)
static int GetHealthBonus(const PlayerData *p)
{
const int maxHealth = p->Char.maxHealth;
return p->hp > maxHealth - 50 ? (p->hp + 50 - p->Char.maxHealth) * 10 : 0;
const int hp = MIN(p->hp, maxHealth);
return hp > maxHealth - 50 ? (hp + 50 - p->Char.maxHealth) * 10 : 0;
}
static int GetResurrectionFee(const PlayerData *p)
{
Expand Down
15 changes: 11 additions & 4 deletions src/cdogs/actors.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,16 @@ static void CheckRescue(const TActor *a)
}
}

void ActorHeal(TActor *actor, int health)
void ActorHeal(TActor *actor, const int amount, const bool exceedMax)
{
actor->health += health;
actor->health = MIN(actor->health, ActorGetCharacter(actor)->maxHealth);
actor->health += amount;
const int maxHealth = ActorGetMaxHeal(actor, exceedMax);
actor->health = MIN(actor->health, maxHealth);
AddParticle ap;
memset(&ap, 0, sizeof ap);
ap.Pos = actor->Pos;
ap.Z = 10;
for (int i = 0; i < MAX(health / 20, 1); i++)
for (int i = 0; i < MAX(amount / 20, 1); i++)
{
ap.Vel = svec2(RAND_FLOAT(-0.2f, 0.2f), RAND_FLOAT(-0.2f, 0.2f));
EmitterStart(&actor->healEffect, &ap);
Expand Down Expand Up @@ -2291,6 +2292,12 @@ static void ActorAddBloodSplatters(
}
}

int ActorGetMaxHeal(const TActor *a, const bool exceedMax)
{
const Character *c = ActorGetCharacter(a);
return exceedMax ? c->excessHealth : c->maxHealth;
}

int ActorGetHealthPercent(const TActor *a)
{
const int maxHealth = ActorGetCharacter(a)->maxHealth;
Expand Down
3 changes: 2 additions & 1 deletion src/cdogs/actors.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void CommandActor(TActor *actor, int cmd, int ticks);
void SlideActor(TActor *actor, int cmd);
void UpdateAllActors(const int ticks);
void ActorsPilotVehicles(void);
void ActorHeal(TActor *actor, int health);
void ActorHeal(TActor *actor, const int amount, const bool exceedMax);
void InjureActor(TActor *actor, int injury);

void ActorAddAmmo(TActor *actor, const int ammoId, const int amount);
Expand Down Expand Up @@ -245,6 +245,7 @@ bool ActorIsInvulnerable(
const TActor *a, const int flags, const int playerUID, const GameMode mode,
const special_damage_e special);

int ActorGetMaxHeal(const TActor *a, const bool exceedMax);
int ActorGetHealthPercent(const TActor *a);
bool ActorIsLowHealth(const TActor *a);
bool ActorIsGrimacing(const TActor *a);
Expand Down
14 changes: 14 additions & 0 deletions src/cdogs/campaigns.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ int CampaignGetMaxHP(const Campaign *c)
return 200 * ConfigGetInt(&gConfig, "Game.PlayerHP") / 100;
}
}
int CampaignGetExcessHP(const Campaign *c)
{
switch (c->Entry.Mode)
{
case GAME_MODE_DOGFIGHT:
return CampaignGetHP(c) * 2;
default:
if (c->Setting.PlayerExcessHP > 0)
{
return c->Setting.PlayerExcessHP;
}
return CampaignGetHP(c) * 2;
}
}
int CampaignGetHP(const Campaign *c)
{
switch (c->Entry.Mode)
Expand Down
2 changes: 2 additions & 0 deletions src/cdogs/campaigns.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ typedef struct
int MaxLives;
int PlayerHP;
int PlayerMaxHP;
int PlayerExcessHP;
CArray Missions; // of Mission
CharacterStore characters;
MusicChunk CustomSongs[MUSIC_COUNT];
Expand Down Expand Up @@ -94,6 +95,7 @@ void CampaignSettingTerminateAll(CampaignSetting *setting);
int CampaignGetMaxLives(const Campaign *c);
int CampaignGetLives(const Campaign *c);
int CampaignGetMaxHP(const Campaign *c);
int CampaignGetExcessHP(const Campaign *c);
int CampaignGetHP(const Campaign *c);

bool CampaignListIsEmpty(const CampaignList *c);
Expand Down
3 changes: 3 additions & 0 deletions src/cdogs/character.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ void CharacterLoadJSON(
CFREE(tmp);
}
LoadInt(&ch->maxHealth, child, "maxHealth");
ch->excessHealth = ch->maxHealth * 2;
LoadInt(&ch->excessHealth, child, "excessHealth");
int flags;
LoadInt(&flags, child, "flags");
ch->flags = flags;
Expand Down Expand Up @@ -289,6 +291,7 @@ bool CharacterSave(CharacterStore *s, const char *path)
json_insert_pair_into_object(node, "Melee", json_new_string(c->Melee->name));
}
AddIntPair(node, "maxHealth", c->maxHealth);
AddIntPair(node, "excessHealth", c->excessHealth);
AddIntPair(node, "flags", c->flags);
if (c->Drop != NULL)
{
Expand Down
2 changes: 2 additions & 0 deletions src/cdogs/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ typedef struct
const WeaponClass *Gun;
const WeaponClass *Melee;
int maxHealth;
// Max health for ExceedMax health pickups
int excessHealth;
unsigned int flags;
CharColors Colors;
const PickupClass *Drop;
Expand Down
1 change: 1 addition & 0 deletions src/cdogs/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ void ConvertCharacter(Character *c, TBadGuy *b)
&c->Colors);
ConvertHairColors(c, face);
c->maxHealth = b->health;
c->excessHealth = c->maxHealth * 2;
c->flags = b->flags;
}
static void ConvertObjective(Objective *dest, struct MissionObjectiveOld *src)
Expand Down
4 changes: 2 additions & 2 deletions src/cdogs/handle_game_events.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2014-2022 Cong Xu
Copyright (c) 2014-2023 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -256,7 +256,7 @@ static void HandleGameEvent(
TActor *a = ActorGetByUID(e.u.Heal.UID);
if (!a->isInUse || a->dead)
break;
ActorHeal(a, e.u.Heal.Amount);
ActorHeal(a, e.u.Heal.Amount, e.u.Heal.ExceedMax);
// Tell the spawner that we took a health so we can
// spawn more (but only if we're the server)
if (e.u.Heal.IsRandomSpawned && !gCampaign.IsClient)
Expand Down
4 changes: 2 additions & 2 deletions src/cdogs/hud/health_gauge.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ void HealthGaugeDraw(
}

HSV hsv = {0.0, 1.0, 1.0};
const int health = actor->health;
const int maxHealth = ActorGetCharacter(actor)->maxHealth;
const int health = MIN(actor->health, maxHealth);
if (actor->poisoned)
{
hsv.h = 120.0;
Expand Down Expand Up @@ -112,7 +112,7 @@ void HealthGaugeDraw(

// Draw health number label
char s[50];
sprintf(s, "%d", health);
sprintf(s, "%d", actor->health);
FontOpts fOpts = opts;
fOpts.Area = svec2i(width, 11);
fOpts.Pad = svec2i(2, 1);
Expand Down
1 change: 1 addition & 0 deletions src/cdogs/map_archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ int MapArchiveSave(const char *filename, CampaignSetting *c)
AddIntPair(root, "MaxLives", c->MaxLives);
AddIntPair(root, "PlayerHP", c->PlayerHP);
AddIntPair(root, "PlayerMaxHP", c->PlayerMaxHP);
AddIntPair(root, "PlayerExcessHP", c->PlayerExcessHP);
AddIntPair(root, "Missions", (int)c->Missions.size);
char buf2[CDOGS_PATH_MAX];
sprintf(buf2, "%s/campaign.json", buf);
Expand Down
1 change: 1 addition & 0 deletions src/cdogs/map_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ void MapNewLoadCampaignJSON(json_t *root, CampaignSetting *c)
LoadInt(&c->MaxLives, root, "MaxLives");
LoadInt(&c->PlayerHP, root, "PlayerHP");
LoadInt(&c->PlayerMaxHP, root, "PlayerMaxHP");
LoadInt(&c->PlayerExcessHP, root, "PlayerExcessHP");
}

static void LoadMissionObjectives(
Expand Down
4 changes: 2 additions & 2 deletions src/cdogs/net_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ void NetServerSendGameStartMessages(NetServer *n, const int peerId)
CA_FOREACH(const PlayerData, pOther, gPlayerDatas)
NPlayerData pd = NMakePlayerData(pOther);
NetServerSendMsg(n, peerId, GAME_EVENT_PLAYER_DATA, &pd);
LOG(LM_NET, LL_DEBUG, "send player data uid(%d) maxHealth(%d) HP(%d)",
(int)pd.UID, (int)pd.MaxHealth, (int)pd.HP);
LOG(LM_NET, LL_DEBUG, "send player data uid(%d) maxHealth(%d) excessHealth(%d) HP(%d)",
(int)pd.UID, (int)pd.MaxHealth, (int)pd.ExcessHealth, (int)pd.HP);
CA_FOREACH_END()

// Send all game-specific config values
Expand Down
1 change: 1 addition & 0 deletions src/cdogs/net_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ NPlayerData NMakePlayerData(const PlayerData *p)
d.Stats = p->Stats;
d.Totals = p->Totals;
d.MaxHealth = p->Char.maxHealth;
d.ExcessHealth = p->Char.excessHealth;
d.HP = p->HP;
d.LastMission = p->lastMission;
d.UID = p->UID;
Expand Down
4 changes: 2 additions & 2 deletions src/cdogs/net_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2014-2017, 2019-2022 Cong Xu
Copyright (c) 2014-2017, 2019-2023 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -40,7 +40,7 @@

#define NET_LISTEN_PORT 34219

#define NET_PROTOCOL_VERSION 14
#define NET_PROTOCOL_VERSION 15

// Messages

Expand Down
7 changes: 4 additions & 3 deletions src/cdogs/pickup.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2014-2015, 2017-2020, 2022 Cong Xu
Copyright (c) 2014-2015, 2017-2020, 2022-2023 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -178,13 +178,14 @@ void PickupPickup(TActor *a, Pickup *p, const bool pickupAll)

case PICKUP_HEALTH:
// Don't pick up unless taken damage
if (a->health < ActorGetCharacter(a)->maxHealth)
if (a->health < ActorGetMaxHeal(a, pe->u.Heal.ExceedMax))
{
canPickup = true;
GameEvent e = GameEventNew(GAME_EVENT_ACTOR_HEAL);
e.u.Heal.UID = a->uid;
e.u.Heal.PlayerUID = a->PlayerUID;
e.u.Heal.Amount = pe->u.Health;
e.u.Heal.Amount = pe->u.Heal.Amount;
e.u.Heal.ExceedMax = pe->u.Heal.ExceedMax;
e.u.Heal.IsRandomSpawned = p->IsRandomSpawned;
GameEventsEnqueue(&gGameEvents, e);
}
Expand Down
7 changes: 4 additions & 3 deletions src/cdogs/pickup_class.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2015-2016, 2018, 2020-2022 Cong Xu
Copyright (c) 2015-2016, 2018, 2020-2023 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -315,8 +315,9 @@ static void LoadPickupEffect(PickupClass *c, json_t *node, const int version)
break;
case PICKUP_HEALTH:
// Set default heal amount
p.u.Health = HEALTH_PICKUP_HEAL_AMOUNT;
LoadInt(&p.u.Health, node, "Health");
p.u.Heal.Amount = HEALTH_PICKUP_HEAL_AMOUNT;
LoadInt(&p.u.Heal.Amount, node, "Health");
LoadBool(&p.u.Heal.ExceedMax, node, "ExceedMax");
break;
case PICKUP_AMMO: {
tmp = GetString(node, "Ammo");
Expand Down
7 changes: 5 additions & 2 deletions src/cdogs/pickup_class.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2015-2016, 2018, 2020-2022 Cong Xu
Copyright (c) 2015-2016, 2018, 2020-2023 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -53,7 +53,10 @@ typedef struct
PickupType Type;
union {
int Score;
int Health;
struct {
int Amount;
bool ExceedMax;
} Heal;
NAmmo Ammo;
int Keys; // Refer to flags in mission.h
int GunId;
Expand Down
Loading

0 comments on commit 04d6b94

Please sign in to comment.