Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Pathfind to area around queued structure to be built, instead of to t…

…ile under structure.

In the following, truck T now pathfinds to x instead of y, when ordered to build a bunker at +. (This was already
the case since 0119eda, for repairing something at + or building a derrick at +.)
*
 *+
 x*y
T  *

Fixes ticket:3576.
  • Loading branch information...
commit 88c1a3c3703d2ba260a101bb24cde419fe009afe 1 parent 47011db
Cyp authored September 13, 2012
1  src/baseobject.h
@@ -30,6 +30,7 @@ struct StructureBounds
30 30
 {
31 31
 	StructureBounds() {}
32 32
 	StructureBounds(Vector2i const &map, Vector2i const &size) : map(map), size(size) {}
  33
+	bool valid() { return size.x >= 0; }
33 34
 
34 35
 	Vector2i map;           ///< Map coordinates of upper left corner of structure.
35 36
 	Vector2i size;          ///< Size (in map coordinates) of the structure.
14  src/fpath.cpp
@@ -353,7 +353,7 @@ void fpathRemoveDroidData(int id)
353 353
 }
354 354
 
355 355
 static FPATH_RETVAL fpathRoute(MOVE_CONTROL *psMove, int id, int startX, int startY, int tX, int tY, PROPULSION_TYPE propulsionType, 
356  
-                               DROID_TYPE droidType, FPATH_MOVETYPE moveType, int owner, bool acceptNearest, BASE_OBJECT *dstStructure)
  356
+                               DROID_TYPE droidType, FPATH_MOVETYPE moveType, int owner, bool acceptNearest, StructureBounds const &dstStructure)
357 357
 {
358 358
 	objTrace(id, "called(*,id=%d,sx=%d,sy=%d,ex=%d,ey=%d,prop=%d,type=%d,move=%d,owner=%d)", id, startX, startY, tX, tY, (int)propulsionType, (int)droidType, (int)moveType, owner);
359 359
 
@@ -432,7 +432,7 @@ static FPATH_RETVAL fpathRoute(MOVE_CONTROL *psMove, int id, int startX, int sta
432 432
 	job.droidID = id;
433 433
 	job.destX = tX;
434 434
 	job.destY = tY;
435  
-	job.dstStructure = getStructureBounds(dstStructure);
  435
+	job.dstStructure = dstStructure;
436 436
 	job.droidType = droidType;
437 437
 	job.propulsion = propulsionType;
438 438
 	job.moveType = moveType;
@@ -481,9 +481,9 @@ FPATH_RETVAL fpathDroidRoute(DROID* psDroid, SDWORD tX, SDWORD tY, FPATH_MOVETYP
481 481
 	// Check whether the start and end points of the route are blocking tiles and find an alternative if they are.
482 482
 	Position startPos = psDroid->pos;
483 483
 	Position endPos = Position(tX, tY, 0);
484  
-	BASE_OBJECT *dstStructure = worldTile(endPos)->psObject;
  484
+	StructureBounds dstStructure = getStructureBounds(worldTile(endPos)->psObject);
485 485
 	startPos = findNonblockingPosition(startPos, getPropulsionStats(psDroid)->propulsionType, psDroid->player, moveType);
486  
-	if (dstStructure == NULL)  // If there's a structure over the destination, ignore it, otherwise pathfind from somewhere around the obstruction.
  486
+	if (!dstStructure.valid())  // If there's a structure over the destination, ignore it, otherwise pathfind from somewhere around the obstruction.
487 487
 	{
488 488
 		endPos   = findNonblockingPosition(endPos,   getPropulsionStats(psDroid)->propulsionType, psDroid->player, moveType);
489 489
 	}
@@ -491,8 +491,10 @@ FPATH_RETVAL fpathDroidRoute(DROID* psDroid, SDWORD tX, SDWORD tY, FPATH_MOVETYP
491 491
 	switch (psDroid->order.type)
492 492
 	{
493 493
 	case DORDER_BUILD:
  494
+	case DORDER_LINEBUILD:                       // build a number of structures in a row (walls + bridges)
  495
+		dstStructure = getStructureBounds(psDroid->order.psStats, psDroid->order.pos, psDroid->order.direction);  // Just need to get close enough to build (can be diagonally), do not need to reach the destination tile.
  496
+		// Continue, do not break.
494 497
 	case DORDER_HELPBUILD:                       // help to build a structure
495  
-	case DORDER_LINEBUILD:                       // 6 - build a number of structures in a row (walls + bridges)
496 498
 	case DORDER_DEMOLISH:                        // demolish a structure
497 499
 	case DORDER_REPAIR:
498 500
 		acceptNearest = false;
@@ -574,7 +576,7 @@ static int fpathResultQueueLength(void)
574 576
 // Only used by fpathTest.
575 577
 static FPATH_RETVAL fpathSimpleRoute(MOVE_CONTROL *psMove, int id, int startX, int startY, int tX, int tY)
576 578
 {
577  
-	return fpathRoute(psMove, id, startX, startY, tX, tY, PROPULSION_TYPE_WHEELED, DROID_WEAPON, FMT_BLOCK, 0, true, NULL);
  579
+	return fpathRoute(psMove, id, startX, startY, tX, tY, PROPULSION_TYPE_WHEELED, DROID_WEAPON, FMT_BLOCK, 0, true, getStructureBounds((BASE_OBJECT *)NULL));
578 580
 }
579 581
 
580 582
 void fpathTest(int x, int y, int x2, int y2)

0 notes on commit 88c1a3c

Please sign in to comment.
Something went wrong with that request. Please try again.