/* * Tracks which monster has had which pain message stored, so redundant * messages don't happen due to monster attacks hitting other monsters. * Returns true if the message is redundant. */ static bool redundant_monster_message(int m_idx, MON_MSG msg_code) { int i; /* No messages yet */ if (size_mon_hist == 0) { return(false); } for (i = 0; i < size_mon_hist; i++) { /* Not the same monster */ if (m_idx != mon_message_hist[i].monster_idx) { continue; } /* Not the same code */ if (msg_code != mon_message_hist[i].message_code) { continue; } /* We have a match. */ return(true); } return(false); }
public mon_timed_effect(MON_MSG a, MON_MSG b, MON_MSG c, uint d, int e) { message_begin = a; message_end = b; message_increase = c; flag_resist = d; max_timer = e; }
/* * Dump a message describing a monster's reaction to damage */ public static void message_pain(int m_idx, int dam) { long oldhp, newhp, tmp; int percentage; Monster m_ptr = Cave.cave_monster(Cave.cave, m_idx); MON_MSG msg_code = MON_MSG.UNHARMED; //char m_name[80]; string m_name; /* Get the monster name */ m_name = m_ptr.monster_desc(0); /* Notice non-damage */ if (dam == 0) { add_monster_message(m_name, m_idx, msg_code, false); return; } /* Note -- subtle fix -CFT */ newhp = (long)(m_ptr.hp); oldhp = newhp + (long)(dam); tmp = (newhp * 100L) / oldhp; percentage = (int)(tmp); if (percentage > 95) { msg_code = MON_MSG.MON_MSG_95; } else if (percentage > 75) { msg_code = MON_MSG.MON_MSG_75; } else if (percentage > 50) { msg_code = MON_MSG.MON_MSG_50; } else if (percentage > 35) { msg_code = MON_MSG.MON_MSG_35; } else if (percentage > 20) { msg_code = MON_MSG.MON_MSG_20; } else if (percentage > 10) { msg_code = MON_MSG.MON_MSG_10; } else { msg_code = MON_MSG.MON_MSG_0; } add_monster_message(m_name, m_idx, msg_code, false); }
/* * Tracks which monster has had which pain message stored, so redundant * messages don't happen due to monster attacks hitting other monsters. * Returns true if the message is redundant. */ static bool redundant_monster_message(int m_idx, MON_MSG msg_code) { int i; /* No messages yet */ if(size_mon_hist == 0) return false; for(i = 0; i < size_mon_hist; i++) { /* Not the same monster */ if(m_idx != mon_message_hist[i].monster_idx) continue; /* Not the same code */ if(msg_code != mon_message_hist[i].message_code) continue; /* We have a match. */ return (true); } return (false); }
/* * Returns a pointer to a statically allocatted string containing a formatted * message based on the given message code and the quantity flag. * The contents of the returned value will change with the next call * to this function */ static string get_mon_msg_action(MON_MSG msg_code, bool do_plural, Monster_Race race) { //static char buf[200]; string buf = ""; string action = msg_repository[(int)msg_code]; short n = 0; /* Regular text */ byte flag = 0; Misc.assert(race.Base != null && race.Base.pain != null); if(race.Base != null && race.Base.pain != null) { switch(msg_code) { case MON_MSG.MON_MSG_95: action = race.Base.pain.Messages[0]; break; case MON_MSG.MON_MSG_75: action = race.Base.pain.Messages[1]; break; case MON_MSG.MON_MSG_50: action = race.Base.pain.Messages[2]; break; case MON_MSG.MON_MSG_35: action = race.Base.pain.Messages[3]; break; case MON_MSG.MON_MSG_20: action = race.Base.pain.Messages[4]; break; case MON_MSG.MON_MSG_10: action = race.Base.pain.Messages[5]; break; case MON_MSG.MON_MSG_0: action = race.Base.pain.Messages[6]; break; } } /* Put the message characters in the buffer */ for(; action.Length > 0; action = action.Substring(1)) { /* Check available space */ if(n >= (buf.Length)) break; /* Are we parsing a quantity modifier? */ if(flag != 0) { /* Check the presence of the modifier's terminator */ if(action[0] == ']') { /* Go back to parsing regular text */ flag = 0; /* Skip the mark */ continue; } /* Check if we have to parse the plural modifier */ if(action[0] == '|') { /* Switch to plural modifier */ flag = PLURAL_MON; /* Skip the mark */ continue; } /* Ignore the character if we need the other part */ if((flag == PLURAL_MON) != do_plural) continue; } /* Do we need to parse a new quantity modifier? */ else if(action[0] == '[') { /* Switch to singular modifier */ flag = SINGULAR_MON; /* Skip the mark */ continue; } /* Append the character to the buffer */ buf += action[0]; n++; } /* Terminate the buffer */ //buf[n] = '\0'; /* Done */ return (buf); }
/* * Stack a codified message for the given monster race. You must supply * the description of some monster of this race. You can also supply * different monster descriptions for the same race. * Return true on success. */ public static bool add_monster_message(string mon_name, int m_idx, MON_MSG msg_code, bool delay) { int i; byte mon_flags = 0; Monster m_ptr = Cave.cave_monster(Cave.cave, m_idx); int r_idx = m_ptr.r_idx; if(redundant_monster_message(m_idx, msg_code)) return (false); /* Paranoia */ if(mon_name == null || mon_name.Length == 0) mon_name = "it"; /* Save the "hidden" mark, if present */ if(mon_name.Contains("(hidden)")) mon_flags |= 0x01; /* Save the "offscreen" mark, if present */ if(mon_name.Contains("(offscreen)")) mon_flags |= 0x02; /* Monster is invisible or out of LOS */ if((mon_name == "it") || mon_name == "something") mon_flags |= 0x04; /* Query if the message is already stored */ for(i = 0; i < size_mon_msg; i++) { /* We found the race and the message code */ if((mon_msg[i].mon_race == r_idx) && (mon_msg[i].mon_flags == mon_flags) && (mon_msg[i].msg_code == msg_code)) { /* Can we increment the counter? */ if(mon_msg[i].mon_count < byte.MaxValue) { /* Stack the message */ ++(mon_msg[i].mon_count); } /* Success */ return (true); } } /* The message isn't stored. Check free space */ if(size_mon_msg >= Misc.MAX_STORED_MON_MSG) return (false); /* Assign the message data to the free slot */ mon_msg[i] = new Monster_Race_Message(); mon_msg[i].mon_race = (short)r_idx; mon_msg[i].mon_flags = mon_flags; mon_msg[i].msg_code = msg_code; mon_msg[i].delay = delay; /* Just this monster so far */ mon_msg[i].mon_count = 1; /* One more entry */ ++size_mon_msg; Misc.p_ptr.notice |= Misc.PN_MON_MESSAGE; /* record which monster had this message stored */ if(size_mon_hist >= Misc.MAX_STORED_MON_CODES) return (true); mon_message_hist[size_mon_hist] = new Monster_Message_History(); mon_message_hist[size_mon_hist].monster_idx = m_idx; mon_message_hist[size_mon_hist].message_code = msg_code; size_mon_hist++; /* Success */ return (true); }
/** * Attempts to set the timer of the given monster effect to `timer`. * * Checks to see if the monster resists the effect, using mon_resist_effect(). * If not, the effect is set to `timer` turns. If `timer` is 0, or if the * effect timer was 0, or if MON_TMD_FLG_NOTIFY is set in `flag`, then a * message is printed, unless MON_TMD_FLG_NOMESSAGE is set in `flag`. * * Set a timed monster event to 'v'. Give messages if the right flags are set. * Check if the monster is able to resist the spell. Mark the lore. * Returns true if the monster was affected. * Return false if the monster was unaffected. */ static bool mon_set_timed(Monster m_ptr, Misc.MON_TMD ef_idx, int timer, ushort flag, bool id) { mon_timed_effect effect; MON_MSG m_note = 0; int resisted; int old_timer; Misc.assert(ef_idx >= 0 && ef_idx < Misc.MON_TMD.MAX); effect = effects[(int)ef_idx]; Misc.assert(m_ptr != null); old_timer = m_ptr.m_timed[(int)ef_idx]; /* Ignore dead monsters */ if (m_ptr.r_idx == 0) { return(false); } /* No change */ if (old_timer == timer) { return(false); } if (timer == 0) { /* Turning off, usually mention */ m_note = effect.message_end; flag |= Misc.MON_TMD_FLG_NOTIFY; } else if (old_timer == 0) { /* Turning on, usually mention */ flag |= Misc.MON_TMD_FLG_NOTIFY; m_note = effect.message_begin; } else if (timer > old_timer) { /* Different message for increases, but don't automatically mention. */ m_note = effect.message_increase; } /* Determine if the monster resisted or not */ resisted = mon_resist_effect(m_ptr, ef_idx, timer, flag)?1:0; if (resisted != 0) { m_note = MON_MSG.UNAFFECTED; } else { m_ptr.m_timed[(int)ef_idx] = (short)timer; } if (Misc.p_ptr.health_who == m_ptr.midx) { Misc.p_ptr.redraw |= (Misc.PR_HEALTH); } /* Update the visuals, as appropriate. */ Misc.p_ptr.redraw |= (Misc.PR_MONLIST); /* Print a message if there is one, if the effect allows for it, and if * either the monster is visible, or we're trying to ID something */ if (m_note != 0 && (m_ptr.ml || id) && (flag & Misc.MON_TMD_FLG_NOMESSAGE) == 0 && (flag & Misc.MON_TMD_FLG_NOTIFY) != 0) { //char m_name[80]; string m_name; m_name = m_ptr.monster_desc((Desc)0x04); Monster_Message.add_monster_message(m_name, m_ptr.midx, m_note, true); } return(resisted == 0); }
/* * Returns a pointer to a statically allocatted string containing a formatted * message based on the given message code and the quantity flag. * The contents of the returned value will change with the next call * to this function */ static string get_mon_msg_action(MON_MSG msg_code, bool do_plural, Monster_Race race) { //static char buf[200]; string buf = ""; string action = msg_repository[(int)msg_code]; short n = 0; /* Regular text */ byte flag = 0; Misc.assert(race.Base != null && race.Base.pain != null); if (race.Base != null && race.Base.pain != null) { switch (msg_code) { case MON_MSG.MON_MSG_95: action = race.Base.pain.Messages[0]; break; case MON_MSG.MON_MSG_75: action = race.Base.pain.Messages[1]; break; case MON_MSG.MON_MSG_50: action = race.Base.pain.Messages[2]; break; case MON_MSG.MON_MSG_35: action = race.Base.pain.Messages[3]; break; case MON_MSG.MON_MSG_20: action = race.Base.pain.Messages[4]; break; case MON_MSG.MON_MSG_10: action = race.Base.pain.Messages[5]; break; case MON_MSG.MON_MSG_0: action = race.Base.pain.Messages[6]; break; } } /* Put the message characters in the buffer */ for (; action.Length > 0; action = action.Substring(1)) { /* Check available space */ if (n >= (buf.Length)) { break; } /* Are we parsing a quantity modifier? */ if (flag != 0) { /* Check the presence of the modifier's terminator */ if (action[0] == ']') { /* Go back to parsing regular text */ flag = 0; /* Skip the mark */ continue; } /* Check if we have to parse the plural modifier */ if (action[0] == '|') { /* Switch to plural modifier */ flag = PLURAL_MON; /* Skip the mark */ continue; } /* Ignore the character if we need the other part */ if ((flag == PLURAL_MON) != do_plural) { continue; } } /* Do we need to parse a new quantity modifier? */ else if (action[0] == '[') { /* Switch to singular modifier */ flag = SINGULAR_MON; /* Skip the mark */ continue; } /* Append the character to the buffer */ buf += action[0]; n++; } /* Terminate the buffer */ //buf[n] = '\0'; /* Done */ return(buf); }
/* * Stack a codified message for the given monster race. You must supply * the description of some monster of this race. You can also supply * different monster descriptions for the same race. * Return true on success. */ public static bool add_monster_message(string mon_name, int m_idx, MON_MSG msg_code, bool delay) { int i; byte mon_flags = 0; Monster m_ptr = Cave.cave_monster(Cave.cave, m_idx); int r_idx = m_ptr.r_idx; if (redundant_monster_message(m_idx, msg_code)) { return(false); } /* Paranoia */ if (mon_name == null || mon_name.Length == 0) { mon_name = "it"; } /* Save the "hidden" mark, if present */ if (mon_name.Contains("(hidden)")) { mon_flags |= 0x01; } /* Save the "offscreen" mark, if present */ if (mon_name.Contains("(offscreen)")) { mon_flags |= 0x02; } /* Monster is invisible or out of LOS */ if ((mon_name == "it") || mon_name == "something") { mon_flags |= 0x04; } /* Query if the message is already stored */ for (i = 0; i < size_mon_msg; i++) { /* We found the race and the message code */ if ((mon_msg[i].mon_race == r_idx) && (mon_msg[i].mon_flags == mon_flags) && (mon_msg[i].msg_code == msg_code)) { /* Can we increment the counter? */ if (mon_msg[i].mon_count < byte.MaxValue) { /* Stack the message */ ++(mon_msg[i].mon_count); } /* Success */ return(true); } } /* The message isn't stored. Check free space */ if (size_mon_msg >= Misc.MAX_STORED_MON_MSG) { return(false); } /* Assign the message data to the free slot */ mon_msg[i] = new Monster_Race_Message(); mon_msg[i].mon_race = (short)r_idx; mon_msg[i].mon_flags = mon_flags; mon_msg[i].msg_code = msg_code; mon_msg[i].delay = delay; /* Just this monster so far */ mon_msg[i].mon_count = 1; /* One more entry */ ++size_mon_msg; Misc.p_ptr.notice |= Misc.PN_MON_MESSAGE; /* record which monster had this message stored */ if (size_mon_hist >= Misc.MAX_STORED_MON_CODES) { return(true); } mon_message_hist[size_mon_hist] = new Monster_Message_History(); mon_message_hist[size_mon_hist].monster_idx = m_idx; mon_message_hist[size_mon_hist].message_code = msg_code; size_mon_hist++; /* Success */ return(true); }