/* Multiply !! */ bool ai_multiply(s32b m_idx) { monster_type *m_ptr = get_monster(m_idx); s32b k, y, x, oy = m_ptr->fy, ox = m_ptr->fx; bool is_frien = (is_friend(m_ptr) > 0); /* Count the adjacent monsters */ for (k = 0, y = oy - 1; y <= oy + 1; y++) { for (x = ox - 1; x <= ox + 1; x++) { if (cave[y][x].m_idx) k++; } } if (is_friend(m_ptr) > 0) { is_frien = TRUE; } else { is_frien = FALSE; } /* Hack -- multiply slower in crowded areas */ if ((k < 4) && (!k || !rand_int(k * MON_MULT_ADJ))) { /* Try to multiply */ if (multiply_monster(m_idx, (is_frien), FALSE)) { /* Take note if visible */ if (m_ptr->ml) monstmem_add(RT_MISC, FLAG_MULTIPLY, m_ptr, 0); /* Multiplying takes energy */ return TRUE; } } return FALSE; }
void npc::draw(WINDOW* w, int ux, int uy, bool inv) { int x = SEEX + posx - ux; int y = SEEY + posy - uy; nc_color col = c_pink; if (attitude == NPCATT_KILL) col = c_red; if (is_friend()) col = c_green; else if (is_following()) col = c_ltgreen; if (inv) mvwputch_inv(w, y, x, col, '@'); else mvwputch (w, y, x, col, '@'); }
int npc::danger_assessment(game *g) { int ret = 0; int sightdist = g->light_level(), junk; for (int i = 0; i < g->z.size(); i++) { if (g->m.sees(posx, posy, g->z[i].posx, g->z[i].posy, sightdist, junk)) ret += g->z[i].type->difficulty; } ret /= 10; if (ret <= 2) ret = -10 + 5 * ret; // Low danger if no monsters around // Mod for the player if (is_enemy()) { if (rl_dist(posx, posy, g->u.posx, g->u.posy) < 10) { if (g->u.weapon.is_gun()) ret += 10; else ret += 10 - rl_dist(posx, posy, g->u.posx, g->u.posy); } } else if (is_friend()) { if (rl_dist(posx, posy, g->u.posx, g->u.posy) < 8) { if (g->u.weapon.is_gun()) ret -= 8; else ret -= 8 - rl_dist(posx, posy, g->u.posx, g->u.posy); } } for (int i = 0; i < num_hp_parts; i++) { if (i == hp_head || i == hp_torso) { if (hp_cur[i] < hp_max[i] / 4) ret += 5; else if (hp_cur[i] < hp_max[i] / 2) ret += 3; else if (hp_cur[i] < hp_max[i] * .9) ret += 1; } else { if (hp_cur[i] < hp_max[i] / 4) ret += 2; else if (hp_cur[i] < hp_max[i] / 2) ret += 1; } } return ret; }
void npc::die(game *g, bool your_fault) { int j; if (g->u_see(posx, posy, j)) g->add_msg("%s dies!", name.c_str()); if (your_fault && !g->u.has_trait(PF_HEARTLESS)) { if (is_friend()) g->u.add_morale(MORALE_KILLED_FRIEND, -500); else if (!is_enemy()) g->u.add_morale(MORALE_KILLED_INNOCENT, -100); } item my_body; my_body.make_corpse(g->itypes[itm_corpse], g->mtypes[mon_null], g->turn); my_body.name = name; g->m.add_item(posx, posy, my_body); for (int i = 0; i < inv.size(); i++) g->m.add_item(posx, posy, inv[i]); for (int i = 0; i < worn.size(); i++) g->m.add_item(posx, posy, worn[i]); if (weapon.type->id != itm_null) g->m.add_item(posx, posy, weapon); }
int is_friend (tree type, tree supplicant) { int declp; tree list; tree context; if (supplicant == NULL_TREE || type == NULL_TREE) return 0; declp = DECL_P (supplicant); if (declp) /* It's a function decl. */ { tree list = DECL_FRIENDLIST (TYPE_MAIN_DECL (type)); tree name = DECL_NAME (supplicant); for (; list ; list = TREE_CHAIN (list)) { if (name == FRIEND_NAME (list)) { tree friends = FRIEND_DECLS (list); for (; friends ; friends = TREE_CHAIN (friends)) { tree this_friend = TREE_VALUE (friends); if (this_friend == NULL_TREE) continue; if (supplicant == this_friend) return 1; if (is_specialization_of_friend (supplicant, this_friend)) return 1; } break; } } } else /* It's a type. */ { if (same_type_p (supplicant, type)) return 1; list = CLASSTYPE_FRIEND_CLASSES (TREE_TYPE (TYPE_MAIN_DECL (type))); for (; list ; list = TREE_CHAIN (list)) { tree t = TREE_VALUE (list); if (TREE_CODE (t) == TEMPLATE_DECL ? is_specialization_of_friend (TYPE_MAIN_DECL (supplicant), t) : same_type_p (supplicant, t)) return 1; } } if (declp) { if (DECL_FUNCTION_MEMBER_P (supplicant)) context = DECL_CONTEXT (supplicant); else context = NULL_TREE; } else { if (TYPE_CLASS_SCOPE_P (supplicant)) /* Nested classes get the same access as their enclosing types, as per DR 45 (this is a change from the standard). */ context = TYPE_CONTEXT (supplicant); else /* Local classes have the same access as the enclosing function. */ context = decl_function_context (TYPE_MAIN_DECL (supplicant)); } /* A namespace is not friend to anybody. */ if (context && TREE_CODE (context) == NAMESPACE_DECL) context = NULL_TREE; if (context) return is_friend (type, context); return 0; }
void npc::talk_to_u(game *g) { if (attitude == NPCATT_TALK) attitude = NPCATT_NULL; dialogue d; d.alpha = &g->u; d.beta = this; d.topic_stack.push_back(chatbin.first_topic); if (is_friend()) d.topic_stack.push_back(TALK_FRIEND); int most_difficult_mission = 0; for (int i = 0; i < chatbin.missions.size(); i++) { mission_type *type = g->find_mission_type(chatbin.missions[i]); if (type->urgent && type->difficulty > most_difficult_mission) { d.topic_stack.push_back(TALK_MISSION_DESCRIBE); chatbin.mission_selected = i; most_difficult_mission = type->difficulty; } } most_difficult_mission = 0; bool chosen_urgent = false; for (int i = 0; i < chatbin.missions_assigned.size(); i++) { mission_type *type = g->find_mission_type(chatbin.missions_assigned[i]); if ((type->urgent && !chosen_urgent) || (type->difficulty > most_difficult_mission && (type->urgent || !chosen_urgent) )) { chosen_urgent = type->urgent; d.topic_stack.push_back(TALK_MISSION_INQUIRE); chatbin.mission_selected = i; most_difficult_mission = type->difficulty; } } if (d.topic_stack.back() == TALK_NONE) { g->add_msg(_("%s says, \"Leave me alone.\""), name.c_str()); return; } moves -= 100; decide_needs(); d.win = newwin(25, 80, 0, 0); wborder(d.win, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX, LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX ); for (int i = 1; i < 24; i++) mvwputch(d.win, i, 41, c_ltgray, LINE_XOXO); mvwputch(d.win, 0, 41, c_ltgray, LINE_OXXX); mvwputch(d.win, 24, 41, c_ltgray, LINE_XXOX); mvwprintz(d.win, 1, 1, c_white, _("Dialogue with %s"), name.c_str()); mvwprintz(d.win, 1, 43, c_white, _("Your response:")); // Main dialogue loop do { talk_topic next = d.opt(d.topic_stack.back(), g); if (next == TALK_NONE) { int cat = topic_category(d.topic_stack.back()); do d.topic_stack.pop_back(); while (cat != -1 && topic_category(d.topic_stack.back()) == cat); } if (next == TALK_DONE || d.topic_stack.empty()) d.done = true; else if (next != TALK_NONE) d.topic_stack.push_back(next); } while (!d.done); delwin(d.win); g->refresh_all(); }
/* * Display current pets */ static void do_cmd_knowledge_pets(void) { s32b i; PHYSFS_file *fff; monster_type *m_ptr; monster_race *r_ptr; s32b t_friends = 0; s32b t_levels = 0; s32b show_upkeep = 0; s32b upkeep_divider = 20; char file_name[1024]; /* Temporary file */ if (path_temp(file_name, 1024)) return; /* Open a new file */ fff = my_fopen(file_name, "w"); if (has_ability(AB_PERFECT_CASTING)) upkeep_divider = 15; /* Process the monsters (backwards) */ for_flags(&monst_list); { i = __key; /* Access the monster */ m_ptr = get_monster(i); r_ptr = &r_info[m_ptr->r_idx]; /* Ignore "dead" monsters */ if (!m_ptr->r_idx) continue; /* Calculate "upkeep" for friendly monsters */ if (is_friend(m_ptr) == 1) { char pet_name[80]; t_friends++; t_levels += m_ptr->level; monster_desc(pet_name, m_ptr, 0x88); fprintf(fff, "%s%s (%s)\n", ((has_flag(m_ptr, FLAG_UNIQUE))) ? "#####G" : "", pet_name, (has_flag(m_ptr, FLAG_PERMANENT)) ? "friend" : "companion"); } } end_for_flags(); if (t_friends > 1 + (p_ptr->lev / (upkeep_divider))) { show_upkeep = (t_levels); if (show_upkeep > 100) show_upkeep = 100; else if (show_upkeep < 10) show_upkeep = 10; } fprintf(fff, "----------------------------------------------\n"); fprintf(fff, " Total: %d pet%s.\n", t_friends, (t_friends == 1 ? "" : "s")); fprintf(fff, " Upkeep: %d%% mana.\n", show_upkeep); /* Close the file */ my_fclose(fff); /* Display the file contents */ show_file(file_name, "Current Pets", 0, 0); /* Remove the file */ fd_kill(file_name); }