diff --git a/Editor/edit_sys.cpp b/Editor/edit_sys.cpp index bebaa10ca..35bc60558 100644 --- a/Editor/edit_sys.cpp +++ b/Editor/edit_sys.cpp @@ -1171,6 +1171,13 @@ void RaiseWorldLand( ) while( pStruct ) { + // Skip cached tiles + if (pStruct->usIndex >= NUMBEROFTILES) + { + pStruct = pStruct->pNext; + continue; + } + pTileElement = &(gTileDatabase[ pStruct->usIndex ]); if (pTileElement->fType==FIRSTCLIFF) { diff --git a/Standard Gaming Platform/video.cpp b/Standard Gaming Platform/video.cpp index 8a2f4b756..2cf3b1874 100644 --- a/Standard Gaming Platform/video.cpp +++ b/Standard Gaming Platform/video.cpp @@ -2239,6 +2239,12 @@ void RefreshScreen(void *DummyVariable) NULL); if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) { + // Prevent the minimizing bug + if (ReturnCode == DDERR_INVALIDRECT) + { + return; + } + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); if (ReturnCode == DDERR_SURFACELOST) @@ -2266,6 +2272,12 @@ void RefreshScreen(void *DummyVariable) if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) { + // Prevent the minimizing bug + if (ReturnCode == DDERR_INVALIDRECT) + { + return; + } + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); if (ReturnCode == DDERR_SURFACELOST) diff --git a/Strategic/Auto Resolve.cpp b/Strategic/Auto Resolve.cpp index a035609ab..e203164f3 100644 --- a/Strategic/Auto Resolve.cpp +++ b/Strategic/Auto Resolve.cpp @@ -66,6 +66,7 @@ #include "Assignments.h" #include "cheats.h" #include "Map Information.h" + #include "MilitiaSquads.h" #endif #include "Reinforcement.h" @@ -1954,12 +1955,95 @@ void RenderAutoResolve() InvalidateScreen(); } +static void ARCreateMilitia( UINT8 mclass, INT32 i, INT16 sX, INT16 sY) +{ + // reset counter of how many mortars this team has rolled + ResetMortarsOnTeamCount(); + + if( mclass == SOLDIER_CLASS_ELITE_MILITIA ) + { + gpCivs[i].pSoldier = TacticalCreateMilitia( SOLDIER_CLASS_ELITE_MILITIA ); + if( gpCivs[i].pSoldier->ubBodyType == REGFEMALE ) + { + gpCivs[i].usIndex = MILITIA3F_FACE; + } + else + { + gpCivs[i].usIndex = MILITIA3_FACE; + } + } + else if( mclass == SOLDIER_CLASS_REG_MILITIA ) + { + gpCivs[i].pSoldier = TacticalCreateMilitia( SOLDIER_CLASS_REG_MILITIA ); + if( gpCivs[i].pSoldier->ubBodyType == REGFEMALE ) + { + gpCivs[i].usIndex = MILITIA2F_FACE; + } + else + { + gpCivs[i].usIndex = MILITIA2_FACE; + } + } + else if( mclass == SOLDIER_CLASS_GREEN_MILITIA ) + { + gpCivs[i].pSoldier = TacticalCreateMilitia( SOLDIER_CLASS_GREEN_MILITIA ); + if( gpCivs[i].pSoldier->ubBodyType == REGFEMALE ) + { + gpCivs[i].usIndex = MILITIA1F_FACE; + } + else + { + gpCivs[i].usIndex = MILITIA1_FACE; + } + } + else + { + AssertMsg( 0, "Attempting to illegally create a militia soldier." ); + } + if( !gpCivs[ i ].pSoldier ) + { + AssertMsg( 0, "Failed to create militia soldier for autoresolve." ); + } + gpCivs[i].uiVObjectID = gpAR->iFaces; + gpCivs[i].pSoldier->sSectorX = sX; + gpCivs[i].pSoldier->sSectorY = sY; + swprintf( gpCivs[i].pSoldier->name, gpStrategicString[ STR_AR_MILITIA_NAME ] ); +} + +static void ARCreateMilitiaSquad( UINT8 *cnt, UINT8 ubEliteMilitia, UINT8 ubRegMilitia, UINT8 ubGreenMilitia, INT16 sX, INT16 sY) +{ + while( *cnt < gpAR->ubCivs && (ubEliteMilitia || ubRegMilitia || ubGreenMilitia) ) + { + if (ubEliteMilitia) + { + ARCreateMilitia( SOLDIER_CLASS_ELITE_MILITIA, *cnt, sX, sY); + ubEliteMilitia--; + } + else if (ubRegMilitia) + { + ARCreateMilitia( SOLDIER_CLASS_REG_MILITIA, *cnt, sX, sY); + ubRegMilitia--; + } + else if (ubGreenMilitia) + { + ARCreateMilitia( SOLDIER_CLASS_GREEN_MILITIA, *cnt, sX, sY); + ubGreenMilitia--; + } + + (*cnt)++; + } +} + void CreateAutoResolveInterface() { VOBJECT_DESC VObjectDesc; INT32 i, index; HVOBJECT hVObject; UINT8 ubGreenMilitia, ubRegMilitia, ubEliteMilitia; + UINT16 pMoveDir[4][3]; + UINT8 uiDirNumber = 0; + UINT8 cnt; + //Setup new autoresolve blanket interface. MSYS_DefineRegion( &gpAR->AutoResolveRegion, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, MSYS_PRIORITY_HIGH-1, 0, MSYS_NO_CALLBACK, MSYS_NO_CALLBACK ); @@ -2049,9 +2133,18 @@ void CreateAutoResolveInterface() } } - ubEliteMilitia = MilitiaInFiveSectorsOfRank( gpAR->ubSectorX, gpAR->ubSectorY, ELITE_MILITIA ); - ubRegMilitia = MilitiaInFiveSectorsOfRank( gpAR->ubSectorX, gpAR->ubSectorY, REGULAR_MILITIA ); - ubGreenMilitia = MilitiaInFiveSectorsOfRank( gpAR->ubSectorX, gpAR->ubSectorY, GREEN_MILITIA ); + // 0verhaul: The following code was modified so that militia bookkeeping could be handled. + // In the previous auto-resolve method, promotions were often lost because the sector did not + // actually have the militia to be promoted--they came from surrounding sectors. The + // sector X and Y are not actually used for auto-resolve itself, so I can use it to adjust + // both the actual sector counts and the promotions, by using the origin sectors of each + // soldier. + ubEliteMilitia = MilitiaInSectorOfRank( gpAR->ubSectorX, gpAR->ubSectorY, ELITE_MILITIA ); + ubRegMilitia = MilitiaInSectorOfRank( gpAR->ubSectorX, gpAR->ubSectorY, REGULAR_MILITIA ); + ubGreenMilitia = MilitiaInSectorOfRank( gpAR->ubSectorX, gpAR->ubSectorY, GREEN_MILITIA ); + + // This block should be unnecessary. If the counts do not line up, there is a bug. +#if 0 while( ubEliteMilitia + ubRegMilitia + ubGreenMilitia < gpAR->ubCivs ) { switch( PreRandom( 3 ) ) @@ -2061,60 +2154,27 @@ void CreateAutoResolveInterface() case 2: ubGreenMilitia++; break; } } - for( i = 0; i < gpAR->ubCivs; i++ ) - { - // reset counter of how many mortars this team has rolled - ResetMortarsOnTeamCount(); +#endif - if( i < ubEliteMilitia ) - { - gpCivs[i].pSoldier = TacticalCreateMilitia( SOLDIER_CLASS_ELITE_MILITIA ); - if( gpCivs[i].pSoldier->ubBodyType == REGFEMALE ) - { - gpCivs[i].usIndex = MILITIA3F_FACE; - } - else - { - gpCivs[i].usIndex = MILITIA3_FACE; - } - } - else if( i < ubRegMilitia + ubEliteMilitia ) - { - gpCivs[i].pSoldier = TacticalCreateMilitia( SOLDIER_CLASS_REG_MILITIA ); - if( gpCivs[i].pSoldier->ubBodyType == REGFEMALE ) - { - gpCivs[i].usIndex = MILITIA2F_FACE; - } - else - { - gpCivs[i].usIndex = MILITIA2_FACE; - } - } - else if( i < ubGreenMilitia + ubRegMilitia + ubEliteMilitia ) - { - gpCivs[i].pSoldier = TacticalCreateMilitia( SOLDIER_CLASS_GREEN_MILITIA ); - if( gpCivs[i].pSoldier->ubBodyType == REGFEMALE ) - { - gpCivs[i].usIndex = MILITIA1F_FACE; - } - else - { - gpCivs[i].usIndex = MILITIA1_FACE; - } - } - else - { - AssertMsg( 0, "Attempting to illegally create a militia soldier." ); - } - if( !gpCivs[ i ].pSoldier ) - { - AssertMsg( 0, "Failed to create militia soldier for autoresolve." ); - } - gpCivs[i].uiVObjectID = gpAR->iFaces; - gpCivs[i].pSoldier->sSectorX = gpAR->ubSectorX; - gpCivs[i].pSoldier->sSectorY = gpAR->ubSectorY; - swprintf( gpCivs[i].pSoldier->name, gpStrategicString[ STR_AR_MILITIA_NAME ] ); + cnt = 0; + // Add the militia in this sector + ARCreateMilitiaSquad( &cnt, ubEliteMilitia, ubRegMilitia, ubGreenMilitia, gpAR->ubSectorX, gpAR->ubSectorY); + + // Add the militia in the surrounding sectors + GenerateDirectionInfos( gpAR->ubSectorX, gpAR->ubSectorY, &uiDirNumber, pMoveDir, + ( GetTownIdForSector( gpAR->ubSectorX, gpAR->ubSectorY ) != BLANK_SECTOR ? TRUE : FALSE ), TRUE, FALSE ); + for( i=0; iubElites; i++, index++ ) @@ -2391,8 +2451,8 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Autoresolve2"); if( fDeleteForGood && gpCivs[ i ].pSoldier->bLife < OKLIFE/2 ) { AddDeadSoldierToUnLoadedSector( gpAR->ubSectorX, gpAR->ubSectorY, 0, gpCivs[ i ].pSoldier, RandomGridNo(), ADD_DEAD_SOLDIER_TO_SWEETSPOT ); -// StrategicRemoveMilitiaFromSector( gpAR->ubSectorX, gpAR->ubSectorY, ubCurrentRank, 1 ); - ARRemoveMilitiaMan( gpAR->ubSectorX, gpAR->ubSectorY, ubCurrentRank ); + StrategicRemoveMilitiaFromSector( gpCivs[ i ].pSoldier->sSectorX, gpCivs[ i ].pSoldier->sSectorY, ubCurrentRank, 1 ); +// ARRemoveMilitiaMan( gpAR->ubSectorX, gpAR->ubSectorY, ubCurrentRank ); if( ProcessLoyalty() )HandleGlobalLoyaltyEvent( GLOBAL_LOYALTY_NATIVE_KILLED, gpAR->ubSectorX, gpAR->ubSectorY, 0 ); } else @@ -2401,7 +2461,7 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Autoresolve2"); // this will check for promotions and handle them for you if( fDeleteForGood && ( gpCivs[ i ].pSoldier->ubMilitiaKills > 0) && ( ubCurrentRank < ELITE_MILITIA ) ) { - ubPromotions = CheckOneMilitiaForPromotion( gpAR->ubSectorX, gpAR->ubSectorY, ubCurrentRank, gpCivs[ i ].pSoldier->ubMilitiaKills ); + ubPromotions = CheckOneMilitiaForPromotion( gpCivs[ i ].pSoldier->sSectorX, gpCivs[ i ].pSoldier->sSectorY, ubCurrentRank, gpCivs[ i ].pSoldier->ubMilitiaKills ); if( ubPromotions ) { if( ubPromotions == 2 ) diff --git a/Strategic/Strategic Movement.cpp b/Strategic/Strategic Movement.cpp index 3e19c6d30..b31bd8d43 100644 --- a/Strategic/Strategic Movement.cpp +++ b/Strategic/Strategic Movement.cpp @@ -690,6 +690,24 @@ GROUP* CreateNewEnemyGroupDepartingFromSector( UINT32 uiSector, UINT8 ubNumAdmin pNew->pEnemyGroup = (ENEMYGROUP*)MemAlloc( sizeof( ENEMYGROUP ) ); AssertMsg( pNew->pEnemyGroup, "MemAlloc failure during enemy group creation." ); memset( pNew->pEnemyGroup, 0, sizeof( ENEMYGROUP ) ); + + // Make sure group is not bigger than allowed! + while (ubNumAdmins + ubNumTroops + ubNumElites > gGameExternalOptions.iMaxEnemyGroupSize) + { + if (ubNumTroops) + { + ubNumTroops--; + } + else if (ubNumAdmins) + { + ubNumAdmins--; + } + else + { + ubNumElites--; + } + } + pNew->pWaypoints = NULL; pNew->ubSectorX = (UINT8)SECTORX( uiSector ); pNew->ubSectorY = (UINT8)SECTORY( uiSector ); @@ -702,7 +720,7 @@ GROUP* CreateNewEnemyGroupDepartingFromSector( UINT32 uiSector, UINT8 ubNumAdmin pNew->pEnemyGroup->ubNumAdmins = ubNumAdmins; pNew->pEnemyGroup->ubNumTroops = ubNumTroops; pNew->pEnemyGroup->ubNumElites = ubNumElites; - pNew->ubGroupSize = (UINT8)(ubNumTroops + ubNumElites); + pNew->ubGroupSize = (UINT8)(ubNumAdmins + ubNumTroops + ubNumElites); pNew->ubTransportationMask = FOOT; pNew->fVehicle = FALSE; pNew->ubCreatedSectorID = pNew->ubOriginalSector; diff --git a/builddefines.h b/builddefines.h index 8fc4eef46..e5ee732a7 100644 --- a/builddefines.h +++ b/builddefines.h @@ -13,8 +13,6 @@ //#define DEBUG_ATTACKBUSY -//#define LUACONSOLE - #define ROBOT_ALWAYS_READY //#ifdef _DEBUG diff --git a/ja2_2005Express.vcproj b/ja2_2005Express.vcproj index 5623e8e5c..bd0938362 100644 --- a/ja2_2005Express.vcproj +++ b/ja2_2005Express.vcproj @@ -1,7 +1,7 @@