From: Martin Read Date: Wed, 19 Feb 2014 02:33:37 +0000 (+0000) Subject: Miscellaneous fun with notifications, display vars/funcs, and bug fixes X-Git-Tag: stretchy-levels~4 X-Git-Url: http://git.blackswordsonics.com/?a=commitdiff_plain;h=a6cd917504a94f84274f6a2f2be22ebe857e987f;p=victrix-abyssi Miscellaneous fun with notifications, display vars/funcs, and bug fixes The crusade to purge references to display vars/functions from the game logic has been completed. * combat.cc: range-vs-accuracy curve now works correctly for player bow shots, and a notification is sent for trying to shoot monsters at point blank. Also, notify_mon_hit_armour() now actually gets used and an uninitialized variable bug has been squashed. * display-nc.cc: Removed some misconceived comments, made permobj colours actually show up on the screen (rather fewer l_grey items now), and added compile-time option to log messages to stderr. * main.cc: call notify_tick() at the end of every tick to make sure pending display updates get flushed. * map.cc: Removed references to display vars and display_update(). * monsters.cc: Removed references to display vars and display_update(). * notify-local-tty.cc, notify.hh: More notifications! Also, fixing some updates that should have set display control flags but didn't. * objects.cc: Removed reference to display var. * u.cc: Removed references to display vars and display_update(). --- diff --git a/combat.cc b/combat.cc index 7d51ed9..6e64679 100644 --- a/combat.cc +++ b/combat.cc @@ -98,7 +98,7 @@ void resolve_player_melee(int mon, int damage) { bool ring_eff; int ring_bonus; - int healing; // = 0; + int healing = 0; if (u.ring != NO_OBJ) { ring_eff = ring_effectiveness(mon, objects[u.ring].obj_id, damage, &ring_bonus, &healing); @@ -181,7 +181,7 @@ int ushootm(Offset step) int tohit; int range; Coord c = u.pos + step; - int done = 0; + bool done = false; int mon; Mon *mptr; Obj *wep; @@ -190,19 +190,19 @@ int ushootm(Offset step) wep = objects + u.weapon; pwep = permobjs + wep->obj_id; damage = one_die(pwep->power); - range = 1; - for ( ; !done; c += step) + for (range = 1; !done; ++range, (c += step)) { mon = lvl.mon_at(c); if (mon != NO_MON) { - done = 1; + done = true; mptr = monsters + mon; tohit = zero_die(u.agility + u.level - range); if (range == 1) { /* Shooting at point-blank is tricky */ tohit = (tohit + 1) / 2; + notify_point_blank_warning(); } if (tohit >= mptr->defence) { @@ -257,6 +257,7 @@ int mhitu(int mon, Damtyp dtype) { /* Monster hit your armour. */ damage_obj(u.armour); + notify_mon_hit_armour(mon); } else { @@ -314,7 +315,6 @@ test_unaffected: drain_body(1, "snake venom", 0); } damage_u(damage, DEATH_KILLED_MON, permons[mptr->mon_id].name); - display_update(); } return 1; } @@ -378,7 +378,6 @@ int mshootu(int mon) damage = one_die(mptr->rdam); damage_u(damage, DEATH_KILLED_MON, permons[mptr->mon_id].name); } - display_update(); return 1; } else diff --git a/display-nc.cc b/display-nc.cc index 5dd83dc..9f07f6c 100644 --- a/display-nc.cc +++ b/display-nc.cc @@ -39,6 +39,8 @@ #include #include +#undef DEBUG_TO_STDERR +//#define DEBUG_TO_STDERR #define DISP_NC_RADIUS (10) #define DISP_NC_SIDE (DISP_NC_RADIUS * 2 + 1) void set_inventory_message(char const *s, bool allow_nil); @@ -311,7 +313,6 @@ static void load_unicode_tiles() j = mbtowc(wch, terrain_props[i].unicode, 4); if (j != 1) { - /// welp. someone didn't see the above warning } wch[1] = 0; setcchar(terrain_tiles + i, wch, @@ -322,14 +323,15 @@ static void load_unicode_tiles() { wchar_t wch[2]; /* policy decision: for now we don't support use of combining - * characters for tiles. */ + * characters for items. */ j = mbtowc(wch, permobjs[i].unicode, 4); if (j != 1) { - /// welp. someone didn't see the above warning } wch[1] = 0; - setcchar(permobj_tiles + i, wch, 0, 0, nullptr); + setcchar(permobj_tiles + i, wch, + colour_data[permobjs[i].colour].attr, + colour_data[permobjs[i].colour].cpair, nullptr); } } @@ -367,7 +369,9 @@ static void load_ascii_tiles() wchar_t wch[2]; wch[0] = permobjs[i].sym; wch[1] = 0; - setcchar(permobj_tiles + i, wch, 0, 0, nullptr); + setcchar(permobj_tiles + i, wch, + colour_data[permobjs[i].colour].attr, + colour_data[permobjs[i].colour].cpair, nullptr); } } @@ -574,6 +578,11 @@ void print_msg(char const *fmt, ...) va_start(ap, fmt); vw_printw(message_window, fmt, ap); va_end(ap); +#ifdef DEBUG_TO_STDERR + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); +#endif display_update(); } @@ -619,6 +628,11 @@ void print_msg(Msg_prio prio, char const *fmt, ...) vw_printw(message_window, fmt, ap); wattr_set(message_window, colour_data[Gcol_prio_normal].attr, colour_data[Gcol_prio_normal].cpair, nullptr); va_end(ap); +#ifdef DEBUG_TO_STDERR + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); +#endif display_update(); } diff --git a/main.cc b/main.cc index fc93498..c23ad70 100644 --- a/main.cc +++ b/main.cc @@ -113,6 +113,7 @@ void main_loop(void) } update_player(); game_tick++; + notify_tick(); } } diff --git a/map.cc b/map.cc index 6e36831..c40b03f 100644 --- a/map.cc +++ b/map.cc @@ -135,8 +135,6 @@ void leave_level(void) } } depth++; - status_updated = 1; - map_updated = 1; } void make_new_level(void) @@ -145,7 +143,7 @@ void make_new_level(void) populate_level(); inject_player(); look_around_you(); - display_update(); + notify_change_of_depth(); } typedef int (*rwalk_mod_funcptr)(Coord c, void *data); diff --git a/monsters.cc b/monsters.cc index 6f3d4cc..fc9a5b3 100644 --- a/monsters.cc +++ b/monsters.cc @@ -73,11 +73,6 @@ int summoning(Coord c, int how_many) } } } - if (created > 0) - { - map_updated = 1; - display_update(); - } return created; } @@ -334,7 +329,6 @@ void damage_mon(int mon, int amount, bool by_you) if (amount >= mptr->hpcur) { kill_mon(mon, by_you); - display_update(); } else { @@ -505,7 +499,6 @@ void move_mon(int mon, Coord c) return; } reloc_mon(mon, c); - display_update(); } void summon_demon_near(Coord c) diff --git a/notify-local-tty.cc b/notify-local-tty.cc index 45504b9..3129cd1 100644 --- a/notify-local-tty.cc +++ b/notify-local-tty.cc @@ -45,7 +45,7 @@ void notify_player_heal(int amount, int boost, bool loud) { - status_updated = 1; + status_updated = true; if (loud) { /* Tell the player how much better they feel. */ @@ -98,17 +98,25 @@ void notify_death(Death d, char const *what) */ void notify_level_gain(void) { - status_updated = 1; + status_updated = true; print_msg("You gained a level!\n"); } +/*! \brief The player has gained experience points + */ +void notify_exp_gain(int amount) +{ + status_updated = true; + display_update(); +} + /*! \brief The player has gained some Agility * * \param Amount of Agility gained */ void notify_agility_gain(int amount) { - status_updated = 1; + status_updated = true; print_msg("You gained %d Agility.\n", amount); } @@ -118,40 +126,46 @@ void notify_agility_gain(int amount) */ void notify_body_gain(int amount) { - status_updated = 1; + status_updated = true; print_msg("You gained %d Body.\n", amount); } void notify_hp_gain(int amount) { - status_updated = 1; + status_updated = true; print_msg("You gained %d hit points.\n", amount); } void notify_body_restore(void) { - status_updated = 1; + status_updated = true; print_msg("You feel less feeble.\n"); } void notify_agility_restore(void) { - status_updated = 1; + status_updated = true; print_msg("You feel less clumsy.\n"); } void notify_agility_drain(int amount) { - status_updated = 1; + status_updated = true; print_msg("You feel clumsy!\n"); } void notify_body_drain(int amount) { - status_updated = 1; + status_updated = true; print_msg("You feel weaker!\n"); } +void notify_defence_recalc(void) +{ + status_updated = true; + display_update(); +} + void notify_player_teleport(void) { print_msg("You are whisked away!\n"); @@ -285,19 +299,19 @@ void notify_mon_disappear(int mon) void notify_start_armourmelt(void) { - status_updated = 1; + status_updated = true; print_msg("Your armour seems suddenly no stronger than dust!\n"); } void notify_start_leadfoot(void) { - status_updated = 1; + status_updated = true; print_msg("Your feet feel like lead!\n"); } void notify_start_withering(void) { - status_updated = 1; + status_updated = true; print_msg("Your limbs twist and wither!\n"); } @@ -358,6 +372,11 @@ void notify_player_combo_powatk(int mon) print_msg(".\n"); } +void notify_point_blank_warning(void) +{ + print_msg(Msg_prio::Alert, "Using a bow at such close quarters is awkward, and you are unlikely to hit your target.\n"); +} + void notify_player_shot_terrain(int obj, Coord c) { print_msg("Your %s hits the %s.\n", (objects[obj].obj_id == PO_CROSSBOW) ? "bolt" : "arrow", terrain_props[lvl.terrain_at(c)].name); @@ -694,6 +713,7 @@ void notify_player_touch_effect(Damtyp dt) void notify_player_damage_taken(int amount) { + status_updated = true; print_msg("You take %d damage.\n", amount); } @@ -930,14 +950,40 @@ void notify_pack_full(void) print_msg(Msg_prio::Alert, "Your pack is full.\n"); } +/*! \brief Inform client of monster at specified position + * + * For local tty versions, this is just a call to newsym() and + * display_update(). + * + * \param c Affected location + * \param mon Monster at that location. + */ void notify_new_mon_at(Coord c, int mon) { newsym(c); + display_update(); } void notify_fov(void) { touch_back_buffer(); + display_update(); +} + +/*! \brief Inform the client that the game tick has advanced. + * + * For local tty versions, this is done by flushing any pending + * display updates. + */ +void notify_tick(void) +{ + display_update(); +} + +void notify_change_of_depth(void) +{ + status_updated = true; + print_msg("Welcome to level %d of the Abyss.\n", depth); } /* Debugging notifications */ diff --git a/notify.hh b/notify.hh index c1aa42b..9dc0230 100644 --- a/notify.hh +++ b/notify.hh @@ -33,6 +33,7 @@ void notify_death(Death d, char const *what); void notify_player_heal(int amount, int boost, bool loud); void notify_level_gain(void); +void notify_exp_gain(int amount); void notify_agility_gain(int amount); void notify_body_gain(int amount); void notify_agility_restore(void); @@ -49,6 +50,7 @@ void notify_armourmelt_recovered(void); void notify_wither_recovered(void); void notify_protection_lost(void); void notify_wasted_gain(void); +void notify_defence_recalc(void); // Resistance notifications @@ -124,6 +126,7 @@ void notify_knockback_mon_immersed_water(int mon); void notify_knockback_mon_water_offscreen(void); void notify_knockback_mon_lava_offscreen(void); +void notify_point_blank_warning(void); void notify_player_shot_terrain(int obj, Coord c); void notify_mon_hit_armour(int mon); @@ -155,6 +158,8 @@ void notify_hellfire_hit(bool resisted); // Miscellaneous notifications void notify_fov(void); +void notify_tick(void); +void notify_change_of_depth(void); // Debugging notifications void debug_move_oob(Coord c); diff --git a/objects.cc b/objects.cc index 5d4b619..cc8b9e0 100644 --- a/objects.cc +++ b/objects.cc @@ -214,7 +214,6 @@ Action_cost quaff_potion(int obj) break; case PO_RESTORATION_POTION: notify_quaff_potion_restoration(); - status_updated = 1; if (u.bdam && ((!u.adam) || zero_die(2))) { u.bdam = 0; diff --git a/u.cc b/u.cc index 0c07a18..5619f59 100644 --- a/u.cc +++ b/u.cc @@ -92,8 +92,7 @@ void recalc_defence(void) break; } } - status_updated = 1; - display_update(); + notify_defence_recalc(); } Action_cost move_player(Offset delta) @@ -179,9 +178,6 @@ void reloc_player(Coord c) u.pos = c; touch_one_screen(oc); look_around_you(); - map_updated = 1; - status_updated = 1; - display_update(); if (lvl.obj_at(c) != NO_OBJ) { notify_obj_at(c); @@ -202,7 +198,6 @@ int gain_body(int amount) amount = 99 - u.body; } u.body += amount; - status_updated = 1; notify_body_gain(amount); return amount; } @@ -228,7 +223,6 @@ int drain_body(int amount, char const *what, int permanent) { return do_death(DEATH_BODY, what); } - display_update(); return 0; } @@ -246,7 +240,6 @@ int gain_agility(int amount) amount = 99 - u.agility; } u.agility += amount; - status_updated = 1; recalc_defence(); notify_agility_gain(amount); return amount; @@ -280,7 +273,6 @@ int drain_agility(int amount, char const *what, int permanent) int damage_u(int amount, Death d, char const *what) { u.hpcur -= amount; - status_updated = 1; notify_player_damage_taken(amount); if (u.hpcur < 0) { @@ -324,8 +316,6 @@ int do_death(Death d, char const *what) u.adam = 0; u.bdam = 0; recalc_defence(); - status_updated = 1; - display_update(); } else { @@ -391,7 +381,7 @@ void gain_experience(int amount) int bodygain; int agilgain; u.experience += amount; - status_updated = 1; + notify_exp_gain(amount); if (u.experience > lev_threshold(u.level)) { u.level++; @@ -420,10 +410,6 @@ void gain_experience(int amount) notify_hp_gain(hpgain); } } - else - { - display_update(); - } } Pass_fail teleport_u(void) @@ -492,7 +478,6 @@ void update_player(void) squeal = 2; } u.food -= food_use; - status_updated = 1; notify_hunger_level(squeal); } if (u.leadfoot > 0) @@ -530,7 +515,6 @@ void update_player(void) notify_protection_lost(); } } - display_update(); } bool Player::resists(Damtyp dtype) const