From bfe520debf7a377ac7eea9822726bcaca6935664 Mon Sep 17 00:00:00 2001 From: Flugente Date: Wed, 18 Feb 2015 21:04:47 +0000 Subject: [PATCH] When clicking on a sector to start militia pathing, and the sector does not have static militia but militia groups, select the last militia group instead of creating a new empty one. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@7742 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Strategic/mapscreen.cpp | 42 +++++++++++++++++++++++++---------------- Strategic/mapscreen.h | 4 ++-- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Strategic/mapscreen.cpp b/Strategic/mapscreen.cpp index 393b9312..ea98d9eb 100644 --- a/Strategic/mapscreen.cpp +++ b/Strategic/mapscreen.cpp @@ -16474,26 +16474,31 @@ BOOLEAN RequestGiveMilitiaNewDestination( void ) return FALSE; } - // if there is already a travelling group in this sector, pick them up instead - /*UINT8 groupid = 0; + // if there are no more static militia in this sector, but a group is, select the last group BOOLEAN fGroupAlreadyExists = FALSE; - if ( GetMilitiaGroupInSector( sSelMapX, sSelMapY, groupid ) ) + if ( MilitiaInSectorOfRankStationary( sSelMapX, sSelMapY, GREEN_MILITIA ) + MilitiaInSectorOfRankStationary( sSelMapX, sSelMapY, REGULAR_MILITIA ) + MilitiaInSectorOfRankStationary( sSelMapX, sSelMapY, ELITE_MILITIA ) == 0 ) { - INT16 internalslot = GetMilitiaPathSlot( groupid ); - - if ( internalslot > -1 ) + UINT8 groupid = 0; + if ( GetLastMilitiaGroupInSector( sSelMapX, sSelMapY, groupid ) ) { - fGroupAlreadyExists = TRUE; + INT16 internalslot = GetMilitiaPathSlot( groupid ); - gMilitiaGroupId = internalslot; + if ( internalslot > -1 ) + { + fGroupAlreadyExists = TRUE; + + gMilitiaGroupId = internalslot; + + gNewMilitiaGroupId = gMilitiaPath[gMilitiaGroupId].sGroupid; - // yes, we intentionally use a different sector number here - gMilitiaPlotStartSector = (INT16)(sSelMapX + sSelMapY*(MAP_WORLD_X)); + // yes, we intentionally use a different sector number here + gMilitiaPlotStartSector = (INT16)(sSelMapX + sSelMapY*(MAP_WORLD_X)); + } } - }*/ + } - // we can actually fail here if there aren't any slots left - if ( !MilitiaPlotStart( ) ) + // if we don't use a previously existing group and can't creae a new one, abort + if ( !fGroupAlreadyExists && !MilitiaPlotStart( ) ) { return FALSE; } @@ -16679,20 +16684,25 @@ void DeleteAllMilitiaPaths() } } -// if a militia group is in this sector, return TRUE, group id will be stored in arId -BOOLEAN GetMilitiaGroupInSector( INT16 sMapX, INT16 sMapY, UINT8& arId ) +// return the last militia group in this sector, group id will be stored in arId. return FALSE if none found +BOOLEAN GetLastMilitiaGroupInSector( INT16 sMapX, INT16 sMapY, UINT8& arId ) { + BOOLEAN fFound = FALSE; + GROUP *pGroup = gpGroupList; while ( pGroup ) { if ( pGroup->usGroupTeam == MILITIA_TEAM && pGroup->ubSectorX == sMapX && pGroup->ubSectorY == sMapY ) { arId = pGroup->ubGroupID; - return TRUE; + fFound = TRUE; } pGroup = pGroup->next; } + if ( fFound ) + return TRUE; + return FALSE; } diff --git a/Strategic/mapscreen.h b/Strategic/mapscreen.h index 2f59d084..7e79cf10 100644 --- a/Strategic/mapscreen.h +++ b/Strategic/mapscreen.h @@ -153,8 +153,8 @@ INT16 GetMilitiaPathSlot(UINT8 uGroupId); void DeleteAllMilitiaPaths(); -// if a militia group is in this sector, return TRUE, group id will be stored in arId -BOOLEAN GetMilitiaGroupInSector( INT16 sMapX, INT16 sMapY, UINT8& arId ); +// return the last militia group in this sector, group id will be stored in arId. return FALSE if none found +BOOLEAN GetLastMilitiaGroupInSector( INT16 sMapX, INT16 sMapY, UINT8& arId ); BOOLEAN CanGiveStrategicMilitiaMoveOrder( INT16 sMapX, INT16 sMapY );