diff options
Diffstat (limited to 'gst')
-rw-r--r-- | gst/gst.c | 1 | ||||
-rw-r--r-- | gst/info.c | 487 | ||||
-rw-r--r-- | gst/info.h | 76 | ||||
-rw-r--r-- | gst/units.c | 21 | ||||
-rw-r--r-- | gst/units.h | 1 |
5 files changed, 343 insertions, 243 deletions
@@ -78,5 +78,6 @@ void gst_process (gamestate *gst, infos *info, float t) { gst_get_maparmy(gst, &m, &ar); army_move(info, ar, m); army_fire(info, ar, m); + army_upkeep(info, ar, m); } }
\ No newline at end of file @@ -42,72 +42,125 @@ void info_unit_init (info_unit *u) { for(int i=0; i<34; u->levels[i] = 0, i++); } +float info_unit_get_capacity(infos *info, info_unit *u) { + float sum = 0; + int lc = u->levels[LEVEL_CHASSIS]; + for(int i=0; i<16; i++) { + if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug[lc]) { + int lvl = u->levels[LEVEL_AUGS+i]; + sum += info->augs[u->augs[i]].add_capacity[lvl]; + } + } + int lvl = u->levels[LEVEL_BATTERY]; + sum += info->batteries[u->battery].capacity[lvl]; + return sum; +} + +float info_unit_get_upkeep(infos *info, info_unit *u) { + float sum = 0; + int lc = u->levels[LEVEL_CHASSIS]; + int lbr = u->levels[LEVEL_BRAIN]; + for(int i=0; i<8; i++) { + if (u->weapons[i] != -1 && info->chassis[u->chassis].slot_weapon[lc]) { + int lvl = u->levels[LEVEL_WEAPONS+i]; + sum += info->weapons[u->weapons[i]].upkeep[lvl]; + } + if (u->armor[i] != -1 && info->chassis[u->chassis].slot_armor[lc]) { + int lvl = u->levels[LEVEL_ARMOR+i]; + sum += info->armors[u->armor[i]].upkeep[lvl]; + } + } + for(int i=0; i<16; i++) { + if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug[lc]) { + int lvl = u->levels[LEVEL_AUGS+i]; + sum += info->augs[u->augs[i]].upkeep[lvl]; + } + } + sum += info->chassis[u->chassis].upkeep[lc]; + sum += info->brains[u->brain].upkeep[lbr]; + return sum; +} + float info_unit_get_weight (infos *info, info_unit *u) { float sum = 0; + int lc = u->levels[LEVEL_CHASSIS]; if (u->battery != -1) { - sum += info->batteries[u->battery].weight; + int lb = u->levels[LEVEL_BATTERY]; + sum += info->batteries[u->battery].weight[lb]; } for(int i=0; i<8; i++) { - if (u->weapons[i] != -1 && i<info->chassis[u->chassis].slot_weapon) { - sum += info->weapons[u->weapons[i]].weight; + if (u->weapons[i] != -1 && i<info->chassis[u->chassis].slot_weapon[lc]) { + int lvl = u->levels[LEVEL_WEAPONS+i]; + sum += info->weapons[u->weapons[i]].weight[lvl]; } - if (u->armor[i] != -1 && i<info->chassis[u->chassis].slot_armor) { - sum += info->armors[u->armor[i]].weight; + if (u->armor[i] != -1 && i<info->chassis[u->chassis].slot_armor[lc]) { + int lvl = u->levels[LEVEL_ARMOR+i]; + sum += info->armors[u->armor[i]].weight[lvl]; } } for(int i=0; i<16; i++) { if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug) { - sum += info->augs[u->augs[i]].weight; + int lvl = u->levels[LEVEL_AUGS+i]; + sum += info->augs[u->augs[i]].weight[lvl]; } } return sum; } float info_unit_get_dps (infos *info, info_unit *u) { + int lc = u->levels[LEVEL_CHASSIS]; float sum = 0; for(int i=0; i<8; i++) { - if (u->weapons[i] != -1 && i<info->chassis[u->chassis].slot_weapon) { + if (u->weapons[i] != -1 && i<info->chassis[u->chassis].slot_weapon[lc]) { info_weapon *w = info->weapons+u->weapons[i]; + int lw = u->levels[LEVEL_WEAPONS+i]; float damage = info_unit_get_damage(info, u, i); - sum += damage/w->cooldown; + sum += damage/w->cooldown[lw]; } } return sum; } float info_unit_get_health(infos *info, info_unit *u) { + int lc = u->levels[LEVEL_CHASSIS]; float sum = 0; for(int i=0; i<16; i++) { - if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug) { - sum += info->augs[u->augs[i]].add_hp; + if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug[lc]) { + int lvl = u->levels[LEVEL_AUGS+i]; + sum += info->augs[u->augs[i]].add_hp[lvl]; } } - sum += info->chassis[u->chassis].hp; + sum += info->chassis[u->chassis].hp[lc]; return sum; } float info_unit_get_speed(infos *info, info_unit *u) { + int lc = u->levels[LEVEL_CHASSIS]; float sum = 0; for(int i=0; i<16; i++) { - if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug) { - sum += info->augs[u->augs[i]].add_speed; + if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug[lc]) { + int lvl = u->levels[LEVEL_AUGS+i]; + sum += info->augs[u->augs[i]].add_speed[lvl]; } } - sum += info->chassis[u->chassis].speed; + sum += info->chassis[u->chassis].speed[lc]; return sum; } float info_unit_get_damage (infos *info, info_unit *u, int w) { + int lc = u->levels[LEVEL_CHASSIS]; int damage_type = info->weapons[u->weapons[w]].damage_type; float sum = 0; for(int i=0; i<16; i++) { - if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug) { - sum += info->augs[u->augs[i]].add_damage[damage_type]; + if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug[lc]) { + int lvl = u->levels[LEVEL_AUGS+i]; + sum += info->augs[u->augs[i]].add_damage[damage_type][lvl]; } } float mult = (1 + sum/100.0f); if (mult < 0) mult = 0; - float dam = info->weapons[u->weapons[w]].damage * mult; + int lw = u->levels[LEVEL_WEAPONS+w]; + float dam = info->weapons[u->weapons[w]].damage[lw] * mult; return dam; } @@ -123,37 +176,53 @@ float info_unit_get_damage_target (infos *info, info_unit *u, int w, } float info_unit_get_cooldown(infos *info, info_unit *u, int w) { + int lc = u->levels[LEVEL_CHASSIS]; float sum = 0; for(int i=0; i<16; i++) { - if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug) { - sum += info->augs[u->augs[i]].add_cooldown; + if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug[lc]) { + int lvl = u->levels[LEVEL_AUGS+i]; + sum += info->augs[u->augs[i]].add_cooldown[lvl]; } } - sum += info->weapons[u->weapons[w]].cooldown; + int lw = u->levels[LEVEL_WEAPONS+w]; + sum += info->weapons[u->weapons[w]].cooldown[lw]; return sum; } float info_unit_get_range(infos *info, info_unit *u, int w) { + int lc = u->levels[LEVEL_CHASSIS]; float sum = 0; for(int i=0; i<16; i++) { - if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug) { - sum += info->augs[u->augs[i]].add_range; + if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug[lc]) { + int lvl = u->levels[LEVEL_AUGS+i]; + sum += info->augs[u->augs[i]].add_range[lvl]; } } - sum += info->weapons[u->weapons[w]].range; + int lw = u->levels[LEVEL_WEAPONS+w]; + sum += info->weapons[u->weapons[w]].range[lw]; + return sum; +} + +float info_unit_get_charge_per_shot (infos *info, info_unit *u, int w) { + float sum = 0; + int lw = u->levels[LEVEL_WEAPONS+w]; + sum += info->weapons[u->weapons[w]].charge_per_shot[lw]; return sum; } float info_unit_get_armor(infos *info, info_unit *u, int d) { + int lc = u->levels[LEVEL_CHASSIS]; float sum = 0; for(int i=0; i<8; i++) { - if (u->armor[i] != -1 && i<info->chassis[u->chassis].slot_armor) { - sum += info->armors[u->armor[i]].armor[d]; + if (u->armor[i] != -1 && i<info->chassis[u->chassis].slot_armor[lc]) { + int lvl = u->levels[LEVEL_ARMOR+i]; + sum += info->armors[u->armor[i]].armor[d][lvl]; } } for(int i=0; i<16; i++) { - if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug) { - sum += info->augs[u->augs[i]].add_armor[d]; + if (u->augs[i] != -1 && info->chassis[u->chassis].slot_aug[lc]) { + int lvl = u->levels[LEVEL_AUGS+i]; + sum += info->augs[u->augs[i]].add_armor[d][lvl]; } } return sum; @@ -162,47 +231,77 @@ float info_unit_get_armor(infos *info, info_unit *u, int d) { void weapon_init (info_weapon *w) { strcpy(w->name, "nameless"); - w->damage_type = 0; - w->weight = 0; w->cooldown = 1; - w->damage = 0; w->range = 0; w->aoe = 0; - w->knockback = 0; w->stun = 0; - for (int i=0; i<7; i++) { w->reduce_armor[i]=0; } + for (int l=0; l<MAXLEVEL; l++) { + w->damage_type = 0; + w->weight[l] = 0; + w->cooldown[l] = 1; + w->damage[l] = 0; + w->range[l] = 0; + w->aoe[l] = 0; + w->knockback[l] = 0; + w->stun[l] = 0; + for (int i=0; i<7; i++) { w->reduce_armor[i][l]=0; } + w->upkeep[l] = 0; + w->charge_per_shot[l] = 0; + } } void chassis_init (info_chassis *c) { strcpy(c->name, "nameless"); - c->slot_weapon = 0; c->slot_armor = 0; c->slot_aug = 0; - c->weight_max = 0; c->hp = 0; + for (int l=0; l<MAXLEVEL; l++) { + c->slot_weapon[l] = 0; + c->slot_armor[l] = 0; + c->slot_aug[l] = 0; + c->weight_max[l] = 0; + c->hp[l] = 0; + c->upkeep[l] = 0; + } } void battery_init (info_battery *b) { strcpy(b->name, "nameless"); - b->weight = 0; b->capacity = 0; b->recharge = 0; + for (int l=0; l<MAXLEVEL; l++) { + b->weight[l] = 0; + b->capacity[l] = 0; + b->recharge[l] = 0; + } } void armor_init (info_armor *a) { strcpy(a->name, "nameless"); - a->weight = 0; - for (int i=0; i<7; i++) { a->armor[i]=0; } + for (int l=0; l<MAXLEVEL; l++) { + a->weight[l] = 0; + for (int i=0; i<7; i++) { a->armor[i][l]=0; } + a->upkeep[l] = 0; + } } void aug_init (info_aug *a) { strcpy(a->name, "nameless"); - a->weight = 0; - for (int i=0; i<7; i++) { a->add_damage[i]=0; } - for (int i=0; i<7; i++) { a->add_armor[i]=0; } - a->add_range = 0; - a->add_cooldown = 0; - a->add_speed = 0; - a->add_hp = 0; + for (int l=0; l<MAXLEVEL; l++) { + a->weight[l] = 0; + for (int i=0; i<7; i++) { a->add_damage[i][l]=0; } + for (int i=0; i<7; i++) { a->add_armor[i][l]=0; } + a->add_range[l] = 0; + a->add_cooldown [l]= 0; + a->add_speed[l] = 0; + a->add_hp[l] = 0; + a->add_capacity[l] = 0; + a->upkeep[l] = 0; + } } void brain_init (info_brain *a) { strcpy(a->name, "nameless"); + for (int l=0; l<MAXLEVEL; l++) { + a->upkeep[l] = 0; + } } -void info_unit_parse (char *json, info_unit *u, jsmntok_t *t, int r) { +void info_unit_parse (char *json, info_unit *u, jsmntok_t *t, int r, + infos *info) +{ info_unit_init(u); int obj_i = 0, dict_i = -1; for (int i=0; i<r; i+=2) { @@ -243,7 +342,9 @@ void info_unit_parse (char *json, info_unit *u, jsmntok_t *t, int r) { } } -void info_weapon_parse (char *json, info_weapon *w, jsmntok_t *t, int r) { +void info_weapon_parse (char *json, info_weapon *w, jsmntok_t *t, int r, + infos *info) +{ weapon_init(w); int obj_i = 0, dict_i = -1; for (int i=0; i<r; i+=2) { @@ -257,70 +358,57 @@ void info_weapon_parse (char *json, info_weapon *w, jsmntok_t *t, int r) { w->damage_type = damage_type_map(val); } if (strcmp(key, "weight") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->weight = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, w->weight, t+i+2, rt-1, 'f'); } if (strcmp(key, "cooldown") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->cooldown = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, w->cooldown, t+i+2, rt-1, 'f'); } if (strcmp(key, "damage") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->damage = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, w->damage, t+i+2, rt-1, 'f'); } if (strcmp(key, "range") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->range = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, w->range, t+i+2, rt-1, 'f'); } if (strcmp(key, "aoe") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->aoe = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, w->aoe, t+i+2, rt-1, 'f'); } if (strcmp(key, "knockback") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->knockback = atoi(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, w->knockback, t+i+2, rt-1, 'i'); } if (strcmp(key, "damage_battery") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->damage_battery = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, w->damage_battery, t+i+2, rt-1, 'f'); } if (strcmp(key, "stun") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->stun = atoi(val); - } - if (strcmp(key, "reduce_pierce") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->reduce_armor[0] = atof(val); - } - if (strcmp(key, "reduce_laser") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->reduce_armor[1] = atof(val); - } - if (strcmp(key, "reduce_impact") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->reduce_armor[2] = atof(val); - } - if (strcmp(key, "reduce_fusion") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->reduce_armor[3] = atof(val); - } - if (strcmp(key, "reduce_explosive") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->reduce_armor[4] = atof(val); - } - if (strcmp(key, "reduce_emp") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->reduce_armor[5] = atof(val); - } - if (strcmp(key, "reduce_spread") == 0) { - char val[32]; substr_token(json, val, t+i+1); - w->reduce_armor[6] = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, w->stun, t+i+2, rt-1, 'i'); + } + for (int h=0; h<7; h++) { + char strkey[32]; sprintf(strkey, "reduce_%s", + info->damage_types[h]); + 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'); + 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'); } } } } -void info_chassis_parse (char *json, info_chassis *c, jsmntok_t *t, int r) { +void info_chassis_parse (char *json, info_chassis *c, jsmntok_t *t, int r, + infos *info) +{ chassis_init(c); int obj_i = 0, dict_i = -1; for (int i=0; i<r; i+=2) { @@ -330,34 +418,40 @@ void info_chassis_parse (char *json, info_chassis *c, jsmntok_t *t, int r) { substr_token(json, c->name, t+i+1); } if (strcmp(key, "slot_weapon") == 0) { - char val[32]; substr_token(json, val, t+i+1); - c->slot_weapon = atoi(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, c->slot_weapon, t+i+2, rt-1, 'i'); } if (strcmp(key, "slot_armor") == 0) { - char val[32]; substr_token(json, val, t+i+1); - c->slot_armor = atoi(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, c->slot_armor, t+i+2, rt-1, 'i'); } if (strcmp(key, "slot_aug") == 0) { - char val[32]; substr_token(json, val, t+i+1); - c->slot_aug = atoi(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, c->slot_aug, t+i+2, rt-1, 'i'); } if (strcmp(key, "weight_max") == 0) { - char val[32]; substr_token(json, val, t+i+1); - c->weight_max = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, c->weight_max, t+i+2, rt-1, 'f'); } if (strcmp(key, "hp") == 0) { - char val[32]; substr_token(json, val, t+i+1); - c->hp = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, c->hp, t+i+2, rt-1, 'f'); } if (strcmp(key, "speed") == 0) { - char val[32]; substr_token(json, val, t+i+1); - c->speed = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, c->speed, t+i+2, rt-1, 'f'); + } + 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'); } } } } -void info_battery_parse (char *json, info_battery *b, jsmntok_t *t, int r) { +void info_battery_parse (char *json, info_battery *b, jsmntok_t *t, int r, + infos *info) +{ battery_init(b); int obj_i = 0, dict_i = -1; for (int i=0; i<r; i+=2) { @@ -367,22 +461,24 @@ void info_battery_parse (char *json, info_battery *b, jsmntok_t *t, int r) { substr_token(json, b->name, t+i+1); } if (strcmp(key, "weight") == 0) { - char val[32]; substr_token(json, val, t+i+1); - b->weight = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, b->weight, t+i+2, rt-1, 'f'); } if (strcmp(key, "capacity") == 0) { - char val[32]; substr_token(json, val, t+i+1); - b->capacity = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, b->capacity, t+i+2, rt-1, 'f'); } if (strcmp(key, "recharge") == 0) { - char val[32]; substr_token(json, val, t+i+1); - b->recharge = atoi(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, b->recharge, t+i+2, rt-1, 'i'); } } } } -void info_armor_parse (char *json, info_armor *a, jsmntok_t *t, int r) { +void info_armor_parse (char *json, info_armor *a, jsmntok_t *t, int r, + infos *info) +{ armor_init(a); int obj_i = 0, dict_i = -1; for (int i=0; i<r; i+=2) { @@ -392,42 +488,26 @@ void info_armor_parse (char *json, info_armor *a, jsmntok_t *t, int r) { substr_token(json, a->name, t+i+1); } if (strcmp(key, "weight") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->weight = atof(val); - } - if (strcmp(key, "pierce") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->armor[0] = atof(val); - } - if (strcmp(key, "laser") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->armor[1] = atof(val); - } - if (strcmp(key, "impact") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->armor[2] = atof(val); - } - if (strcmp(key, "fusion") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->armor[3] = atof(val); - } - if (strcmp(key, "explosive") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->armor[4] = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, a->weight, t+i+2, rt-1, 'f'); } - if (strcmp(key, "emp") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->armor[5] = atof(val); + 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'); + } } - if (strcmp(key, "spread") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->armor[6] = atof(val); + 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'); } } } } -void info_aug_parse (char *json, info_aug *a, jsmntok_t *t, int r) { +void info_aug_parse (char *json, info_aug *a, jsmntok_t *t, int r, + infos *info) +{ aug_init(a); int obj_i = 0, dict_i = -1; for (int i=0; i<r; i+=2) { @@ -437,82 +517,54 @@ void info_aug_parse (char *json, info_aug *a, jsmntok_t *t, int r) { substr_token(json, a->name, t+i+1); } if (strcmp(key, "weight") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->weight = atof(val); - } - if (strcmp(key, "damage_pierce") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_damage[0] = atof(val); - } - if (strcmp(key, "damage_laser") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_damage[1] = atof(val); - } - if (strcmp(key, "damage_impact") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_damage[2] = atof(val); - } - if (strcmp(key, "damage_fusion") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_damage[3] = atof(val); - } - if (strcmp(key, "damage_explosive") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_damage[4] = atof(val); - } - if (strcmp(key, "damage_emp") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_damage[5] = atof(val); - } - if (strcmp(key, "add_spread") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_damage[6] = atof(val); - } - if (strcmp(key, "armor_pierce") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_armor[0] = atof(val); - } - if (strcmp(key, "armor_laser") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_armor[1] = atof(val); - } - if (strcmp(key, "armor_impact") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_armor[2] = atof(val); - } - if (strcmp(key, "armor_fusion") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_armor[3] = atof(val); - } - if (strcmp(key, "armor_explosive") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_armor[4] = atof(val); - } - if (strcmp(key, "armor_emp") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_armor[5] = atof(val); - } - if (strcmp(key, "armor_spread") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_armor[6] = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, a->weight, t+i+2, rt-1, 'f'); + } + for (int h=0; h<7; h++) { + char strkey[32]; sprintf(strkey, "damage_%s", + info->damage_types[h]); + 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'); + break; + } + } + for (int h=0; h<7; h++) { + char strkey[32]; sprintf(strkey, "armor_%s", + info->damage_types[h]); + 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'); + break; + } } if (strcmp(key, "add_range") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_range = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, a->add_range, t+i+2, rt-1, 'f'); } if (strcmp(key, "add_cooldown") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_cooldown = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, a->add_cooldown, t+i+2, rt-1, 'f'); } if (strcmp(key, "add_hp") == 0) { - char val[32]; substr_token(json, val, t+i+1); - a->add_hp = atof(val); + int rt = json_parse_subtokens(json, t, r, i+1); + json_parse_array(json, a->add_hp, t+i+2, rt-1, 'f'); + } + 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'); + } + 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'); } } } } -void info_brain_parse (char *json, info_brain *a, jsmntok_t *t, int r) { +void info_brain_parse (char *json, info_brain *a, jsmntok_t *t, int r, + infos *info) +{ brain_init(a); int obj_i = 0, dict_i = -1; for (int i=0; i<r; i+=2) { @@ -521,6 +573,10 @@ void info_brain_parse (char *json, info_brain *a, jsmntok_t *t, int r) { if (strcmp(key, "name") == 0) { substr_token(json, a->name, t+i+1); } + 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'); + } } } } @@ -534,31 +590,38 @@ void info_parse_json (infos *info, char *json, char *obj) { if (t[i].type == JSMN_OBJECT) { int rt = json_parse_subtokens(json, t, r, i); if (strcmp(obj, "template") == 0) { - info_unit_parse(json, info->templates+index, t+i+1, rt); + info_unit_parse(json, + info->templates+index, t+i+1, rt, info); info->templateslen = index+1; } if (strcmp(obj, "weapon") == 0) { - info_weapon_parse(json, info->weapons+index, t+i+1, rt); + info_weapon_parse(json, + info->weapons+index, t+i+1, rt, info); info->weaponslen = index+1; } if (strcmp(obj, "chassis") == 0) { - info_chassis_parse(json, info->chassis+index, t+i+1, rt); + info_chassis_parse(json, + info->chassis+index, t+i+1, rt, info); info->chassislen = index+1; } if (strcmp(obj, "battery") == 0) { - info_battery_parse(json, info->batteries+index, t+i+1, rt); + info_battery_parse(json, + info->batteries+index, t+i+1, rt, info); info->batterieslen = index+1; } if (strcmp(obj, "armor") == 0) { - info_armor_parse(json, info->armors+index, t+i+1, rt); + info_armor_parse(json, + info->armors+index, t+i+1, rt, info); info->armorslen = index+1; } if (strcmp(obj, "aug") == 0) { - info_aug_parse(json, info->augs+index, t+i+1, rt); + info_aug_parse(json, + info->augs+index, t+i+1, rt, info); info->augslen = index+1; } if (strcmp(obj, "brain") == 0) { - info_brain_parse(json, info->brains+index, t+i+1, rt); + info_brain_parse(json, + info->brains+index, t+i+1, rt, info); info->brainslen = index+1; } index ++; @@ -2,71 +2,86 @@ #define INFO_H #define MAXTEMPLATES 128 +#define MAXLEVEL 3 #include <stdint.h> +#define LEVEL_CHASSIS 0 +#define LEVEL_BRAIN 1 +#define LEVEL_BATTERY 2 +#define LEVEL_WEAPONS 3 +#define LEVEL_ARMOR 11 +#define LEVEL_AUGS 19 + typedef struct { char name[32]; // indexes of info.* int8_t chassis; int8_t brain; + int8_t battery; int8_t weapons[8]; int8_t armor[8]; int8_t augs[16]; - int8_t battery; - int8_t levels[34]; + int8_t levels[35]; } info_unit; typedef struct { char name[32]; int damage_type; - float weight; - float cooldown; - float damage; - float range; - float aoe; - int knockback; - float damage_battery; - int stun; - float reduce_armor[7]; + float weight[MAXLEVEL]; + float cooldown[MAXLEVEL]; + float damage[MAXLEVEL]; + float range[MAXLEVEL]; + float aoe[MAXLEVEL]; + int knockback[MAXLEVEL]; + float damage_battery[MAXLEVEL]; + int stun[MAXLEVEL]; + float reduce_armor[7][MAXLEVEL]; + float upkeep[MAXLEVEL]; + float charge_per_shot[MAXLEVEL]; } info_weapon; typedef struct { char name[32]; - int slot_weapon; - int slot_armor; - int slot_aug; - float weight_max; - float hp; - float speed; + int slot_weapon[MAXLEVEL]; + int slot_armor[MAXLEVEL]; + int slot_aug[MAXLEVEL]; + float weight_max[MAXLEVEL]; + float hp[MAXLEVEL]; + float speed[MAXLEVEL]; + float upkeep[MAXLEVEL]; } info_chassis; typedef struct { char name[32]; - float weight; - float capacity; - int recharge; + float weight[MAXLEVEL]; + float capacity[MAXLEVEL]; + int recharge[MAXLEVEL]; } info_battery; typedef struct { char name[32]; - float weight; - float armor[7]; + float weight[MAXLEVEL]; + float armor[7][MAXLEVEL]; + float upkeep[MAXLEVEL]; } info_armor; typedef struct { char name[32]; - float weight; - float add_damage[7]; - float add_armor[7]; - float add_range; - float add_cooldown; - float add_speed; - float add_hp; + float weight[MAXLEVEL]; + float add_damage[7][MAXLEVEL]; + float add_armor[7][MAXLEVEL]; + float add_range[MAXLEVEL]; + float add_cooldown[MAXLEVEL]; + float add_speed[MAXLEVEL]; + float add_hp[MAXLEVEL]; + float add_capacity[MAXLEVEL]; + float upkeep[MAXLEVEL]; } info_aug; typedef struct { char name[32]; + float upkeep[MAXLEVEL]; } info_brain; typedef struct { @@ -88,11 +103,14 @@ typedef struct { } infos; void info_unit_init (info_unit *u); +float info_unit_get_capacity (infos *info, info_unit *u); +float info_unit_get_upkeep (infos *info, info_unit *u); float info_unit_get_weight (infos *info, info_unit *u); float info_unit_get_dps (infos *info, info_unit *u); float info_unit_get_health(infos *info, info_unit *u); float info_unit_get_speed(infos *info, info_unit *u); float info_unit_get_damage(infos *info, info_unit *u, int w); +float info_unit_get_charge_per_shot(infos *info, info_unit *u, int w); float info_unit_get_damage_target(infos *info, info_unit *u, int w, info_unit *t); float info_unit_get_cooldown(infos *info, info_unit *u, int w); diff --git a/gst/units.c b/gst/units.c index 72089f2..dbf177b 100644 --- a/gst/units.c +++ b/gst/units.c @@ -36,6 +36,7 @@ void unit_init (infos *info, army *ar, map *m, u->owner = owner; u->hp = info_unit_get_health(info, iu); u->move_points = 0; + u->charge = info_unit_get_capacity(info, iu); for (int i=0; i<8; u->cooldown[i] = 1, i++); } @@ -113,6 +114,7 @@ int army_move_step (infos *info, army *ar, map *m) { unit *u = ar->us+i; if (u->move_points <= 0) continue; if (u->hp <= 0) continue; + if (u->charge <= 0) continue; // search target unit *t[32]; unit_search(info, ar, m, u, t, 100); @@ -180,7 +182,8 @@ void army_move (infos *info, army *ar, map *m) { void army_fire (infos *info, army *ar, map *m) { for (int i=0; i<ar->uslen; i++) { unit *u = ar->us+i; - for (int j=0; j<info->chassis[u->info.chassis].slot_weapon; j++) { + int lw = u->info.levels[LEVEL_CHASSIS]; + for (int j=0; j<info->chassis[u->info.chassis].slot_weapon[lw]; j++) { u->cooldown[j] += 1; } } @@ -189,7 +192,9 @@ void army_fire (infos *info, army *ar, map *m) { for (int i=0; i<ar->uslen; i++) { unit *u = ar->us+i; if (u->hp <= 0) continue; - for (int j=0; j<info->chassis[u->info.chassis].slot_weapon; j++) { + if (u->charge <= 0) continue; + int lw = u->info.levels[LEVEL_CHASSIS]; + for (int j=0; j<info->chassis[u->info.chassis].slot_weapon[lw]; j++) { if (u->info.weapons[j] == -1) continue; if (u->cooldown[j] <= 0) continue; float range = info_unit_get_range(info, &u->info, j); @@ -200,6 +205,8 @@ void army_fire (infos *info, army *ar, map *m) { info, &u->info, j, &t[0]->info); dmgslen++; u->cooldown[j] -= info_unit_get_cooldown(info, &u->info, j); + u->charge -= info_unit_get_charge_per_shot(info, &u->info, j); + if (u->charge < 0) u->charge = 0; } } } @@ -209,4 +216,14 @@ void army_fire (infos *info, army *ar, map *m) { unit_dead(ar, m, dmgs[i].u); } } +} + +void army_upkeep (infos *info, army *ar, map *m) { + // battery drain or recharge + for (int i=0; i<ar->uslen; i++) { + unit *u = ar->us+i; + if (u->hp <= 0) continue; + u->charge -= info_unit_get_upkeep(info, &u->info); + if (u->charge < 0) u->charge = 0; + } }
\ No newline at end of file diff --git a/gst/units.h b/gst/units.h index 86f7fd7..615eaa7 100644 --- a/gst/units.h +++ b/gst/units.h @@ -36,5 +36,6 @@ void army_destory(army *ar); void army_spawn (army *ar, map *m, unit u); void army_move (infos *info, army *ar, map *m); void army_fire (infos *info, army *ar, map *m); +void army_upkeep (infos *info, army *ar, map *m); #endif
\ No newline at end of file |