aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacopo grandi <jak.sk8@hotmail.it>2021-02-19 19:24:22 +0100
committerjacopo grandi <jak.sk8@hotmail.it>2021-02-19 19:24:22 +0100
commitc135f85fcdc1eeedd04e0c9e9f626b907500f20a (patch)
tree942ed9fe531361c001da958860ce9d156a0a6876
parent5126638d46398579c26d3c7bd908fe17b8508b13 (diff)
stabilized levels
-rw-r--r--build/content/templates/default.txt78
-rw-r--r--build/test.exebin751250 -> 751762 bytes
-rw-r--r--gst/info.c60
-rw-r--r--hud/hud_views.c14
-rw-r--r--main.c2
5 files changed, 79 insertions, 75 deletions
diff --git a/build/content/templates/default.txt b/build/content/templates/default.txt
index 7ec433c..9b68936 100644
--- a/build/content/templates/default.txt
+++ b/build/content/templates/default.txt
@@ -1,72 +1,32 @@
[
{
"name": "tank",
- "chassis": "5",
- "brain": "1",
- "battery": "1",
- "weapons": [ 1, 1, 4, -1, -1, -1, -1, -1 ],
+ "chassis": "0",
+ "brain": "0",
+ "battery": "0",
+ "weapons": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
"armor": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
"augs": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
- "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
+ "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
},
{
"name": "tank2",
- "chassis": "14",
- "brain": "2",
- "battery": "2",
- "weapons": [ 1, 1, 4, -1, -1, -1, -1, -1 ],
- "armor": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
- "augs": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
- "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
- },
- {
- "name": "nameless",
- "chassis": "14",
- "brain": "5",
- "battery": "1",
- "weapons": [ 36, 12, 10, -1, -1, -1, -1, -1 ],
- "armor": [ 10, 7, 10, 4, 3, 4, -1, -1 ],
- "augs": [ 3, 4, 3, 2, 1, 3, -1, -1 ],
- "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
- },
- {
- "name": "nameless",
- "chassis": "13",
- "brain": "1",
- "battery": "4",
- "weapons": [ 3, 35, -1, -1, -1, -1, -1, -1 ],
- "armor": [ 3, 2, 1, 4, 4, -1, -1, -1 ],
- "augs": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
- "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
- },
- {
- "name": "nameless",
- "chassis": "3",
- "brain": "3",
- "battery": "3",
- "weapons": [ 2, 2, -1, -1, -1, -1, -1, -1 ],
- "armor": [ 9, -1, -1, -1, -1, -1, -1, -1 ],
- "augs": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
- "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
- },
- {
- "name": "nameless",
- "chassis": "11",
- "brain": "1",
- "battery": "1",
- "weapons": [ 0, -1, -1, -1, -1, -1, -1, -1 ],
- "armor": [ 9, -1, -1, -1, -1, -1, -1, -1 ],
- "augs": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
- "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
+ "chassis": "5",
+ "brain": "0",
+ "battery": "0",
+ "weapons": [ 0, 0, -1, -1, -1, -1, -1, -1 ],
+ "armor": [ 10, 0, 0, 0, -1, -1, -1, -1 ],
+ "augs": [ 0, 0, -1, -1, -1, -1, -1, -1 ],
+ "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
},
{
"name": "nameless",
- "chassis": "17",
- "brain": "0",
- "battery": "0",
- "weapons": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
- "armor": [ -1, -1, -1, -1, -1, -1, -1, -1 ],
- "augs": [ 16, -1, -1, -1, -1, -1, -1, -1 ],
- "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
+ "chassis": "9",
+ "brain": "2",
+ "battery": "2",
+ "weapons": [ 2, 1, -1, -1, -1, -1, -1, -1 ],
+ "armor": [ 0, 0, -1, -1, -1, -1, -1, -1 ],
+ "augs": [ 0, 0, 0, -1, -1, -1, -1, -1 ],
+ "levels": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
}
] \ No newline at end of file
diff --git a/build/test.exe b/build/test.exe
index 835c6e6..de1814f 100644
--- a/build/test.exe
+++ b/build/test.exe
Binary files differ
diff --git a/gst/info.c b/gst/info.c
index e442b2c..985b7dd 100644
--- a/gst/info.c
+++ b/gst/info.c
@@ -304,11 +304,12 @@ void info_unit_parse (char *json, info_unit *u, jsmntok_t *t, int r,
{
info_unit_init(u);
int obj_i = 0, dict_i = -1;
- for (int i=0; i<r; i+=2) {
+ for (int i=0; i<r; i+=1) {
if (t[i].type == JSMN_STRING) {
char key[32]; substr_token(json, key, t+i);
if (strcmp(key, "name") == 0) {
substr_token(json, u->name, t+i+1);
+ i++;
}
if (strcmp(key, "chassis") == 0) {
char val[32]; substr_token(json, val, t+i+1);
@@ -325,18 +326,22 @@ void info_unit_parse (char *json, info_unit *u, jsmntok_t *t, int r,
if (strcmp(key, "weapons") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, u->weapons, t+i+2, rt-1, 'c');
+ i++;
}
if (strcmp(key, "armor") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, u->armor, t+i+2, rt-1, 'c');
+ i++;
}
if (strcmp(key, "augs") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, u->augs, t+i+2, rt-1, 'c');
+ i++;
}
if (strcmp(key, "levels") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, u->levels, t+i+2, rt-1, 'c');
+ i++;
}
}
}
@@ -347,47 +352,57 @@ void info_weapon_parse (char *json, info_weapon *w, jsmntok_t *t, int r,
{
weapon_init(w);
int obj_i = 0, dict_i = -1;
- for (int i=0; i<r; i+=2) {
+ for (int i=0; i<r; i+=1) {
if (t[i].type == JSMN_STRING) {
char key[32]; substr_token(json, key, t+i);
if (strcmp(key, "name") == 0) {
substr_token(json, w->name, t+i+1);
+ i++;
}
if (strcmp(key, "damage_type") == 0) {
char val[32]; substr_token(json, val, t+i+1);
w->damage_type = damage_type_map(val);
+ i++;
}
if (strcmp(key, "weight") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, w->weight, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "cooldown") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, w->cooldown, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "damage") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, w->damage, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "range") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, w->range, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "aoe") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, w->aoe, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "knockback") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, w->knockback, t+i+2, rt-1, 'i');
+ i += rt;
}
if (strcmp(key, "damage_battery") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, w->damage_battery, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "stun") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, w->stun, t+i+2, rt-1, 'i');
+ i += rt;
}
for (int h=0; h<7; h++) {
char strkey[32]; sprintf(strkey, "reduce_%s",
@@ -395,12 +410,14 @@ void info_weapon_parse (char *json, info_weapon *w, jsmntok_t *t, int r,
if (strcmp(key, strkey) == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, w->reduce_armor[h], t+i+2, rt-1, 'f');
+ i += rt;
break;
}
}
if (strcmp(key, "upkeep") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, w->upkeep, t+i+2, rt-1, 'f');
+ i += rt;
}
}
}
@@ -411,39 +428,47 @@ void info_chassis_parse (char *json, info_chassis *c, jsmntok_t *t, int r,
{
chassis_init(c);
int obj_i = 0, dict_i = -1;
- for (int i=0; i<r; i+=2) {
+ for (int i=0; i<r; i+=1) {
if (t[i].type == JSMN_STRING) {
char key[32]; substr_token(json, key, t+i);
if (strcmp(key, "name") == 0) {
substr_token(json, c->name, t+i+1);
+ i++;
}
if (strcmp(key, "slot_weapon") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, c->slot_weapon, t+i+2, rt-1, 'i');
+ i += rt;
}
if (strcmp(key, "slot_armor") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, c->slot_armor, t+i+2, rt-1, 'i');
+ i += rt;
}
if (strcmp(key, "slot_aug") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, c->slot_aug, t+i+2, rt-1, 'i');
+ i += rt;
}
if (strcmp(key, "weight_max") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, c->weight_max, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "hp") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, c->hp, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "speed") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, c->speed, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "upkeep") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, c->upkeep, t+i+2, rt-1, 'f');
+ i += rt;
}
}
}
@@ -454,23 +479,27 @@ void info_battery_parse (char *json, info_battery *b, jsmntok_t *t, int r,
{
battery_init(b);
int obj_i = 0, dict_i = -1;
- for (int i=0; i<r; i+=2) {
+ for (int i=0; i<r; i+=1) {
if (t[i].type == JSMN_STRING) {
char key[32]; substr_token(json, key, t+i);
if (strcmp(key, "name") == 0) {
substr_token(json, b->name, t+i+1);
+ i++;
}
if (strcmp(key, "weight") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, b->weight, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "capacity") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, b->capacity, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "recharge") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, b->recharge, t+i+2, rt-1, 'i');
+ i += rt;
}
}
}
@@ -481,25 +510,29 @@ void info_armor_parse (char *json, info_armor *a, jsmntok_t *t, int r,
{
armor_init(a);
int obj_i = 0, dict_i = -1;
- for (int i=0; i<r; i+=2) {
+ for (int i=0; i<r; i+=1) {
if (t[i].type == JSMN_STRING) {
char key[32]; substr_token(json, key, t+i);
if (strcmp(key, "name") == 0) {
substr_token(json, a->name, t+i+1);
+ i++;
}
if (strcmp(key, "weight") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->weight, t+i+2, rt-1, 'f');
+ i += rt;
}
for (int h=0; h<7; h++) {
if (strcmp(key, info->damage_types[h]) == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->armor[h], t+i+2, rt-1, 'f');
+ i += rt;
}
}
if (strcmp(key, "upkeep") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->upkeep, t+i+2, rt-1, 'f');
+ i += rt;
}
}
}
@@ -510,15 +543,17 @@ void info_aug_parse (char *json, info_aug *a, jsmntok_t *t, int r,
{
aug_init(a);
int obj_i = 0, dict_i = -1;
- for (int i=0; i<r; i+=2) {
+ for (int i=0; i<r; i+=1) {
if (t[i].type == JSMN_STRING) {
char key[32]; substr_token(json, key, t+i);
if (strcmp(key, "name") == 0) {
substr_token(json, a->name, t+i+1);
+ i++;
}
if (strcmp(key, "weight") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->weight, t+i+2, rt-1, 'f');
+ i += rt;
}
for (int h=0; h<7; h++) {
char strkey[32]; sprintf(strkey, "damage_%s",
@@ -526,6 +561,7 @@ void info_aug_parse (char *json, info_aug *a, jsmntok_t *t, int r,
if (strcmp(key, strkey) == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->add_damage[h], t+i+2, rt-1, 'f');
+ i += rt;
break;
}
}
@@ -535,28 +571,34 @@ void info_aug_parse (char *json, info_aug *a, jsmntok_t *t, int r,
if (strcmp(key, strkey) == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->add_armor[h], t+i+2, rt-1, 'f');
+ i += rt;
break;
}
}
if (strcmp(key, "add_range") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->add_range, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "add_cooldown") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->add_cooldown, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "add_hp") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->add_hp, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "add_capacity") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->add_capacity, t+i+2, rt-1, 'f');
+ i += rt;
}
if (strcmp(key, "upkeep") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->upkeep, t+i+2, rt-1, 'f');
+ i += rt;
}
}
}
@@ -567,15 +609,17 @@ void info_brain_parse (char *json, info_brain *a, jsmntok_t *t, int r,
{
brain_init(a);
int obj_i = 0, dict_i = -1;
- for (int i=0; i<r; i+=2) {
+ for (int i=0; i<r; i+=1) {
if (t[i].type == JSMN_STRING) {
char key[32]; substr_token(json, key, t+i);
if (strcmp(key, "name") == 0) {
substr_token(json, a->name, t+i+1);
+ i++;
}
if (strcmp(key, "upkeep") == 0) {
int rt = json_parse_subtokens(json, t, r, i+1);
json_parse_array(json, a->upkeep, t+i+2, rt-1, 'f');
+ i += rt;
}
}
}
@@ -746,7 +790,7 @@ void info_dump_json_templates (infos *info, char *str) {
char w2[64]; json_dump_array(w2, u->augs, 8, 'c');
sprintf(str+len, " \"augs\": %s,\n", w2);
len = strlen(str);
- char w3[128]; json_dump_array(w3, u->levels, 34, 'c');
+ char w3[128]; json_dump_array(w3, u->levels, 35, 'c');
sprintf(str+len, " \"levels\": %s\n", w3);
len = strlen(str);
char comma = ','; if(i==info->templateslen-1) comma = ' ';
diff --git a/hud/hud_views.c b/hud/hud_views.c
index a7237e2..4828275 100644
--- a/hud/hud_views.c
+++ b/hud/hud_views.c
@@ -65,15 +65,15 @@ void render_view_chassis (SDL_Renderer* rend, txtd *t, int px, int py,
render_text_scaled(rend, sname, pname, t, 2);
float pweight[2] = { px+10, py+40 };
char sweight[64]; sprintf(sweight, "MAX WEIGHT: %0.0f",
- info->chassis[chassis].weight_max);
+ info->chassis[chassis].weight_max[lvl]);
render_text_scaled(rend, sweight, pweight, t, 1);
float php[2] = { px+10, py+55 };
char shp[64]; sprintf(shp, "HP: %0.1f",
- info->chassis[chassis].hp);
+ info->chassis[chassis].hp[lvl]);
render_text_scaled(rend, shp, php, t, 1);
float pspeed[2] = { px+10, py+70 };
char sspeed[64]; sprintf(sspeed, "SPEED: %0.2f tiles/turn",
- info->chassis[chassis].speed);
+ info->chassis[chassis].speed[lvl]);
render_text_scaled(rend, sspeed, pspeed, t, 1);
SDL_Rect srcRect = { chassis*32, 32, 32, 32 };
@@ -95,15 +95,15 @@ void render_view_battery (SDL_Renderer* rend, txtd *t, int px, int py,
render_text_scaled(rend, sname, pname, t, 1);
float pweight[2] = { px+10, py+40 };
char sweight[64]; sprintf(sweight, "WEIGHT: %0.0f",
- info->batteries[batt].weight);
+ info->batteries[batt].weight[lvl]);
render_text_scaled(rend, sweight, pweight, t, 1);
float pcapacity[2] = { px+10, py+55 };
char scapacity[64]; sprintf(scapacity, "CAPACITY: %0.1f",
- info->batteries[batt].capacity);
+ info->batteries[batt].capacity[lvl]);
render_text_scaled(rend, scapacity, pcapacity, t, 1);
float prech[2] = { px+10, py+70 };
char srech[64];
- if (info->batteries[batt].recharge == 0) {
+ if (info->batteries[batt].recharge[lvl] == 0) {
strcpy(srech, "NOT RECHARGEABLE");
} else {
strcpy(srech, "RECHARGEABLE");
@@ -376,6 +376,6 @@ void render_view_template (SDL_Renderer* rend, txtd *t, int px, int py,
float wplace = get_text_width("place", t);
float pname[2] = { wplace+wedit+4*4+10+px, py+4 };
- char *sname = info->chassis[info->templates[temp].chassis].name;
+ char *sname = info->templates[temp].name;
render_text_scaled(rend, sname, pname, t, 1);
} \ No newline at end of file
diff --git a/main.c b/main.c
index eb8e458..4c5c9b4 100644
--- a/main.c
+++ b/main.c
@@ -210,7 +210,7 @@ int main( int argc, char* args[] ) {
SDL_SetRenderDrawColor(rend, 255*sw, 255*(1-sw), 0, 255);
SDL_RenderFillRect(rend, &hprect);
- SDL_SetTextureColorMod(txsmall, 0, 100, 0);
+ SDL_SetTextureColorMod(txsmall, sw*100, 100*(1-sw), 0);
char shp[32]; sprintf(shp, "%.0f", ar->us[i].hp);
float php[2] = { (int)x-posx, (int)y-posy+ts-5 };
render_text_small(rend, shp, php, txsmall);