View Single Post
Old March 23, 2019, 15:53   #1
wobbly
Veteran
 
Join Date: May 2012
Location: Adelaide, Australia
Posts: 2,269
wobbly is on a distinguished road
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);

	}

}
So it takes energy, moves the player & then decreases the run counter (only here returning if the counter is =0 ? ) before queing CMD_RUN?

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);

}
It seems to set the run counter to 0 but I don't see anywhere where it removes the que-ed command? As far as I understand it that run command will still make a move if the run counter is 0? What am I missing here?

Last edited by wobbly; March 23, 2019 at 15:59.
wobbly is offline   Reply With Quote