/** * Add power for +to_ac */ static int to_ac_power(const object_type *obj, int p) { int q; if (obj->to_a == 0) return p; q = (obj->to_a * TO_AC_POWER / 2); p += q; log_obj(format("Add %d power for to_ac of %d, total is %d\n", q, obj->to_a, p)); if (obj->to_a > HIGH_TO_AC) { q = ((obj->to_a - (HIGH_TO_AC - 1)) * TO_AC_POWER); p += q; log_obj(format("Add %d power for high to_ac, total is %d\n", q, p)); } if (obj->to_a > VERYHIGH_TO_AC) { q = ((obj->to_a - (VERYHIGH_TO_AC -1)) * TO_AC_POWER * 2); p += q; log_obj(format("Add %d power for very high to_ac, total is %d\n",q, p)); } if (obj->to_a >= INHIBIT_AC) { p += INHIBIT_POWER; log_obj("INHIBITING: AC bonus too high\n"); } return p; }
/** * Add power for modifiers */ static int modifier_power(const object_type *obj, int p, bool known) { int i, k = 1, extra_stat_bonus = 0, q; for (i = 0; i < OBJ_MOD_MAX; i++) { if (known || object_this_mod_is_visible(obj, i)) { k = obj->modifiers[i]; extra_stat_bonus += (k * mod_mult(i)); } else continue; if (mod_power(i)) { q = (k * mod_power(i) * mod_slot_mult(i, wield_slot(obj))); p += q; if (q) log_obj(format("Add %d power for %d %s, total is %d\n", q, k, mod_name(i), p)); } } /* Add extra power term if there are a lot of ability bonuses */ if (extra_stat_bonus > 249) { log_obj(format("Inhibiting - Total ability bonus of %d is too high\n", extra_stat_bonus)); p += INHIBIT_POWER; } else if (extra_stat_bonus > 0) { q = ability_power[extra_stat_bonus / 10]; if (!q) return p; p += q; log_obj(format("Add %d power for modifier total of %d, total is %d\n", q, extra_stat_bonus, p)); } return p; }
/** * Add power for base AC and adjust for weight */ static int ac_power(const object_type *obj, int p) { int q = 0; if (obj->ac) { p += BASE_ARMOUR_POWER; q += (obj->ac * BASE_AC_POWER / 2); log_obj(format("Adding %d power for base AC value\n", q)); /* Add power for AC per unit weight */ if (obj->weight > 0) { int i = 750 * (obj->ac + obj->to_a) / obj->weight; /* Avoid overpricing Elven Cloaks */ if (i > 450) i = 450; q *= i; q /= 100; /* Weightless (ethereal) armour items get fixed boost */ } else q *= 5; p += q; log_obj(format("Add %d power for AC per unit weight, now %d\n", q, p)); } return p; }
/** * Add power for non-derived flags (derived flags have flag_power 0) */ static int flags_power(const object_type *obj, int p, int verbose, ang_file *log_file, bool known) { size_t i, j; int q; bitflag flags[OF_SIZE]; /* Extract the flags */ if (known) object_flags(obj, flags); else object_flags_known(obj, flags); /* Log the flags in human-readable form */ if (verbose) log_flags(flags, log_file); /* Zero the flag counts */ for (i = 0; i < N_ELEMENTS(flag_sets); i++) flag_sets[i].count = 0; for (i = of_next(flags, FLAG_START); i != FLAG_END; i = of_next(flags, i + 1)) { if (flag_power(i)) { q = (flag_power(i) * flag_slot_mult(i, wield_slot(obj))); p += q; log_obj(format("Add %d power for %s, total is %d\n", q, flag_name(i), p)); } /* Track combinations of flag types */ for (j = 0; j < N_ELEMENTS(flag_sets); j++) if (flag_sets[j].type == obj_flag_type(i)) flag_sets[j].count++; } /* Add extra power for multiple flags of the same type */ for (i = 0; i < N_ELEMENTS(flag_sets); i++) { if (flag_sets[i].count > 1) { q = (flag_sets[i].factor * flag_sets[i].count * flag_sets[i].count); p += q; log_obj(format("Add %d power for multiple %s, total is %d\n", q, flag_sets[i].desc, p)); } /* Add bonus if item has a full set of these flags */ if (flag_sets[i].count == flag_sets[i].size) { q = flag_sets[i].bonus; p += q; log_obj(format("Add %d power for full set of %s, total is %d\n", q, flag_sets[i].desc, p)); } } return p; }
/** * Evaluate the object's overall power level. */ s32b object_power(const object_type* obj, int verbose, ang_file *log_file, bool known) { s32b p = 0, dice_pwr = 0; int mult = 1; /* Set the log file */ object_log = log_file; /* Known status */ if (known) log_obj("Object is deemed known\n"); else log_obj("Object may not be fully known\n"); /* Get all the attack power */ p = to_damage_power(obj); dice_pwr = damage_dice_power(obj); p += dice_pwr; if (dice_pwr) log_obj(format("total is %d\n", p)); p += ammo_damage_power(obj, p); mult = bow_multiplier(obj); p = launcher_ammo_damage_power(obj, p); p = extra_blows_power(obj, p, known); if (p > INHIBIT_POWER) return p; p = extra_shots_power(obj, p, known); if (p > INHIBIT_POWER) return p; p = extra_might_power(obj, p, mult, known); if (p > INHIBIT_POWER) return p; p = slay_power(obj, p, verbose, dice_pwr, known); p = rescale_bow_power(obj, p); p = to_hit_power(obj, p); /* Armour class power */ p = ac_power(obj, p); p = to_ac_power(obj, p); /* Bonus for jewelry */ p = jewelry_power(obj, p); /* Other object properties */ p = modifier_power(obj, p, known); p = flags_power(obj, p, verbose, object_log, known); p = element_power(obj, p, known); p = effects_power(obj, p, known); log_obj(format("FINAL POWER IS %d\n", p)); return p; }
int main(int argc, char** argv) { const std::string conf_file("../test/slave.conf"); confreader conf(conf_file); logging log_obj(conf.get(std::string("log"))); log_obj.write("SLAVE: starting slave"); const std::string listen_host = conf.get(std::string("host")); log_obj.write("SLAVE: listen_host", listen_host); const std::string listen_port = conf.get(std::string("port")); log_obj.write("SLAVE: listen_port", listen_port); const std::string docker_port = conf.get(std::string("docker_port")); log_obj.write("SLAVE: docker_port", docker_port); const std::string docker_host = conf.get(std::string("docker_host")); log_obj.write("SLAVE: docker_host", docker_host); container container_server(docker_host, docker_port); while (true) { tcpserver server(listen_host, listen_port); log_obj.write("SLAVE: listening"); std::string s = server.read_string(); log_obj.write("SLAVE: master connected"); json json_object(s); auto json_map = json_object.get_map(); // std::string action = json_map["action"]; std::string action = json_map["action"]; log_obj.write("SLAVE: action", action); if (action == "run_container") { log_obj.write("SLAVE: run_container"); std::string container_image = json_map["image"]; log_obj.write("SLAVE: image:", container_image); std::string container_command = json_map["command"]; log_obj.write("SLAVE: command:", container_command); std::string container_id = container_server.run_container(container_image, container_command); log_obj.write("SLAVE: container_id", container_id); server.write_string(container_id); } else if (action == "get_containers") { log_obj.write("SLAVE: get_containers"); auto containers_list = container_server.get_containers(); json json_containers_list(containers_list); auto containers_list_str = json_containers_list.get_string_from_list(); log_obj.write(containers_list_str); server.write_string(containers_list_str); } else if (action == "destroy_container") { log_obj.write("SLAVE: destroy container"); auto container_id = json_map["id"]; auto container_destroy_answer = container_server.destroy_container(container_id); log_obj.write(container_destroy_answer); server.write_string(container_destroy_answer); } else if (action == "stop") { log_obj.write("SLAVE: stop"); server.write_string("OK"); break; } else { server.write_string("NONONONO"); log_obj.write("SLAVE: received: ", s); } } log_obj.write("exiting"); return 0; }
/** * Melee weapons assume MAX_BLOWS per turn, so we must divide by MAX_BLOWS * to get equal ratings for launchers. */ static int rescale_bow_power(const object_type *obj, int p) { if (wield_slot(obj) == slot_by_name(player, "shooting")) { p /= MAX_BLOWS; log_obj(format("Rescaling bow power, total is %d\n", p)); } return p; }
/** * Add power for +to_hit */ static int to_hit_power(const object_type *obj, int p) { int q = (obj->to_h * TO_HIT_POWER / 2); p += q; if (p) log_obj(format("Add %d power for to hit, total is %d\n", q, p)); return p; }
/** * Add power for extra might */ static int extra_might_power(const object_type *obj, int p, int mult, bool known) { if (known || object_this_mod_is_visible(obj, OBJ_MOD_MIGHT)) { if (obj->modifiers[OBJ_MOD_MIGHT] >= INHIBIT_MIGHT) { p += INHIBIT_POWER; log_obj("INHIBITING - too much extra might - quitting\n"); return p; } else { mult += obj->modifiers[OBJ_MOD_MIGHT]; } log_obj(format("Mult after extra might is %d\n", mult)); } p *= mult; log_obj(format("After multiplying power for might, total is %d\n", p)); return p; }
/** * To damage power */ static int to_damage_power(const object_type *obj) { int p; p = (obj->to_d * DAMAGE_POWER / 2); if (p) log_obj(format("%d power from to_dam\n", p)); /* Add second lot of damage power for non-weapons */ if ((wield_slot(obj) != slot_by_name(player, "shooting")) && !tval_is_melee_weapon(obj) && !tval_is_ammo(obj)) { int q = (obj->to_d * DAMAGE_POWER); p += q; if (q) log_obj(format("Add %d from non-weapon to_dam, total %d\n", q, p)); } return p; }
/** * Add base power for jewelry */ static int jewelry_power(const object_type *obj, int p) { if (tval_is_jewelry(obj)) { p += BASE_JEWELRY_POWER; log_obj(format("Adding %d power for jewelry, total is %d\n", BASE_JEWELRY_POWER, p)); } return p; }
/** * Add power for extra shots - note that we cannot handle negative shots */ static int extra_shots_power(const object_type *obj, int p, bool known) { if (obj->modifiers[OBJ_MOD_SHOTS] == 0) return p; if (known || object_this_mod_is_visible(obj, OBJ_MOD_SHOTS)) { if (obj->modifiers[OBJ_MOD_SHOTS] >= INHIBIT_SHOTS) { p += INHIBIT_POWER; log_obj("INHIBITING - too many extra shots - quitting\n"); return p; } else if (obj->modifiers[OBJ_MOD_SHOTS] > 0) { int q = obj->modifiers[OBJ_MOD_SHOTS]; p = p * (1 + q); log_obj(format("Multiplying power by %d for extra shots, total is %d\n", 1 + q, p)); } } return p; }
/** * Calculate the multiplier we'll get with a given bow type. */ static int bow_multiplier(const object_type *obj) { int mult = 1; if (obj->tval != TV_BOW) return mult; else mult = obj->pval; log_obj(format("Base mult for this weapon is %d\n", mult)); return mult; }
/** * Damage dice power or equivalent */ static int damage_dice_power(const object_type *obj) { int dice = 0; /* Add damage from dice for any wieldable weapon or ammo */ if (tval_is_melee_weapon(obj) || tval_is_ammo(obj)) { dice = (obj->dd * (obj->ds + 1) * DAMAGE_POWER / 4); log_obj(format("Add %d power for damage dice, ", dice)); } else if (wield_slot(obj) != slot_by_name(player, "shooting")) { /* Add power boost for nonweapons with combat flags */ if (obj->brands || obj->slays || (obj->modifiers[OBJ_MOD_BLOWS] > 0) || (obj->modifiers[OBJ_MOD_SHOTS] > 0) || (obj->modifiers[OBJ_MOD_MIGHT] > 0)) { dice = (WEAP_DAMAGE * DAMAGE_POWER); log_obj(format("Add %d power for non-weapon combat bonuses, ", dice)); } } return dice; }
/** * Add power for extra blows */ static int extra_blows_power(const object_type *obj, int p, bool known) { int q = p; if (obj->modifiers[OBJ_MOD_BLOWS] == 0) return p; if (known || object_this_mod_is_visible(obj, OBJ_MOD_BLOWS)) { if (obj->modifiers[OBJ_MOD_BLOWS] >= INHIBIT_BLOWS) { p += INHIBIT_POWER; log_obj("INHIBITING - too many extra blows - quitting\n"); return p; } else { p = p * (MAX_BLOWS + obj->modifiers[OBJ_MOD_BLOWS]) / MAX_BLOWS; /* Add boost for assumed off-weapon damage */ p += (NONWEAP_DAMAGE * obj->modifiers[OBJ_MOD_BLOWS] * DAMAGE_POWER / 2); log_obj(format("Add %d power for extra blows, total is %d\n", p - q, p)); } } return p; }
std::string httpclient::post(std::string url, std::string body) { logging log_obj("httpclient.log"); tcpclient tcp_client(this->host, this->port); int body_length = body.length(); std::string body_length_str = std::to_string(body_length - 1); std::string message = std::string("POST ") + url + " HTTP/1.1\n Host: " + this->host + ":" + this->port + "\n" + "User-agent: huyorg/0.0.1\n Accept: */*\nContent-Type: " "application/json\n" + "Content-Length: " + body_length_str + "\n\n" + body + "\n"; auto read_message = tcp_client.write_read_string(message); log_obj.write(read_message); return read_message; }
/** * Add launcher bonus for ego ammo, multiply for launcher and rescale */ static int launcher_ammo_damage_power(const object_type *obj, int p) { int ammo_type = 0; if (tval_is_ammo(obj)) { if (obj->tval == TV_ARROW) ammo_type = 1; if (obj->tval == TV_BOLT) ammo_type = 2; if (obj->ego) p += (archery[ammo_type].launch_dam * DAMAGE_POWER / 2); p = p * archery[ammo_type].launch_mult / (2 * MAX_BLOWS); log_obj(format("After multiplying ammo and rescaling, power is %d\n", p)); } return p; }
/** * Add power for effect */ static int effects_power(const object_type *obj, int p, bool known) { int q = 0; if (known || object_effect_is_known(obj)) { if (obj->artifact && obj->artifact->activation && obj->artifact->activation->power) { q = obj->artifact->activation->power; } else if (obj->kind->power) { q = obj->kind->power; } if (q) { p += q; log_obj(format("Add %d power for item activation, total is %d\n", q, p)); } } return p; }
/** * Add ammo damage for launchers, get multiplier and rescale */ static int ammo_damage_power(const object_type *obj, int p) { int q = 0; int launcher = -1; if (wield_slot(obj) == slot_by_name(player, "shooting")) { if (kf_has(obj->kind->kind_flags, KF_SHOOTS_SHOTS)) launcher = 0; else if (kf_has(obj->kind->kind_flags, KF_SHOOTS_ARROWS)) launcher = 1; else if (kf_has(obj->kind->kind_flags, KF_SHOOTS_BOLTS)) launcher = 2; if (launcher != -1) { q = (archery[launcher].ammo_dam * DAMAGE_POWER / 2); log_obj(format("Adding %d power from ammo, total is %d\n", q, p + q)); } } return q; }
/** * Calculate the rating for a given slay combination */ static s32b slay_power(const object_type *obj, int p, int verbose, int dice_pwr, bool known) { u32b sv = 0; int i, q, num_brands = 0, num_slays = 0, num_kills = 0; int mult; int tot_mon_power = 0; struct brand *brands = obj->brands; struct slay *slays = obj->slays; /* Count the known brands and slays */ while (brands) { if (known || brands->known) num_brands++; brands = brands->next; } while (slays) { if (known || slays->known) { if (slays->multiplier <= 3) num_slays++; else num_kills++; } slays = slays->next; } /* If there are no slays or brands return */ if ((num_slays + num_brands + num_kills) == 0) return p; /* Look in the cache to see if we know this one yet */ sv = check_slay_cache(obj); /* If it's cached (or there are no slays), return the value */ if (sv) { log_obj("Slay cache hit\n"); } else { /* * Otherwise we need to calculate the expected average multiplier * for this combination (multiplied by the total number of * monsters, which we'll divide out later). */ for (i = 0; i < z_info->r_max; i++) { monster_type *mon = mem_zalloc(sizeof(*mon)); const struct brand *b = NULL; const struct slay *s = NULL; char verb[20]; mult = 1; mon->race = &r_info[i]; /* Find the best multiplier against this monster */ improve_attack_modifier((object_type *)obj, mon, &b, &s, verb, FALSE, FALSE, !known); if (s) mult = s->multiplier; else if (b) mult = b->multiplier; /* Add up totals */ tot_mon_power += mon->race->scaled_power; sv += mult * mon->race->scaled_power; mem_free(mon); } /* * To get the expected damage for this weapon, multiply the * average damage from base dice by sv, and divide by the * total number of monsters. */ if (verbose) { struct brand *b, *brands = NULL; struct slay *s, *slays = NULL; /* Write info about the slay combination and multiplier */ log_obj("Slay multiplier for: "); brands = brand_collect(obj->brands, NULL, !known); slays = slay_collect(obj->slays, NULL, !known); for (b = brands; b; b = b->next) { log_obj(format("%sx%d ", b->name, b->multiplier)); } for (s = slays; s; s = s->next) { log_obj(format("%sx%d ", s->name, s->multiplier)); } log_obj(format("\nsv is: %d\n", sv)); log_obj(format(" and t_m_p is: %d \n", tot_mon_power)); log_obj(format("times 1000 is: %d\n", (1000 * sv) / tot_mon_power)); free_brand(brands); free_slay(slays); } /* Add to the cache */ if (fill_slay_cache(obj, sv)) log_obj("Added to slay cache\n"); } q = (dice_pwr * (sv / 100)) / (tot_mon_power / 100); p += q; log_obj(format("Add %d for slay power, total is %d\n", q, p)); /* Bonuses for multiple brands and slays */ if (num_slays > 1) { q = (num_slays * num_slays * dice_pwr) / (DAMAGE_POWER * 5); p += q; log_obj(format("Add %d power for multiple slays, total is %d\n", q, p)); } if (num_brands > 1) { q = (2 * num_brands * num_brands * dice_pwr) / (DAMAGE_POWER * 5); p += q; log_obj(format("Add %d power for multiple brands, total is %d\n",q, p)); } if (num_kills > 1) { q = (3 * num_kills * num_kills * dice_pwr) / (DAMAGE_POWER * 5); p += q; log_obj(format("Add %d power for multiple kills, total is %d\n", q, p)); } if (num_slays == 8) { p += 10; log_obj(format("Add 10 power for full set of slays, total is %d\n", p)); } if (num_brands == 5) { p += 20; log_obj(format("Add 20 power for full set of brands, total is %d\n",p)); } if (num_kills == 3) { p += 20; log_obj(format("Add 20 power for full set of kills, total is %d\n", p)); } return p; }
/** * Add power for elemental properties */ static int element_power(const object_type *obj, int p, bool known) { size_t i, j; int q; /* Zero the set counts */ for (i = 0; i < N_ELEMENTS(element_sets); i++) element_sets[i].count = 0; /* Analyse each element for ignore, vulnerability, resistance or immunity */ for (i = 0; i < N_ELEMENTS(el_powers); i++) { if (!known && !object_element_is_known(obj, i)) continue; if (obj->el_info[i].flags & EL_INFO_IGNORE) { if (el_powers[i].ignore_power != 0) { q = (el_powers[i].ignore_power); p += q; log_obj(format("Add %d power for ignoring %s, total is %d\n", q, el_powers[i].name, p)); } } if (obj->el_info[i].res_level == -1) { if (el_powers[i].vuln_power != 0) { q = (el_powers[i].vuln_power); p += q; log_obj(format("Add %d power for vulnerability to %s, total is %d\n", q, el_powers[i].name, p)); } } else if (obj->el_info[i].res_level == 1) { if (el_powers[i].res_power != 0) { q = (el_powers[i].res_power); p += q; log_obj(format("Add %d power for resistance to %s, total is %d\n", q, el_powers[i].name, p)); } } else if (obj->el_info[i].res_level == 3) { if (el_powers[i].im_power != 0) { q = (el_powers[i].im_power + el_powers[i].res_power); p += q; log_obj(format("Add %d power for immunity to %s, total is %d\n", q, el_powers[i].name, p)); } } /* Track combinations of element properties */ for (j = 0; j < N_ELEMENTS(element_sets); j++) if ((element_sets[j].type == el_powers[i].type) && (element_sets[j].res_level <= obj->el_info[i].res_level)) element_sets[j].count++; } /* Add extra power for multiple flags of the same type */ for (i = 0; i < N_ELEMENTS(element_sets); i++) { if (element_sets[i].count > 1) { q = (element_sets[i].factor * element_sets[i].count * element_sets[i].count); p += q; log_obj(format("Add %d power for multiple %s, total is %d\n", q, element_sets[i].desc, p)); } /* Add bonus if item has a full set of these flags */ if (element_sets[i].count == element_sets[i].size) { q = element_sets[i].bonus; p += q; log_obj(format("Add %d power for full set of %s, total is %d\n", q, element_sets[i].desc, p)); } } return p; }