void npc::load_info(std::string data) { std::stringstream dump; int deathtmp, classtmp; dump << data; // Standard player stuff dump >> id >> posx >> posy >> str_cur >> str_max >> dex_cur >> dex_max >> int_cur >> int_max >> per_cur >> per_max >> hunger >> thirst >> fatigue >> stim >> pain >> pkill >> radiation >> cash >> recoil >> scent >> moves >> underwater >> can_dodge >> oxygen >> deathtmp >> classtmp; if (deathtmp == 1) marked_for_death = true; else marked_for_death = false; myclass = npc_class(classtmp); for (int i = 0; i < PF_MAX2; i++) dump >> my_traits[i]; for (int i = 0; i < num_hp_parts; i++) dump >> hp_cur[i] >> hp_max[i]; for (int i = 0; i < num_skill_types; i++) dump >> sklevel[i] >> skexercise[i]; int numill; int typetmp; disease illtmp; dump >> numill; for (int i = 0; i < numill; i++) { dump >> typetmp >> illtmp.duration; illtmp.type = dis_type(typetmp); illness.push_back(illtmp); } int numadd; addiction addtmp; dump >> numadd; for (int i = 0; i < numadd; i++) { dump >> typetmp >> addtmp.intensity >> addtmp.sated; addtmp.type = add_type(typetmp); addictions.push_back(addtmp); } int numbio; bionic biotmp; dump >> numbio; for (int i = 0; i < numbio; i++) { dump >> typetmp >> biotmp.invlet >> biotmp.powered >> biotmp.charge; biotmp.id = bionic_id(typetmp); my_bionics.push_back(biotmp); } // Special NPC stuff int misstmp, flagstmp, agg, bra, col, alt, tru, val, fea, ang, owe; dump >> agg >> bra >> col >> alt >> wandx >> wandy >> wandf >> omx >> omy >> omz >> mapx >> mapy >> plx >> ply >> goalx >> goaly >> misstmp >> tru >> val >> fea >> ang >> owe >> flagstmp >> fac_id; personality.aggression = agg; personality.bravery = bra; personality.collector = col; personality.altruism = alt; op_of_u.trust = tru; op_of_u.value = val; op_of_u.fear = fea; op_of_u.anger = ang; op_of_u.owed = owe; mission = npc_mission(misstmp); flags = flagstmp; }
void npc::randomize(game *g, npc_class type) { id = g->assign_npc_id(); str_max = dice(4, 3); dex_max = dice(4, 3); int_max = dice(4, 3); per_max = dice(4, 3); weapon.make(g->itypes[itm_null]); ret_null.make(g->itypes[itm_null]); inv.clear(); personality.aggression = rng(-10, 10); personality.bravery = rng(-10, 10); personality.collector = rng(-10, 10); personality.altruism = rng(-10, 10); cash = 100 * rng(0, 20) + 10 * rng(0, 30) + rng(0, 50); moves = 100; mission = NPC_MISSION_NULL; if (one_in(2)) male = true; else male = false; pick_name(); if (type == NC_NONE) type = npc_class(rng(0, NC_MAX - 1)); if (one_in(5)) type = NC_NONE; switch (type) { // Type of character case NC_NONE: // Untyped; no particular specialization for (int i = 1; i < num_skill_types; i++) sklevel[i] = dice(4, 2) - 4; break; case NC_DOCTOR: for (int i = 1; i < num_skill_types; i++) sklevel[i] = dice(3, 2) - 3; sklevel[sk_firstaid] += rng(2, 6); str_max -= rng(0, 2); int_max += rng(0, 2); per_max += rng(0, 1) * rng(0, 1); personality.aggression -= rng(0, 4); if (one_in(4)) flags |= mfb(NF_DRUGGIE); cash += 100 * rng(0, 3) * rng(0, 3); break; case NC_TRADER: for (int i = 1; i < num_skill_types; i++) sklevel[i] = dice(2, 2) - 2 + (rng(0, 1) * rng(0, 1)); sklevel[sk_mechanics] += rng(0, 2); sklevel[sk_electronics] += rng(0, 2); sklevel[sk_speech] += rng(0, 3); sklevel[sk_barter] += rng(2, 4); int_max += rng(0, 1) * rng(0, 1); per_max += rng(0, 1) * rng(0, 1); personality.collector += rng(1, 5); cash += 250 * rng(1, 10); break; case NC_NINJA: for (int i = 1; i < num_skill_types; i++) sklevel[i] = dice(2, 2) - 2; sklevel[sk_dodge] += rng(2, 4); sklevel[sk_melee] += rng(1, 4); sklevel[sk_unarmed] += rng(3, 5); sklevel[sk_throw] += rng(0, 2); str_max -= rng(0, 1); dex_max += rng(0, 2); per_max += rng(0, 2); personality.bravery += rng(0, 3); personality.collector -= rng(1, 6); break; case NC_COWBOY: for (int i = 1; i < num_skill_types; i++) { sklevel[i] = dice(3, 2) - 4; if (sklevel[i] < 0) sklevel[i] = 0; } sklevel[sk_gun] += rng(0, 2); sklevel[sk_pistol] += rng(1, 3); sklevel[sk_rifle] += rng(0, 2); int_max -= rng(0, 2); str_max += rng(0, 1); personality.aggression += rng(0, 2); personality.bravery += rng(1,5); break; case NC_SCIENTIST: for (int i = 1; i < num_skill_types; i++) { sklevel[i] = dice(3, 2) - 4; if (sklevel[i] < 0) sklevel[i] = 0; } sklevel[sk_computer] += rng(1, 4); sklevel[sk_electronics] += rng(1, 3); sklevel[sk_firstaid] += rng(0, 1); if (one_in(4)) flags |= mfb(NF_TECHNOPHILE); if (one_in(3)) flags |= mfb(NF_BOOKWORM); str_max -= rng(1, 3); dex_max -= rng(0, 1); int_max += rng(2, 5); personality.aggression -= rng(1, 5); personality.bravery -= rng(2, 8); personality.collector += rng (0, 2); break; case NC_BOUNTY_HUNTER: for (int i = 1; i < num_skill_types; i++) { sklevel[i] = dice(3, 2) - 3; if (sklevel[i] > 0 && one_in(3)) sklevel[i]--; } sklevel[sk_gun] += rng(2, 4); sklevel[rng(sk_pistol, sk_rifle)] += rng(3, 5); personality.aggression += rng(1, 6); personality.bravery += rng(0, 5); break; } for (int i = 0; i < num_hp_parts; i++) { hp_max[i] = 60 + str_max * 3; hp_cur[i] = hp_max[i]; } starting_weapon(g); worn = starting_clothes(type, male, g); inv = starting_inv(this, type, g); update_worst_item_value(); }
/* * load npc */ void npc::deserialize(JsonIn &jsin) { JsonObject data = jsin.get_object(); json_load_common_variables(data); int misstmp, classtmp, flagstmp, atttmp, tmpid; data.read("id",tmpid); setID(tmpid); data.read("name",name); data.read("marked_for_death", marked_for_death); data.read("dead", dead); if ( data.read( "myclass", classtmp) ) { myclass = npc_class( classtmp ); } data.read("personality", personality); data.read("wandx",wandx); data.read("wandy",wandy); data.read("wandf",wandf); data.read("omx",omx); data.read("omy",omy); data.read("omz",omz); data.read("mapx",mapx); data.read("mapy",mapy); data.read("plx",plx); data.read("ply",ply); data.read("goalx",goal.x); data.read("goaly",goal.y); data.read("goalz",goal.z); if ( data.read("mission",misstmp) ) { mission = npc_mission( misstmp ); } if ( data.read( "flags", flagstmp) ) { flags = flagstmp; } if ( data.read( "attitude", atttmp) ) { attitude = npc_attitude(atttmp); } inv.clear(); if ( data.has_member("inv") ) { JsonIn *invin = data.get_raw("inv"); inv.json_load_items( *invin ); } worn.clear(); data.read("worn",worn); weapon.contents.clear(); data.read("weapon",weapon); data.read("op_of_u",op_of_u); data.read("chatbin",chatbin); data.read("combat_rules",combat_rules); }