This is the mail archive of the xconq7@sources.redhat.com mailing list for the Xconq project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Possible movement improvement



Both mplayer.c and iplayer.c have the following:


	    /* Try moving sideways. */
	    if (probability(80)) {
		dx = task->args[0] - unit->x;  dy = task->args[1] - unit->y;
		fact = (flip_coin() ? 50 : -50);
		x1 = unit->x - ((fact * dy) / 100);
		y1 = unit->y + ((fact * dx) / 100);
		if (inside_area(x1, y1)) {
			DMprintf("%s blocked, moving sideways to (%d, %d).", unit_desig(unit), x1, y1);
			net_push_move_to_task(unit, x1, y1, 1);
	    	}
	    }

This is called when a unit is blocked and could not perform a move_to task.

If I read the code correctly, it seems to only allow two of the possible four directions to be tried. I have seen units get stuck behind 'C' shaped obstacles, and this may partly explain why. A proposed change would be:

	fact = (flip_coin() ? 50 : -50);
		x1 = unit->x - ((fact * dy) / 100);
fact = (flip_coin() ? 50 : -50);  /* this line is new */
			y1 = unit->y + ((fact * dx) / 100);
	
This may allow the unit to try any of four directions randomly.

If this change makes sense, it will need to be in both mplayer.c and iplayer.c.


Brian



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]