Skip to content

Commit

Permalink
Appearance shuffling.
Browse files Browse the repository at this point in the history
A roguelike classic! This lets us shuffle appearances and colors
for actors read in from json files. This commit also ensures that
actor arrays are properly freed when the game finishes. I'm quite
happy with this refactoring.
  • Loading branch information
Kestrel Gregorich-Trevor committed Jan 19, 2024
1 parent e82c901 commit 082c15e
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 176 deletions.
116 changes: 61 additions & 55 deletions data/creature/boxers.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
{
"flyweight": {
"name": "flyweight",
"lv": 1,
"appearance": "boxer",
"chr": "B",
"color": "yellow",
"hp": 12,
"speed": 40,
"attacks": [
{"damage": 6, "accuracy": 80, "types": ["Mid"]}
],
"ai": { "seekdef": 3 }
},
"bantamweight": {
"name": "bantamweight",
"lv": 5,
"appearance": "boxer",
"chr": "B",
"color": "white",
"hp": 20,
"speed": 40,
"attacks": [
{"damage": 6, "accuracy": 80, "types": ["Mid"]},
{"damage": 8, "accuracy": 60, "types": ["Mid"]}
],
"ai": { "seekdef": 3 }
},
"featherweight": {
"name": "featherweight",
"lv": 10,
"appearance": "boxer",
"chr": "B",
"color": "blue",
"hp": 40,
"speed": 40,
"attacks": [
{"damage": 8, "accuracy": 80, "types": ["Mid"]},
{"damage": 10, "kb":1, "accuracy": 70, "types": ["Mid"]}
],
"ai": { "seekdef": 3 }
},
"lightweight": {
"name": "lightweight",
"lv": 15,
"appearance": "boxer",
"chr": "B",
"color": "magenta",
"hp": 80,
"speed": 40,
"attacks": [
{"damage": 8, "kb": 1, "accuracy": 80, "types": ["Mid"]},
{"damage": 10, "kb": 1, "accuracy": 80, "types": ["Mid"]},
{"damage": 12, "accuracy": 60, "types": ["High"]}
],
"ai": { "seekdef": 3 }
"shuffle": {
"color": 1,
"appearance": 0
},
"actors": {
"flyweight": {
"name": "flyweight",
"lv": 1,
"appearance": "boxer",
"chr": "B",
"color": "yellow",
"hp": 12,
"speed": 40,
"attacks": [
{"damage": 6, "accuracy": 80, "types": ["Mid"]}
],
"ai": { "seekdef": 3 }
},
"bantamweight": {
"name": "bantamweight",
"lv": 5,
"appearance": "boxer",
"chr": "B",
"color": "white",
"hp": 20,
"speed": 40,
"attacks": [
{"damage": 6, "accuracy": 80, "types": ["Mid"]},
{"damage": 8, "accuracy": 60, "types": ["Mid"]}
],
"ai": { "seekdef": 3 }
},
"featherweight": {
"name": "featherweight",
"lv": 10,
"appearance": "boxer",
"chr": "B",
"color": "blue",
"hp": 40,
"speed": 40,
"attacks": [
{"damage": 8, "accuracy": 80, "types": ["Mid"]},
{"damage": 10, "kb":1, "accuracy": 70, "types": ["Mid"]}
],
"ai": { "seekdef": 3 }
},
"lightweight": {
"name": "lightweight",
"lv": 15,
"appearance": "boxer",
"chr": "B",
"color": "magenta",
"hp": 80,
"speed": 40,
"attacks": [
{"damage": 8, "kb": 1, "accuracy": 80, "types": ["Mid"]},
{"damage": 10, "kb": 1, "accuracy": 80, "types": ["Mid"]},
{"damage": 12, "accuracy": 60, "types": ["High"]}
],
"ai": { "seekdef": 3 }
}
}
}
36 changes: 21 additions & 15 deletions data/creature/characters.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
{
"Zenzi": {
"name": "Zenzi",
"lv": 1,
"chr": "@",
"color": "white",
"hp": 40,
"speed": 40,
"unique": 1,
"attacks": [
{ "damage": 6, "stun": 40, "accuracy": 70, "types": ["Low"] },
{ "damage": 8, "stun": 80, "accuracy": 95, "types": ["Mid"] },
{ "damage": 12, "stun": 160, "recovery": 80, "accuracy": 50, "kb": 1, "types": ["High"] },
{ "damage": 6, "stun": 80, "kb": 2, "accuracy": 70, "types": ["Grab"] }
],
"equip" : {}
"shuffle": {
"color": 0,
"appearance": 0
},
"actors" :{
"Zenzi": {
"name": "Zenzi",
"lv": 1,
"chr": "@",
"color": "yellow",
"hp": 40,
"speed": 40,
"unique": 1,
"attacks": [
{ "damage": 6, "stun": 40, "accuracy": 70, "types": ["Low"] },
{ "damage": 8, "stun": 80, "accuracy": 95, "types": ["Mid"] },
{ "damage": 12, "stun": 160, "recovery": 80, "accuracy": 50, "kb": 1, "types": ["High"] },
{ "damage": 6, "stun": 80, "kb": 2, "accuracy": 70, "types": ["Grab"] }
],
"equip" : {}
}
}
}
30 changes: 18 additions & 12 deletions data/creature/debug.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{
"sandbag": {
"name": "sandbag",
"lv": 0,
"appearance": "punching bag",
"chr": "S",
"color": "blue",
"hp": 100,
"speed": 40,
"attacks": [
{"damage": 6, "accuracy": 0, "types": ["Mid"]}
],
"ai": { "seekdef": 10 }
"shuffle": {
"color": 0,
"appearance": 0
},
"actors": {
"sandbag": {
"name": "sandbag",
"lv": 0,
"appearance": "punching bag",
"chr": "S",
"color": "blue",
"hp": 100,
"speed": 40,
"attacks": [
{"damage": 6, "accuracy": 0, "types": ["Mid"]}
],
"ai": { "seekdef": 10 }
}
}
}
36 changes: 21 additions & 15 deletions data/creature/employees.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
{
"flunky": {
"name": "flunky",
"lv": 1,
"appearance": "exhausted employee",
"chr": "@",
"color": "green",
"hp": 12,
"speed": 40,
"attacks": [
{ "damage": 4, "accuracy": 30, "types": ["Low"] }
],
"ai": {
"seekdef": 5
},
"equip": {}
"shuffle": {
"color": 1,
"appearance": 0
},
"actors": {
"flunky": {
"name": "flunky",
"lv": 1,
"appearance": "exhausted employee",
"chr": "@",
"color": "green",
"hp": 12,
"speed": 40,
"attacks": [
{ "damage": 4, "accuracy": 30, "types": ["Low"] }
],
"ai": {
"seekdef": 5
},
"equip": {}
}
}
}
64 changes: 35 additions & 29 deletions data/item/weapons.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
{
"knife": {
"name": "combat knife",
"lv": 0,
"appearance": "knife",
"chr": "/",
"color": "white",
"hp": 4,
"speed": 50,
"attacks": [
{ "damage": 5, "kb": 0, "accuracy": 70, "types": ["Mid"] }
],
"item": {
"pref_slot": "weapon"
},
"description": "A combat knife. Standard issue for somebody."
"shuffle": {
"color": 0,
"appearance": 0
},
"pipe": {
"name": "lead pipe",
"lv": 0,
"appearance": "pipe",
"chr": "/",
"color": "cyan",
"hp": 10,
"speed": 100,
"attacks": [
{ "damage": 12, "kb": 1, "accuracy": 80, "types": ["High"] }
],
"item": {
"pref_slot": "weapon"
"actors": {
"knife": {
"name": "combat knife",
"lv": 0,
"appearance": "knife",
"chr": "/",
"color": "white",
"hp": 4,
"speed": 50,
"attacks": [
{ "damage": 5, "kb": 0, "accuracy": 70, "types": ["Mid"] }
],
"item": {
"pref_slot": "weapon"
},
"description": "A combat knife. Standard issue for somebody."
},
"description": "A trusty pipe. Polaris really shouldn't leave these lying around."
"pipe": {
"name": "lead pipe",
"lv": 0,
"appearance": "pipe",
"chr": "/",
"color": "cyan",
"hp": 10,
"speed": 100,
"attacks": [
{ "damage": 12, "kb": 1, "accuracy": 80, "types": ["High"] }
],
"item": {
"pref_slot": "weapon"
},
"description": "A trusty pipe. Polaris really shouldn't leave these lying around."
}
}
}
2 changes: 1 addition & 1 deletion include/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/* Function Prototypes */
struct wfc_image parse_wfc_json(char *infile);
struct actor *actor_from_file(const char *);
void json_to_monster_list(const char *);
void json_to_actor_array(const char *, int *, struct actor **);
void json_to_item_list(const char *);

#endif
7 changes: 3 additions & 4 deletions include/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@
/* Func Proto */
void setup_term_dimensions(int, int, int, int);

#define MAX_MONSTERS 200
#define MAX_ITEMS 200
#define MAX_ACTORS 200 /* Ridin' High! Monsters and items are counted seperately. */

/* Persistent data which is saved and loaded. */
typedef struct global {
char userbuf[MAX_USERSZ];
struct tile levmap[MAPW][MAPH];
int heatmap[NUM_HEATMAPS][MAPW][MAPH];
struct actor *monsters[MAX_MONSTERS];
struct actor *items[MAX_ITEMS];
struct actor *monsters[MAX_ACTORS];
struct actor *items[MAX_ACTORS];
struct actor *player; /* Assume player is first NPC */
struct actor *target;
struct actor *active_attacker;
Expand Down
Loading

0 comments on commit 082c15e

Please sign in to comment.