Skip to content

Commit

Permalink
Add health pickups to config (fixes #219)
Browse files Browse the repository at this point in the history
Change all config to bool types
  • Loading branch information
cxong committed Mar 17, 2014
1 parent d29732e commit 978f2d9
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/cdogs/campaigns.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef struct
char filename[CDOGS_FILENAME_MAX];
char path[CDOGS_PATH_MAX];
char info[80];
int isBuiltin;
bool isBuiltin;
campaign_mode_e mode;
int builtinIndex;
int numMissions;
Expand Down
3 changes: 2 additions & 1 deletion src/cdogs/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void ConfigLoadDefault(Config *config)
config->Game.EnemyDensity = 100;
config->Game.FriendlyFire = 0;
config->Game.NonPlayerHP = 100;
config->Game.PlayerHP = 100;
config->Game.PlayerHP = 50;
config->Game.RandomSeed = 0;
config->Game.SlowMotion = 0;
config->Game.Fog = 1;
Expand All @@ -322,6 +322,7 @@ void ConfigLoadDefault(Config *config)
config->Game.SwitchMoveStyle = SWITCHMOVE_SLIDE;
config->Game.ShotsPushback = 1;
config->Game.AllyCollision = ALLYCOLLISION_REPEL;
config->Game.HealthPickups = true;
config->Graphics.Brightness = 0;
config->Graphics.Fullscreen = 0;
config->Graphics.ResolutionHeight = 240;
Expand Down
23 changes: 12 additions & 11 deletions src/cdogs/config.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) 2013, Cong Xu
Copyright (c) 2013-2014, Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -72,20 +72,21 @@ ScaleMode StrScaleMode(const char *str);

typedef struct
{
int FriendlyFire;
bool FriendlyFire;
unsigned int RandomSeed;
difficulty_e Difficulty;
int SlowMotion;
bool SlowMotion;
int EnemyDensity;
int NonPlayerHP;
int PlayerHP;
int Fog;
bool Fog;
int SightRange;
int Shadows;
int MoveWhenShooting;
bool Shadows;
bool MoveWhenShooting;
SwitchMoveStyle SwitchMoveStyle;
int ShotsPushback;
bool ShotsPushback;
AllyCollision AllyCollision;
bool HealthPickups;
} GameConfig;

typedef enum
Expand All @@ -100,10 +101,10 @@ SplitscreenStyle StrSplitscreenStyle(const char *str);

typedef struct
{
int ShowFPS;
int ShowTime;
bool ShowFPS;
bool ShowTime;
SplitscreenStyle Splitscreen;
int ShowHUDMap;
bool ShowHUDMap;
} InterfaceConfig;

typedef enum
Expand All @@ -127,7 +128,7 @@ typedef struct
QuickPlayQuantity EnemyCount;
QuickPlayQuantity EnemySpeed;
QuickPlayQuantity EnemyHealth;
int EnemiesWithExplosives;
bool EnemiesWithExplosives;
QuickPlayQuantity ItemCount;
} QuickPlayConfig;

Expand Down
7 changes: 5 additions & 2 deletions src/cdogs/config_json.c
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) 2013, Cong Xu
Copyright (c) 2013-2014, Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -63,6 +63,7 @@ static void LoadGameConfigNode(GameConfig *config, json_t *node)
LoadBool(&config->ShotsPushback, node, "ShotsPushback");
JSON_UTILS_LOAD_ENUM(
config->AllyCollision, node, "AllyCollision", StrAllyCollision);
LoadBool(&config->HealthPickups, node, "HealthPickups");
}
static void AddGameConfigNode(GameConfig *config, json_t *root)
{
Expand Down Expand Up @@ -92,6 +93,8 @@ static void AddGameConfigNode(GameConfig *config, json_t *root)
subConfig, "ShotsPushback", json_new_bool(config->ShotsPushback));
JSON_UTILS_ADD_ENUM_PAIR(
subConfig, "AllyCollision", config->AllyCollision, AllyCollisionStr);
json_insert_pair_into_object(
subConfig, "HealthPickups", json_new_bool(config->HealthPickups));
json_insert_pair_into_object(root, "Game", subConfig);
}

Expand Down Expand Up @@ -205,7 +208,7 @@ static void LoadInterfaceConfigNode(
LoadBool(&config->ShowTime, node, "ShowTime");
if (version < 4)
{
int splitscreenAlways;
bool splitscreenAlways;
LoadBool(&splitscreenAlways, node, "SplitscreenAlways");
config->Splitscreen =
splitscreenAlways ? SPLITSCREEN_ALWAYS : SPLITSCREEN_NORMAL;
Expand Down
4 changes: 3 additions & 1 deletion src/cdogs/grafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#ifndef __GRAFX
#define __GRAFX

#include <stdbool.h>

#include <SDL_video.h>

#include "c_array.h"
Expand All @@ -69,7 +71,7 @@ typedef struct
int Brightness;
int ResolutionWidth;
int ResolutionHeight;
int Fullscreen;
bool Fullscreen;
int ScaleFactor;
int ShakeMultiplier;
ScaleMode ScaleMode;
Expand Down
3 changes: 2 additions & 1 deletion src/cdogs/health_pickup.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ static bool TryPlacePickup(HealthPickups *h);
void HealthPickupsUpdate(HealthPickups *h, int ticks)
{
// Don't spawn pickups if not allowed
if (!AreHealthPickupsAllowed(gCampaign.Entry.mode))
if (!AreHealthPickupsAllowed(gCampaign.Entry.mode) ||
!gConfig.Game.HealthPickups)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cdogs/json_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int TryLoadValue(json_t **node, const char *name)
}
return 1;
}
void LoadBool(int *value, json_t *node, const char *name)
void LoadBool(bool *value, json_t *node, const char *name)
{
if (!TryLoadValue(&node, name))
{
Expand Down
4 changes: 3 additions & 1 deletion src/cdogs/json_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
#ifndef __json_utils
#define __json_utils

#include <stdbool.h>

#include <json/json.h>

void AddIntPair(json_t *parent, const char *name, int number);
void AddBoolPair(json_t *parent, const char *name, int value);
void AddStringPair(json_t *parent, const char *name, const char *s);
void LoadBool(int *value, json_t *node, const char *name);
void LoadBool(bool *value, json_t *node, const char *name);
void LoadInt(int *value, json_t *node, const char *name);
char *GetString(json_t *node, const char *name); // remember to free

Expand Down
6 changes: 3 additions & 3 deletions src/cdogs/mission.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ typedef struct
int Count;
int Min;
int Max;
int Edge;
int Overlap;
bool Edge;
bool Overlap;
int Walls;
int WallLength;
int WallPad;
} Rooms;
int Squares;
struct
{
int Enabled;
bool Enabled;
int Min;
int Max;
} Doors;
Expand Down
8 changes: 5 additions & 3 deletions src/cdogs/sounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#ifndef __SOUNDS
#define __SOUNDS

#include <stdbool.h>

#include <SDL_mixer.h>

#include "defs.h"
Expand Down Expand Up @@ -130,9 +132,9 @@ typedef struct
int SoundVolume;
int MusicVolume;
int SoundChannels;
int Footsteps;
int Hits;
int Reloads;
bool Footsteps;
bool Hits;
bool Reloads;
} SoundConfig;

void SoundInitialize(SoundDevice *device, SoundConfig *config);
Expand Down
8 changes: 7 additions & 1 deletion src/mainmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ menu_t *MenuCreateOptionsGame(const char *name)
&gConfig.Game.PlayerHP,
25, 200, 25,
MENU_OPTION_DISPLAY_STYLE_INT_TO_STR_FUNC, (void (*)(void))PercentStr));
MenuAddSubmenu(
menu,
MenuCreateOptionToggle(
"Health pickups",
&gConfig.Game.HealthPickups,
MENU_OPTION_DISPLAY_STYLE_YES_NO));
MenuAddSubmenu(
menu,
MenuCreateOptionToggle(
Expand Down Expand Up @@ -546,7 +552,7 @@ menu_t *MenuCreateQuit(const char *name)


menu_t *MenuCreateOptionToggle(
const char *name, int *config, menu_option_display_style_e style)
const char *name, bool *config, menu_option_display_style_e style)
{
menu_t *menu = MenuCreate(name, MENU_TYPE_SET_OPTION_TOGGLE);
menu->u.option.uHook.optionToggle = config;
Expand Down
4 changes: 2 additions & 2 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct menu
{
union
{
int *optionToggle;
bool *optionToggle;
struct
{
int *option;
Expand Down Expand Up @@ -269,7 +269,7 @@ void MenuSetPostInputFunc(menu_t *menu, MenuPostInputFunc func, void *data);
void MenuSetCustomDisplay(menu_t *menu, MenuDisplayFunc func, void *data);

menu_t *MenuCreateOptionToggle(
const char *name, int *config, menu_option_display_style_e style);
const char *name, bool *config, menu_option_display_style_e style);
menu_t *MenuCreateOptionRange(
const char *name,
int *config,
Expand Down

0 comments on commit 978f2d9

Please sign in to comment.