From f5ac5be03f1c343deb00cfba06c97e4b2f10c29c Mon Sep 17 00:00:00 2001 From: Kriplo Date: Tue, 10 Sep 2013 20:49:49 +0000 Subject: [PATCH] Brief: //dnl ch68 - Magically appeared reinforcements for enemy and militia just turn after they are called from now could be delayed and randomized. Details: - Practically all enemy reinforcement which can populate available slots was always appeared next turn after they are called so now we have game settings under "Strategic Gameplay Settings" for fine tunning enemy and militia reinforce entry: MIN_DELAY_ENEMY_REINFORCEMENTS enemy reinforcement will arrive minimum this number of turns after they are called, if 0 then is disabled. RND_DELAY_ENEMY_REINFORCEMENTS additional random delay added to minimum when reinforcements will arrive after they are called. MIN_ENTER_ENEMY_REINFORCEMENTS minimum enemy units which will enter after above delay is over. RND_ENTER_ENEMY_REINFORCEMENTS additional random enemy units to appear after passing delay. MIN_DELAY_MILITIA_REINFORCEMENTS enemy reinforcement will arrive minimum this number of turns after they are called, if 0 then is disabled. RND_DELAY_MILITIA_REINFORCEMENTS additional random delay added to minimum when reinforcements will arrive after they are called. MIN_ENTER_MILITIA_REINFORCEMENTS minimum enemy units which will enter after above delay is over. RND_ENTER_MILITIA_REINFORCEMENTS additional random enemy units to appear after passing delay. - After first delay ends any other reinforcement appeared more frequently or if already arrive (but no free slot), they will pop up soon after slot is free. - Add option NO_REMOVE_RANDOM_SECTOR_ITEMS under "Strategic Gameplay Settings" to prevent permanent random removal of your sector items. - Add missing function DisplaySectorItemsInfo. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6386 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- GameSettings.cpp | 14 +++++++- GameSettings.h | 14 +++++++- SaveLoadGame.cpp | 5 +++ SaveLoadScreen.cpp | 2 +- Standard Gaming Platform/Random.cpp | 2 +- .../Map Screen Interface Map Inventory.cpp | 23 ++++++++++++ Strategic/Queen Command.cpp | 35 +++++++++++++++++++ Strategic/Queen Command.h | 4 ++- Strategic/Reinforcement.cpp | 35 +++++++++++++++++++ Strategic/Strategic Town Loyalty.cpp | 2 ++ Tactical/Tactical Turns.cpp | 1 + Tactical/TeamTurns.cpp | 1 + TileEngine/worldman.cpp | 30 ++++++++-------- 13 files changed, 148 insertions(+), 20 deletions(-) diff --git a/GameSettings.cpp b/GameSettings.cpp index 503d6d1e..4b1ae024 100644 --- a/GameSettings.cpp +++ b/GameSettings.cpp @@ -2015,13 +2015,25 @@ void LoadGameExternalOptions() gGameExternalOptions.fUseXMLSquadNames = iniReader.ReadBoolean("Strategic Assignment Settings", "USE_XML_SQUADNAMES", FALSE); + //dnl ch68 090913 Reinforcements minimum+random turn delay and minimum+random units enter for enemy and militia after they have been called + gGameExternalOptions.sMinDelayEnemyReinforcements = iniReader.ReadInteger("Strategic Gameplay Settings", "MIN_DELAY_ENEMY_REINFORCEMENTS", 7, 0, 100); + gGameExternalOptions.sRndDelayEnemyReinforcements = iniReader.ReadInteger("Strategic Gameplay Settings", "RND_DELAY_ENEMY_REINFORCEMENTS", 8, 0, 100); + gGameExternalOptions.sMinEnterEnemyReinforcements = iniReader.ReadInteger("Strategic Gameplay Settings", "MIN_ENTER_ENEMY_REINFORCEMENTS", 6, 1, 64); + gGameExternalOptions.sRndEnterEnemyReinforcements = iniReader.ReadInteger("Strategic Gameplay Settings", "RND_ENTER_ENEMY_REINFORCEMENTS", 6, 1, 64); + gGameExternalOptions.sMinDelayMilitiaReinforcements = iniReader.ReadInteger("Strategic Gameplay Settings", "MIN_DELAY_MILITIA_REINFORCEMENTS", 10, 0, 100); + gGameExternalOptions.sRndDelayMilitiaReinforcements = iniReader.ReadInteger("Strategic Gameplay Settings", "RND_DELAY_MILITIA_REINFORCEMENTS", 10, 0, 100); + gGameExternalOptions.sMinEnterMilitiaReinforcements = iniReader.ReadInteger("Strategic Gameplay Settings", "MIN_ENTER_MILITIA_REINFORCEMENTS", 6, 1, 64); + gGameExternalOptions.sRndEnterMilitiaReinforcements = iniReader.ReadInteger("Strategic Gameplay Settings", "RND_ENTER_MILITIA_REINFORCEMENTS", 4, 1, 64); + //dnl ch68 090913 Don't allow permanent items removal from sector + gGameExternalOptions.fNoRemoveRandomSectorItems = iniReader.ReadBoolean("Strategic GamePlay Settings", "NO_REMOVE_RANDOM_SECTOR_ITEMS", true, false); + // WANNE: This is just a debug setting. Only in debug version we set that property to TRUE. // In Release version this should always be set to FALSE // dnl ch51 081009 JA2 Debug Settings #ifdef _DEBUG gGameExternalOptions.fEnableInventoryPoolQ = TRUE; #else - gGameExternalOptions.fEnableInventoryPoolQ = FALSE; + gGameExternalOptions.fEnableInventoryPoolQ = FALSE; #endif ////////// CLOCK SETTINGS ////////// diff --git a/GameSettings.h b/GameSettings.h index 7d76179c..58aecdcc 100644 --- a/GameSettings.h +++ b/GameSettings.h @@ -1146,7 +1146,7 @@ typedef struct BOOLEAN fSaveGameSlot; //dnl ch51 081009 JA2 Debug Settings - BOOLEAN fEnableInventoryPoolQ; + BOOLEAN fEnableInventoryPoolQ; //legion by Jazz //BOOLEAN fShowTacticalFaceGear; //legion 2 @@ -1280,6 +1280,18 @@ typedef struct // Flugente: externalised squad names BOOLEAN fUseXMLSquadNames; + //dnl ch68 090913 Reinforcements Setttings + UINT16 sMinDelayEnemyReinforcements; + UINT16 sRndDelayEnemyReinforcements; + UINT16 sMinEnterEnemyReinforcements; + UINT16 sRndEnterEnemyReinforcements; + UINT16 sMinDelayMilitiaReinforcements; + UINT16 sRndDelayMilitiaReinforcements; + UINT16 sMinEnterMilitiaReinforcements; + UINT16 sRndEnterMilitiaReinforcements; + + BOOLEAN fNoRemoveRandomSectorItems;//dnl ch68 090913 + } GAME_EXTERNAL_OPTIONS; typedef struct diff --git a/SaveLoadGame.cpp b/SaveLoadGame.cpp index cf4bff32..fe0f06fa 100644 --- a/SaveLoadGame.cpp +++ b/SaveLoadGame.cpp @@ -5963,6 +5963,11 @@ BOOLEAN LoadSavedGame( int ubSavedGameID ) if(gGameExternalOptions.fEnableInventoryPoolQ)//dnl ch51 081009 if(!LoadInventoryPoolQ(ubSavedGameID)) return(FALSE); + //dnl ch68 100913 // basic guess when reinforcement should arrive after load game as reinforcement globals are not saved + if(guiReinforceTurn) + guiReinforceTurn = guiTurnCnt + gGameExternalOptions.sMinDelayEnemyReinforcements/2 + Random(gGameExternalOptions.sRndDelayEnemyReinforcements+1); + if(guiMilitiaReinforceTurn) + guiMilitiaReinforceTurn = guiTurnCnt + gGameExternalOptions.sMinDelayMilitiaReinforcements/2 + Random(gGameExternalOptions.sRndDelayMilitiaReinforcements+1); //now change the savegame format so that temp files are saved and loaded correctly guiCurrentSaveGameVersion = SAVE_GAME_VERSION; diff --git a/SaveLoadScreen.cpp b/SaveLoadScreen.cpp index f23352ee..444a4e25 100644 --- a/SaveLoadScreen.cpp +++ b/SaveLoadScreen.cpp @@ -2921,4 +2921,4 @@ BOOLEAN LoadDataSaveFromLoadGameFile( HWFILE hFile ) } return( TRUE ); -} +} diff --git a/Standard Gaming Platform/Random.cpp b/Standard Gaming Platform/Random.cpp index 99295a1b..c4d4fe88 100644 --- a/Standard Gaming Platform/Random.cpp +++ b/Standard Gaming Platform/Random.cpp @@ -92,4 +92,4 @@ void InitializeRandom() guiPreRandomIndex = 0; } -#endif +#endif diff --git a/Strategic/Map Screen Interface Map Inventory.cpp b/Strategic/Map Screen Interface Map Inventory.cpp index b5a9b23c..888ab3c0 100644 --- a/Strategic/Map Screen Interface Map Inventory.cpp +++ b/Strategic/Map Screen Interface Map Inventory.cpp @@ -3450,6 +3450,9 @@ BOOLEAN CanPlayerUseSectorInventory( SOLDIERTYPE *pSelectedSoldier ) { INT16 sSectorX, sSectorY, sSectorZ; + if(gGameExternalOptions.fEnableInventoryPoolQ)//dnl ch51 200813 + return(TRUE); + //Get the sector that has a battle BOOLEAN fInCombat = GetCurrentBattleSectorXYZAndReturnTRUEIfThereIsABattle( &sSectorX, &sSectorY, &sSectorZ ); @@ -3723,6 +3726,26 @@ BOOLEAN CopySectorInventoryToInventoryPoolQs(UINT8 idx) fMapPanelDirty = TRUE; return(TRUE); } + +BOOLEAN DisplaySectorItemsInfo(void)//dnl ch51 090913 +{ + INT32 iCounter, iItemCount, iItemTraps; + WORLDITEM *pWorldItem; + + iItemCount = 0; + iItemTraps = 0; + for(iCounter=0; (UINT32)iCounterbVisible<=0 && pWorldItem->fExists && !(pWorldItem->object.usItem==NOTHING || pWorldItem->object.usItem==SWITCH || pWorldItem->object.usItem==ACTION_ITEM || pWorldItem->object.usItem==OWNERSHIP || pWorldItem->object.usItem==SYRINGE_3 || pWorldItem->object.usItem==SYRINGE_4 || pWorldItem->object.usItem==SYRINGE_5)) + iItemCount++; + if(/*pWorldItem->object[0]->data.bTrap > 0 && (pWorldItem->usFlags & WORLD_ITEM_ARMED_BOMB) && */pWorldItem->object[0]->data.misc.usBombItem) + iItemTraps++; +// SendFmtMsg("Item%.4d:%4d %d %.4X %.4X %.2X %.2X %.2X %d", iCounter, pWorldItem->bVisible, pWorldItem->fExists, pWorldItem->sGridNo, pWorldItem->usFlags, pWorldItem->object[0]->data.bTrap, pWorldItem->object[0]->data.fUsed, pWorldItem->object[0]->data.misc.usBombItem, pWorldItem->object.usItem); + } + ScreenMsg(FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"%d unseen items and %d boobytraps left.", iItemCount, iItemTraps); + return(TRUE); +} //dnl ch51 081009 finish void DeleteAllItemsInInventoryPool() diff --git a/Strategic/Queen Command.cpp b/Strategic/Queen Command.cpp index b11ac05d..e0fee489 100644 --- a/Strategic/Queen Command.cpp +++ b/Strategic/Queen Command.cpp @@ -73,6 +73,7 @@ std::vector SectorInfo (256); UNDERGROUND_SECTORINFO *gpUndergroundSectorInfoHead = NULL; extern UNDERGROUND_SECTORINFO* gpUndergroundSectorInfoTail; BOOLEAN gfPendingEnemies = FALSE; +UINT32 guiTurnCnt = 0, guiReinforceTurn = 0, guiArrived = 0;//dnl ch68 080913 extern void BuildUndergroundSectorInfoList(); extern void EndCreatureQuest(); @@ -1390,6 +1391,40 @@ void AddPossiblePendingEnemiesToBattle() || !NumEnemiesInSector( gWorldSectorX, gWorldSectorY ) ) return; ubSlots = NumFreeEnemySlots(); + if(gGameExternalOptions.sMinDelayEnemyReinforcements)//dnl ch68 080913 + { + if(gTacticalStatus.Team[ENEMY_TEAM].bAwareOfOpposition == TRUE) + { + if(guiReinforceTurn == 0) + { + guiReinforceTurn = guiTurnCnt + gGameExternalOptions.sMinDelayEnemyReinforcements + Random(gGameExternalOptions.sRndDelayEnemyReinforcements+1);// first possible reinforcement + ubSlots = 0; + } + else if(guiTurnCnt >= guiReinforceTurn) + { + guiReinforceTurn = guiTurnCnt + gGameExternalOptions.sMinDelayEnemyReinforcements/3 + Random(gGameExternalOptions.sRndDelayEnemyReinforcements+1);// any other reinforcement should appear more frequently + ubNumAvailable = gGameExternalOptions.sMinEnterEnemyReinforcements + Random(gGameExternalOptions.sRndEnterEnemyReinforcements+1);// total allowed units to enter per reinforce turn +//SendFmtMsg("Enemy reinforcements: ubSlots=%d ubNumAvailable=%d", ubSlots, ubNumAvailable); + if(ubSlots > ubNumAvailable) + ubSlots = ubNumAvailable; + guiArrived += (ubNumAvailable - ubSlots); + } + else + { + if(guiArrived > 0) + { + if(ubSlots > guiArrived) + ubSlots = guiArrived; + guiArrived -= ubSlots; + } + else + ubSlots = 0; + } + } + else + guiReinforceTurn = guiArrived = 0; +//SendFmtMsg("Enemy reinforcements: guiTurnCnt=%d guiReinforceTurn=%d guiArrived=%d", guiTurnCnt, guiReinforceTurn, guiArrived); + } if( !ubSlots ) { //no available slots to add enemies to. Try again later... return; diff --git a/Strategic/Queen Command.h b/Strategic/Queen Command.h index cb93e1ba..9299d1ea 100644 --- a/Strategic/Queen Command.h +++ b/Strategic/Queen Command.h @@ -62,4 +62,6 @@ extern INT32 gsGridNoForMapEdgePointInfo; BOOLEAN CheckPendingEnemies(); -#endif \ No newline at end of file +extern UINT32 guiTurnCnt, guiReinforceTurn, guiMilitiaReinforceTurn;//dnl ch68 080913 + +#endif diff --git a/Strategic/Reinforcement.cpp b/Strategic/Reinforcement.cpp index b9a46b56..c8640378 100644 --- a/Strategic/Reinforcement.cpp +++ b/Strategic/Reinforcement.cpp @@ -29,6 +29,7 @@ #include "MilitiaSquads.h" UINT8 gubReinforcementMinEnemyStaticGroupSize = 12; +UINT32 guiMilitiaReinforceTurn = 0, guiMilitiaArrived = 0;//dnl ch68 090913 void GetNumberOfEnemiesInFiveSectors( INT16 sSectorX, INT16 sSectorY, UINT8 *pubNumAdmins, UINT8 *pubNumTroops, UINT8 *pubNumElites ) { @@ -399,6 +400,40 @@ void AddPossiblePendingMilitiaToBattle() return; //gGameExternalOptions.guiMaxMilitiaSquadSize - CountAllMilitiaInSector( gWorldSectorX, gWorldSectorY ); ubSlots = NumFreeMilitiaSlots(); + if(gGameExternalOptions.sMinDelayMilitiaReinforcements)//dnl ch68 090913 + { + if(gTacticalStatus.Team[MILITIA_TEAM].bAwareOfOpposition == TRUE) + { + if(guiMilitiaReinforceTurn == 0) + { + guiMilitiaReinforceTurn = guiTurnCnt + gGameExternalOptions.sMinDelayMilitiaReinforcements + Random(gGameExternalOptions.sRndDelayMilitiaReinforcements+1);// first possible reinforcement + ubSlots = 0; + } + else if(guiTurnCnt >= guiMilitiaReinforceTurn) + { + guiMilitiaReinforceTurn = guiTurnCnt + gGameExternalOptions.sMinDelayMilitiaReinforcements/3 + Random(gGameExternalOptions.sRndDelayMilitiaReinforcements+1);// any other reinforcement should appear more frequently + UINT8 ubNumAvailable = gGameExternalOptions.sMinEnterMilitiaReinforcements + Random(gGameExternalOptions.sRndEnterMilitiaReinforcements+1);// total allowed units to enter per reinforce turn +//SendFmtMsg("Militia reinforcements: ubSlots=%d ubNumAvailable=%d", ubSlots, ubNumAvailable); + if(ubSlots > ubNumAvailable) + ubSlots = ubNumAvailable; + guiMilitiaArrived += (ubNumAvailable - ubSlots); + } + else + { + if(guiMilitiaArrived > 0) + { + if(ubSlots > guiMilitiaArrived) + ubSlots = guiMilitiaArrived; + guiMilitiaArrived -= ubSlots; + } + else + ubSlots = 0; + } + } + else + guiMilitiaReinforceTurn = guiMilitiaArrived = 0; +//SendFmtMsg("Militia reinforcements: guiTurnCnt=%d guiReinforceTurn=%d guiArrived=%d", guiTurnCnt, guiMilitiaReinforceTurn, guiMilitiaArrived); + } if( !ubSlots ) { //no available slots to add militia to. Try again later... return; diff --git a/Strategic/Strategic Town Loyalty.cpp b/Strategic/Strategic Town Loyalty.cpp index b2d106a8..a29f64d4 100644 --- a/Strategic/Strategic Town Loyalty.cpp +++ b/Strategic/Strategic Town Loyalty.cpp @@ -1115,6 +1115,8 @@ void RemoveRandomItemsInSector( INT16 sSectorX, INT16 sSectorY, INT16 sSectorZ, UINT32 uiNewTotal = 0; CHAR16 wSectorName[ 128 ]; + if(gGameExternalOptions.fNoRemoveRandomSectorItems)//dnl ch68 090913 + return; // stealing should fail anyway 'cause there shouldn't be a temp file for unvisited sectors, but let's check anyway Assert( GetSectorFlagStatus( sSectorX, sSectorY, ( UINT8 ) sSectorZ, SF_ALREADY_VISITED ) == TRUE ); diff --git a/Tactical/Tactical Turns.cpp b/Tactical/Tactical Turns.cpp index 95e4715b..57f89090 100644 --- a/Tactical/Tactical Turns.cpp +++ b/Tactical/Tactical Turns.cpp @@ -175,6 +175,7 @@ void HandleTacticalEndTurn( ) // decay AI warning values from corpses DecayRottingCorpseAIWarnings(); + ((gTacticalStatus.Team[ENEMY_TEAM].bTeamActive || gTacticalStatus.Team[MILITIA_TEAM].bTeamActive) ? (guiTurnCnt++) : (guiTurnCnt = 0));//dnl ch68 090913 //Check for enemy pooling (add enemies if there happens to be more than the max in the //current battle. If one or more slots have freed up, we can add them now. AddPossiblePendingEnemiesToBattle(); diff --git a/Tactical/TeamTurns.cpp b/Tactical/TeamTurns.cpp index 6b308c27..9322c584 100644 --- a/Tactical/TeamTurns.cpp +++ b/Tactical/TeamTurns.cpp @@ -325,6 +325,7 @@ void EndTurn( UINT8 ubNextTeam ) } else { + guiTurnCnt++;//dnl ch68 080913 // Flugente: I'm not really sure why we check here for gGameExternalOptions.ubReinforcementsFirstTurnFreeze, shouldn't that be a check for ALLOW_REINFORCEMENTS? // as this inhibits reinforcements during turnbased-mode, I'll check for that instead // HEADROCK HAM 3.2: Experimental fix to force reinforcements enter battle with 0 APs. diff --git a/TileEngine/worldman.cpp b/TileEngine/worldman.cpp index b45e50e0..8990a844 100644 --- a/TileEngine/worldman.cpp +++ b/TileEngine/worldman.cpp @@ -3625,21 +3625,21 @@ LEVELNODE * FindShadow( INT32 sGridNo, UINT16 usStructIndex ) // WANNE: Improved v1.13 version to find the shadow tile. (by Realist) // This should fix the bug, finding and swapping shadows when swapping structures // e.g: When curring a fence tile, the shadow tile was not swapped. Now it should be fixed. -LEVELNODE* FindShadow(INT32 sGridNo, UINT16 usStructIndex) -{ - TILE_ELEMENT const * const te = &gTileDatabase[usStructIndex]; - if (te->uiFlags & HAS_SHADOW_BUDDY && te->sBuddyNum != -1) - { - LEVELNODE* pLevelNode; - for (pLevelNode = gpWorldLevelData[sGridNo].pShadowHead; pLevelNode != NULL; pLevelNode = pLevelNode->pNext) - { - if (pLevelNode->usIndex == te->sBuddyNum) - { - return pLevelNode; - } - } - } - return NULL; +LEVELNODE* FindShadow(INT32 sGridNo, UINT16 usStructIndex) +{ + TILE_ELEMENT const * const te = &gTileDatabase[usStructIndex]; + if (te->uiFlags & HAS_SHADOW_BUDDY && te->sBuddyNum != -1) + { + LEVELNODE* pLevelNode; + for (pLevelNode = gpWorldLevelData[sGridNo].pShadowHead; pLevelNode != NULL; pLevelNode = pLevelNode->pNext) + { + if (pLevelNode->usIndex == te->sBuddyNum) + { + return pLevelNode; + } + } + } + return NULL; }