Skip to content

Commit

Permalink
Split actor data into multiple json files.
Browse files Browse the repository at this point in the history
This has several advantages. First, it's much easier to find individual
monsters when they're organized into subcategories than it is when they
all live in one massive unorganized file. Second, adding appearance
randomization is going to be a snap under this new method. Third,
modding support is going to be much easier to achieve in the future.
  • Loading branch information
Kestrel Gregorich-Trevor committed Jan 18, 2024
1 parent f5563cd commit 0dffa1a
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 121 deletions.
58 changes: 58 additions & 0 deletions data/creature/boxers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"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 }
}
}
18 changes: 18 additions & 0 deletions data/creature/characters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"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" : {}
}
}
112 changes: 0 additions & 112 deletions data/creature/creatures.json

This file was deleted.

15 changes: 15 additions & 0 deletions data/creature/debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"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 }
}
}
18 changes: 18 additions & 0 deletions data/creature/employees.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"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": {}
}
}
2 changes: 2 additions & 0 deletions data/item/weapons.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"knife": {
"name": "combat knife",
"lv": 0,
"appearance": "knife",
"chr": "/",
"color": "white",
Expand All @@ -16,6 +17,7 @@
},
"pipe": {
"name": "lead pipe",
"lv": 0,
"appearance": "pipe",
"chr": "/",
"color": "cyan",
Expand Down
2 changes: 1 addition & 1 deletion include/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct actor {
int id, chr;
unsigned char color;
/* Mutable attributes */
unsigned char x, y;
unsigned char x, y, lv;
int energy;
int hp, hpmax;
int speed; /* For creatures, denotes move speed. For items, attack speed. */
Expand Down
5 changes: 4 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ void handle_sigsegv(int sig) {
*
*/
void new_game(void) {
json_to_monster_list("data/creature/creatures.json");
json_to_monster_list("data/creature/characters.json");
json_to_monster_list("data/creature/boxers.json");
json_to_monster_list("data/creature/employees.json");
json_to_monster_list("data/creature/debug.json");
json_to_item_list("data/item/weapons.json");
if (g.practice || g.debug) {
logm("The high score list is disabled due to the game mode.");
Expand Down
11 changes: 4 additions & 7 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ struct actor *actor_from_json(cJSON *actor_json) {
*actor = (struct actor) { 0 };

/* Parse Fields */
field = cJSON_GetObjectItemCaseSensitive(actor_json, "lv");
actor->lv = field->valueint;
actor_primitives_from_json(actor, actor_json);
field = cJSON_GetObjectItemCaseSensitive(actor_json, "attacks");
attacks_from_json(actor, field);
field = cJSON_GetObjectItemCaseSensitive(actor_json, "color");
color_from_json(&(actor->color), field);

/* Parse Components */
field = cJSON_GetObjectItemCaseSensitive(actor_json, "ai");
if (field) {
Expand Down Expand Up @@ -123,7 +124,6 @@ struct actor *actor_from_json(cJSON *actor_json) {

void json_to_monster_list(const char *fname) {
// comb through every file in the folder via looking through the master file
int i = 0;
cJSON *all_json = json_from_file(fname);
cJSON *actor_json;
struct actor *new_actor;
Expand All @@ -141,16 +141,14 @@ void json_to_monster_list(const char *fname) {
}
new_actor = actor_from_json(actor_json);
new_actor->id = g.total_monsters;
g.monsters[i] = new_actor;
i++;
g.monsters[g.total_monsters] = new_actor;
g.total_monsters++;
}
//cJSON_Delete(all_json);
cJSON_Delete(actor_json);
}

void json_to_item_list(const char *fname) {
int i = 0;
cJSON *all_json = json_from_file(fname);
cJSON *actor_json;
struct actor *new_actor;
Expand All @@ -168,8 +166,7 @@ void json_to_item_list(const char *fname) {
}
new_actor = actor_from_json(actor_json);
new_actor->id = g.total_items;
g.items[i] = new_actor;
i++;
g.items[g.total_items] = new_actor;
g.total_items++;
}
//cJSON_Delete(all_json);
Expand Down

0 comments on commit 0dffa1a

Please sign in to comment.