![]() |
#1 |
Prophet
Join Date: May 2012
Location: Adelaide, Australia
Posts: 2,584
![]() |
Trying to understand Run/Disturb Code
Code:
/* Take time */ player->upkeep->energy_use = z_info->move_energy / player->state.num_moves; /* Move the player; running straight into a trap == trying to disarm */ move_player(run_cur_dir, dir && disarm ? true : false); /* Decrease counter if it hasn't been cancelled */ /* occurs after movement so that using p->u->running as flag works */ if (player->upkeep->running) { player->upkeep->running--; } else if (!player->upkeep->running_withpathfind) return; /* Prepare the next step */ if (player->upkeep->running) { cmdq_push(CMD_RUN); cmd_set_arg_direction(cmdq_peek(), "direction", 0); } } Now when it disturbs: Code:
void disturb(struct player *p, int stop_search) { /* Cancel repeated commands */ cmd_cancel_repeat(); /* Cancel Resting */ if (player_is_resting(p)) { player_resting_cancel(p, true); p->upkeep->redraw |= PR_STATE; } /* Cancel running */ if (p->upkeep->running) { p->upkeep->running = 0; /* Check for new panel if appropriate */ event_signal(EVENT_PLAYERMOVED); p->upkeep->update |= PU_TORCH; /* Mark the whole map to be redrawn */ event_signal_point(EVENT_MAP, -1, -1); } /* Flush input */ event_signal(EVENT_INPUT_FLUSH); } Last edited by wobbly; March 23, 2019 at 15:59. |
![]() |
![]() |
![]() |
#2 |
Prophet
Join Date: May 2012
Location: Adelaide, Australia
Posts: 2,584
![]() |
My understanding (which is limited & possibly wrong) of what happens here is it returns before movement (in run_test) for a visible monster but that doesn't help for off-screen breathers & invisible monsters. It doesn't que the next cmd_run if p->upkeep->running = 0 but it still actually moves if cmd_run is already qued.
so in the following situation with the dragon fly just out of LOS: Code:
#### @..F. #### While I'm not 100% sure that's how it works in the code, it's certainly what I'm seeing in-game. Edit: Hmm it doesn't interrupt properly for visible either. I can see this by running past a corridor full of sleeping 'p's, it moves 1 step too many. Last edited by wobbly; March 24, 2019 at 06:55. |
![]() |
![]() |
![]() |
#3 |
Prophet
Join Date: May 2012
Location: Adelaide, Australia
Posts: 2,584
![]() |
I'll have a go at fixing this in my own copy in the next couple of days. Just wanted to note that it runs the extra step if you recall while running.
|
![]() |
![]() |
![]() |
#4 |
Vanilla maintainer
Join Date: Apr 2007
Location: Canberra, Australia
Age: 56
Posts: 9,356
Donated: $60
![]() ![]() |
If you work this out that would be great
![]()
__________________
One for the Dark Lord on his dark throne In the Land of Mordor where the Shadows lie. |
![]() |
![]() |
![]() |
#5 |
Prophet
Join Date: May 2012
Location: Adelaide, Australia
Posts: 2,584
![]() |
Had my plans messed up by the flu & only just got round to this, so apologises for the delay. Anyway I've got something that appears to be working on mine. Not sure whether it's the best solution but it is working when I test it.
In player-path.c, run_step I've inserted a little check here: Code:
/* Inserted a check here before movement - MC */ if ((!player->upkeep->running) && (!player->upkeep->running_withpathfind)) { return; } /* Take time */ player->upkeep->energy_use = z_info->move_energy / player->state.num_moves; /* Move the player; running straight into a trap == trying to disarm */ move_player(run_cur_dir, dir && disarm ? true : false); /* Decrease counter if it hasn't been cancelled */ /* occurs after movement so that using p->u->running as flag works */ if (player->upkeep->running) { player->upkeep->running--; } else if (!player->upkeep->running_withpathfind) return; /* Prepare the next step */ if (player->upkeep->running) { cmdq_push(CMD_RUN); cmd_set_arg_direction(cmdq_peek(), "direction", 0); } } In player-util.c, disturb I added a bit: Code:
void disturb(struct player *p, int stop_search) { /* Cancel repeated commands */ cmd_cancel_repeat(); /* Cancel Resting */ if (player_is_resting(p)) { player_resting_cancel(p, true); p->upkeep->redraw |= PR_STATE; } /* Cancel running */ if (p->upkeep->running) { p->upkeep->running = 0; /* Check for new panel if appropriate */ event_signal(EVENT_PLAYERMOVED); p->upkeep->update |= PU_TORCH; /* Mark the whole map to be redrawn */ event_signal_point(EVENT_MAP, -1, -1); } /* Cancel running_withpathfind?? - MC */ if (p->upkeep->running_withpathfind) { player->upkeep->running_withpathfind = false; /* Check for new panel if appropriate */ event_signal(EVENT_PLAYERMOVED); p->upkeep->update |= PU_TORCH; /* Mark the whole map to be redrawn */ event_signal_point(EVENT_MAP, -1, -1); } /* Flush input */ event_signal(EVENT_INPUT_FLUSH); } I was tempted to add message spam in to trace & output what was going on inside the code, though in the end I didn't. I assume there is a more technical way to do that then message spam? What's the usual way to get the game to output this information? Last edited by wobbly; April 4, 2019 at 08:55. |
![]() |
![]() |
![]() |
#6 |
Vanilla maintainer
Join Date: Apr 2007
Location: Canberra, Australia
Age: 56
Posts: 9,356
Donated: $60
![]() ![]() |
So I think I've fixed this issue once and for all by more major surgery. Basically I put in a mechanism for the disturb function to cancel all commands in the queue. I don't think this will have any bad side-effects...
__________________
One for the Dark Lord on his dark throne In the Land of Mordor where the Shadows lie. |
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Townspeople don't disturb (new option; diff included) | Derakon | Vanilla | 6 | October 31, 2010 22:49 |
Trying to understand the Angband 3.X source code | nppangband | Development | 62 | July 11, 2010 18:20 |
feature request - no disturb on 100% search | PowerDiver | Vanilla | 11 | June 14, 2010 22:07 |
Man on the run....well High Elf on the run. | Fendell Orcbane | AAR | 10 | May 1, 2010 08:50 |
feature request - disturb on reverse LOS | PowerDiver | Vanilla | 2 | May 18, 2009 06:46 |