Files
source/Strategic/Hourly Update.cpp
T
Wanne e64d5a2fa6 MERGED source code from development trunk revision 4545 up to latest current revision 4882
Development Trunk: https://ja2svn.dyndns.org/source/ja2/branches/Wanne/JA2%201.13%20MP
A detailed list of all the features (changes) is visible in the history log of the development trunk:

INFO: The source code for the official 2011 release (4870) has been branched here:
https://ja2svn.dyndns.org/source/ja2/branches/JA2_rev.4870_2011

This commit contains the following features:

*** Externalized Vehicles ***
o Now with this feature we can add/remove vehicles
o New XML File: TableData\Vehicles.xml
o Added a new function parameter to lua file Scripts\Overhead lua to set up the helicopter in method: SetUpHelicopterForPlayer()
o Added example mini (Docs\Externalized Vehicles Example.zip) mod which adds 2 additional vehicles (hummer and ice-cream truck to sector A9)

*** Up to 255 save slots ***
- There is a "Next" and "Prev" button where you can scroll through the save slots
- It is now possible to load the automatic save (SAVE_EVERY_N_HOURS) from the load screen. This is the first slot after the quickload slot
- Added the 2 alternate players end turn saves (which can be enabled/disabled in option screen) to the save/load game form

*** New Feature: Externalized emails from Emails.edt to XML***
o This feature can be enabled/disabled in the Source:
--> See email.cpp: If "ReadXMLEmail" == FALSE, then normal way (read from Email.edt) otherwise read from XML files
o 2 new XML files: TableData\Email\EmailMercAvailable.xml and EmailMercLevelUp.xml
o Renamed SenderNamesList.xml to EmailSenderNamesList.xml and moved from TableData folder to TableData\Email folder
o Names for mercenaries are get from the file MercProfiles.xml and different names get from the file EmailSenderNamesList.xml

*** Externalized Hidden Towns (Tixa, Orta) ***
o Now it is possible to add new hidden towns (locations)
o See file: TableData/Map/Cities.xml
o New variable in TableData/Map/Cities.xml
- hiddenTown:   0 = show on strategy map, 1 = Hide on strategy map
- townIcon:     1 = on, 0 = off (This is the icon you see on the strategy map)
- szIconFile:   The path to the sti icon file (eg: interface\prison.sti, interface\my_icon.sti)
- iconPosition: The x,y position of the icon on the strategy map

*** Encyclopedia and Briefing Room, reachable from the laptop ***
o 2 new ja2_options.ini properties: BRIEFING_ROOM, ENCYCLOPEDIA
o demonstration video: http://www.youtube.com/watch?v=7CIXdXWLrAo
o Added Example usage of the Briefing Room
- Extract it in your JA2 1.13 folder and use the latest development executable
- The briefing room can be reached from the laptop. Enter SN5631 for the code and then click the "Exit" button
- See "Info_BriefingRoom.txt" and "BriefingRoom_Mission1.png"

*** Improved interrupt system (IIS) ***
o This system changes the way interrupts work. See: http://www.ja-galaxy-forum.com/board/ubbthreads.php?ubb=showflat&Number=290787#Post290787
o Option system (see ja2_options.ini: IMPROVED_INTERRUPT_SYSTEM)
o A few more settings for the interrupt system in ja2_options.ini
o INFO: Multiplayer games always use the "old" interrupt system, not matter what the user selects in the ja2_options.ini

*** Walking and sidestepping with weapon raised ***
o Enable/disable the walking/sidestepping with raised weapon in ja2_options.ini: ALLOW_WALKING_WITH_WEAPON_RAISED
o You can set an AP/BP modifier when walking/sidestepping with weapon raised in APBPConstants.ini: AP_MODIFIER_WEAPON_READY
o The following feature apply when you walk/sidestep with weapon raised:
-> limited angle of view, but you can see more farther when the weapon has a scope
-> better change for interrupts if you see an enemy
-> less APs and BPs when shooting, because the weapon is already raised
-> It should cost more APs when walking. Maybe you can export the additional AP and BP modifier to the APBPConstants.ini

*** Increase squad size to 8 (800x600) and 8 and 10 (1024x768) ***
o Squad sizes (dependend on the screen resolution) can be selected in the start new game screen
o In a multiplayer game, the squad size will always be 6, because it does not work with more soldiers/squad

*** Added UB-1.13 source code ***
o Merged the UB-1.13 source code (Revision: 4721) from svn: http://subversion.assembla.com/svn/ub-source113
o If you want to build UB-EXE or UB-MapEditor, just enable the 2 defines (JA2UB and JA2UBMAPS) in "builddefines.h"
o The UB-Verion reads from "ja2_UB.ini" instead of "ja2.ini"
o There are 2 new XML files
- Layout\LayoutMainMenu.xml
- MapAction\ActionItems.xml
o There are 2 new LUA-Script files
- Scripts\ExplosionControl.lua
- Scripts\InterfaceDialogue.lua

*** Hide enemy health text / enemy hit count ***
o ja2_options.ini: HIDE_ENEMY_HEALTH_TEXT, HIDE_ENEMY_HIT_COUNT
o both new settings only have effect in a singleplayer game
o see: http://www.ja-galaxy-forum.com/board/ubbthreads.php?ubb=showflat&Number=128840&page=1


git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@4885 3b4a5df2-a311-0410-b5c6-a8a6f20db521
2012-01-18 11:19:01 +00:00

472 lines
13 KiB
C++

#ifdef PRECOMPILEDHEADERS
#include "Strategic All.h"
#else
#include "Assignments.h"
#include "Strategic Town Loyalty.h"
#include "Strategic Merc Handler.h"
#include "Strategic Mines.h"
#include "Campaign.h"
#include "Morale.h"
#include "Quests.h"
#include "Game Clock.h"
#include "Overhead.h"
#include "Boxing.h"
#include "jascreens.h"
#include "screenids.h"
#include "Items.h"
#include "Random.h"
#include "finances.h"
#include "history.h"
#include "Dialogue Control.h"
#include "Strategic AI.h"
#endif
#include "Luaglobal.h"
#include "LuaInitNPCs.h"
#include "SaveLoadGame.h"
#include "GameSettings.h"
#include "connect.h"
#include "Options Screen.h"
#include "SaveLoadScreen.h"
#include "Text.h"
// HEADROCK HAM 3.5: Add facility code for hourly update of detection levels
#include "Facilities.h"
void HourlyQuestUpdate( void );
void HourlyLarryUpdate( void );
extern INT32 GetCurrentBalance( void );
extern void PayOffSkyriderDebtIfAny( );
#ifdef JA2UB
//no UB
#else
void HourlyCheckIfSlayAloneSoHeCanLeave();
#endif
void UpdateRegenCounters( void );
void HandleMinuteUpdate()
{
}
// This function gets called every hour, on the hour.
// It spawns the handling of all sorts of stuff:
// Morale changes, assignment progress, town loyalties, etc.
void HandleHourlyUpdate()
{
CHAR16 zString[128];
//if the game hasnt even started yet ( we havent arrived in the sector ) dont process this
if ( DidGameJustStart() )
return;
if(is_networked)
return;
// hourly update of town loyalty
HandleTownLoyalty();
// hourly update of team assignments
UpdateAssignments();
// HEADROCK HAM 3.5: Tells the rest of the program whether we've got mercs working on detecting enemy units.
UpdateStrategicDetectionLevel();
// HEADROCK HAM 3.5: Re-calculates a modifier to Skyrider's flight costs based on mercs working in specific facilities.
UpdateSkyriderCostModifier();
// hourly update of hated/liked mercs
UpdateBuddyAndHatedCounters();
HandleHourlyRisks();
// update morale!
HourlyMoraleUpdate();
// degrade camouflage
HourlyCamouflageUpdate();
// check mines for monster infestation/extermination
HourlyMinesUpdate();
// check how well the player is doing right now
HourlyProgressUpdate();
// do any quest stuff necessary
HourlyQuestUpdate();
HourlyLarryUpdate();
#ifdef JA2UB
// no UB
#else
HourlyCheckIfSlayAloneSoHeCanLeave();
#endif
// WDS - New AI
HourlyCheckStrategicAI();
PayOffSkyriderDebtIfAny();
if ( GetWorldHour() % 6 == 0 ) // 4 times a day
{
UpdateRegenCounters();
}
// WANNE: This check should avoid the resaving of a loaded auto-save game, when entering tactical
BOOLEAN doAutoSave = TRUE;
if (lastLoadedSaveGameDay == GetWorldDay() && lastLoadedSaveGameHour == GetWorldHour() )
{
doAutoSave = FALSE;
}
if (doAutoSave)
{
if ( AutoSaveToSlot[1] == FALSE && AutoSaveToSlot[2] == FALSE && AutoSaveToSlot[3] == FALSE && AutoSaveToSlot[4] == FALSE )
AutoSaveToSlot[0] = TRUE;
if ((gGameExternalOptions.autoSaveTime != 0) && (GetWorldHour() % gGameExternalOptions.autoSaveTime == 0))
{
if ( AutoSaveToSlot[0] == TRUE )
{
if( CanGameBeSaved() )
{
guiPreviousOptionScreen = guiCurrentScreen;
swprintf( zString, L"%s%d",pMessageStrings[ MSG_SAVE_AUTOSAVE_TEXT ],SAVE__TIMED_AUTOSAVE_SLOT1);
DoAutoSave(SAVE__TIMED_AUTOSAVE_SLOT1,zString);
}
AutoSaveToSlot[0] = FALSE;
AutoSaveToSlot[1] = TRUE;
AutoSaveToSlot[2] = FALSE;
AutoSaveToSlot[3] = FALSE;
AutoSaveToSlot[4] = FALSE;
}
else if ( AutoSaveToSlot[1] == TRUE )
{
if( CanGameBeSaved() )
{
guiPreviousOptionScreen = guiCurrentScreen;
swprintf( zString, L"%s%d",pMessageStrings[ MSG_SAVE_AUTOSAVE_TEXT ],SAVE__TIMED_AUTOSAVE_SLOT2);
DoAutoSave(SAVE__TIMED_AUTOSAVE_SLOT2,zString);
}
AutoSaveToSlot[0] = FALSE;
AutoSaveToSlot[1] = FALSE;
AutoSaveToSlot[2] = TRUE;
AutoSaveToSlot[3] = FALSE;
AutoSaveToSlot[4] = FALSE;
}
else if ( AutoSaveToSlot[2] == TRUE )
{
if( CanGameBeSaved() )
{
guiPreviousOptionScreen = guiCurrentScreen;
swprintf( zString, L"%s%d",pMessageStrings[ MSG_SAVE_AUTOSAVE_TEXT ],SAVE__TIMED_AUTOSAVE_SLOT3);
DoAutoSave(SAVE__TIMED_AUTOSAVE_SLOT3,zString);
}
AutoSaveToSlot[0] = FALSE;
AutoSaveToSlot[1] = FALSE;
AutoSaveToSlot[2] = FALSE;
AutoSaveToSlot[3] = TRUE;
AutoSaveToSlot[4] = FALSE;
}
else if ( AutoSaveToSlot[3] == TRUE )
{
if( CanGameBeSaved() )
{
guiPreviousOptionScreen = guiCurrentScreen;
swprintf( zString, L"%s%d",pMessageStrings[ MSG_SAVE_AUTOSAVE_TEXT ],SAVE__TIMED_AUTOSAVE_SLOT4);
DoAutoSave(SAVE__TIMED_AUTOSAVE_SLOT4,zString);
}
AutoSaveToSlot[0] = FALSE;
AutoSaveToSlot[1] = FALSE;
AutoSaveToSlot[2] = FALSE;
AutoSaveToSlot[3] = FALSE;
AutoSaveToSlot[4] = TRUE;
}
else if ( AutoSaveToSlot[4] == TRUE )
{
if( CanGameBeSaved() )
{
guiPreviousOptionScreen = guiCurrentScreen;
swprintf( zString, L"%s%d",pMessageStrings[ MSG_SAVE_AUTOSAVE_TEXT ],SAVE__TIMED_AUTOSAVE_SLOT5);
DoAutoSave(SAVE__TIMED_AUTOSAVE_SLOT5,zString);
}
AutoSaveToSlot[0] = TRUE;
AutoSaveToSlot[1] = FALSE;
AutoSaveToSlot[2] = FALSE;
AutoSaveToSlot[3] = FALSE;
AutoSaveToSlot[4] = FALSE;
}
}
}
}
void UpdateRegenCounters( void )
{
UINT8 ubID;
for ( ubID = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; ubID <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; ubID++ )
{
if ( MercPtrs[ ubID ]->bRegenBoostersUsedToday > 0 )
{
MercPtrs[ ubID ]->bRegenBoostersUsedToday--;
}
}
}
void HandleQuarterHourUpdate()
{
//if the game hasnt even started yet ( we havent arrived in the sector ) dont process this
if ( DidGameJustStart() )
return;
DecayTacticalMoraleModifiers( );
}
void HourlyQuestUpdate( void )
{
UINT32 uiHour = GetWorldHour();
#ifdef LUA_HOURLY_QUEST_UPDATE
LetLuaHourlyQuestUpdate(0);
#else
// brothel
if ( uiHour == 4 )
{
SetFactFalse( FACT_BROTHEL_OPEN );
}
else if ( uiHour == 20 )
{
SetFactTrue( FACT_BROTHEL_OPEN );
}
// bar/nightclub
if ( uiHour == 15 )
{
UINT8 ubLoop;
SetFactTrue( FACT_CLUB_OPEN );
SetFactFalse( FACT_PAST_CLUB_CLOSING_AND_PLAYER_WARNED );
// reset boxes fought
for ( ubLoop = 0; ubLoop < NUM_BOXERS; ubLoop++ )
{
gfBoxerFought[ ubLoop ] = FALSE;
}
// if # of boxing matches the player has won is a multiple of
// 3, and the boxers haven't rested, then make them rest
if ( gfBoxersResting )
{
// done resting now!
gfBoxersResting = FALSE;
gubBoxersRests++;
}
else if ( gubBoxingMatchesWon / 3 > gubBoxersRests )
{
// time for the boxers to rest!
gfBoxersResting = TRUE;
}
}
else if ( uiHour == 2 )
{
SetFactFalse( FACT_CLUB_OPEN );
}
// museum
if ( uiHour == 9 )
{
SetFactTrue( FACT_MUSEUM_OPEN );
}
else if ( uiHour == 18 )
{
SetFactFalse( FACT_MUSEUM_OPEN );
}
#endif
}
#define BAR_TEMPTATION 4
#define NUM_LARRY_ITEMS 6
UINT16 LarryItems[ NUM_LARRY_ITEMS ][ 3 ] =
{
// item, temptation, points to use
{ ADRENALINE_BOOSTER, 5, 100 },
{ ALCOHOL, BAR_TEMPTATION, 25 },
{ MEDICKIT, 4, 10 },
{ WINE, 3, 50 },
{ REGEN_BOOSTER, 3, 100 },
{ BEER, 2, 100 },
};
#define LARRY_FALLS_OFF_WAGON 8
void HourlyLarryUpdate( void )
{
SOLDIERTYPE * pSoldier;
INT8 bSlot = NO_SLOT, bBoozeSlot;
INT8 bLarryItemLoop;
UINT16 usTemptation = 0;
UINT16 usCashAmount;
BOOLEAN fBar = FALSE;
pSoldier = FindSoldierByProfileID( LARRY_NORMAL, TRUE );
if ( !pSoldier )
{
pSoldier = FindSoldierByProfileID( LARRY_DRUNK, TRUE );
}
if ( pSoldier )
{
if ( pSoldier->bAssignment >= ON_DUTY )
{
return;
}
if ( pSoldier->flags.fBetweenSectors )
{
return;
}
if ( pSoldier->bActive && pSoldier->bInSector && (gTacticalStatus.fEnemyInSector || guiCurrentScreen == GAME_SCREEN ) )
{
return;
}
// look for items in Larry's inventory to maybe use
for ( bLarryItemLoop = 0; bLarryItemLoop < NUM_LARRY_ITEMS; bLarryItemLoop++ )
{
bSlot = FindObj( pSoldier, LarryItems[ bLarryItemLoop ][ 0 ] );
if ( bSlot != NO_SLOT )
{
usTemptation = LarryItems[ bLarryItemLoop ][ 1 ];
break;
}
}
// check to see if we're in a bar sector, if we are, we have access to alcohol
// which may be better than anything we've got...
if ( usTemptation < BAR_TEMPTATION && GetCurrentBalance() >= Item[ ALCOHOL ].usPrice )
{
if ( pSoldier->bSectorZ == 0 &&
( ( pSoldier->sSectorX == 13 && pSoldier->sSectorY == MAP_ROW_D) ||
( pSoldier->sSectorX == 13 && pSoldier->sSectorY == MAP_ROW_C) ||
( pSoldier->sSectorX == 5 && pSoldier->sSectorY == MAP_ROW_C) ||
( pSoldier->sSectorX == 6 && pSoldier->sSectorY == MAP_ROW_C) ||
( pSoldier->sSectorX == 5 && pSoldier->sSectorY == MAP_ROW_D) ||
( pSoldier->sSectorX == 2 && pSoldier->sSectorY == MAP_ROW_H)
)
)
{
// in a bar!
fBar = TRUE;
usTemptation = BAR_TEMPTATION;
}
}
if ( usTemptation > 0 )
{
if ( pSoldier->ubProfile == LARRY_NORMAL )
{
gMercProfiles[ LARRY_NORMAL ].bNPCData += (INT8) Random( usTemptation );
if ( gMercProfiles[ LARRY_NORMAL ].bNPCData >= LARRY_FALLS_OFF_WAGON )
{
if ( fBar )
{
// take $ from player's account
usCashAmount = Item[ ALCOHOL ].usPrice;
AddTransactionToPlayersBook ( TRANSFER_FUNDS_TO_MERC, pSoldier->ubProfile, GetWorldTotalMin() , -( usCashAmount ) );
// give Larry some booze and set slot etc values appropriately
// CHRISL: Change final parameter to allow dynamic control of inventory slots
bBoozeSlot = FindEmptySlotWithin( pSoldier, HANDPOS, NUM_INV_SLOTS );
if ( bBoozeSlot != NO_SLOT )
{
// give Larry booze here
CreateItem( ALCOHOL, 100, &(pSoldier->inv[bBoozeSlot]) );
}
bSlot = bBoozeSlot;
bLarryItemLoop = 1;
}
// ahhhh!!!
SwapLarrysProfiles( pSoldier );
if ( bSlot != NO_SLOT )
{
UseKitPoints( &(pSoldier->inv[ bSlot ]), LarryItems[ bLarryItemLoop ][ 2 ], pSoldier );
}
}
}
else
{
// NB store all drunkenness info in LARRY_NORMAL profile (to use same values)
// so long as he keeps consuming, keep number above level at which he cracked
gMercProfiles[ LARRY_NORMAL ].bNPCData = __max( gMercProfiles[ LARRY_NORMAL ].bNPCData, LARRY_FALLS_OFF_WAGON );
gMercProfiles[ LARRY_NORMAL ].bNPCData += (INT8) Random( usTemptation );
// allow value to keep going up to 24 (about 2 days since we subtract Random( 2 ) when he has no access )
gMercProfiles[ LARRY_NORMAL ].bNPCData = __min( gMercProfiles[ LARRY_NORMAL ].bNPCData, 24 );
if ( fBar )
{
// take $ from player's account
usCashAmount = Item[ ALCOHOL ].usPrice;
AddTransactionToPlayersBook ( TRANSFER_FUNDS_TO_MERC, pSoldier->ubProfile, GetWorldTotalMin() , -( usCashAmount ) );
// give Larry some booze and set slot etc values appropriately
// CHRISL: Change final parameter to allow dynamic control of inventory slots
bBoozeSlot = FindEmptySlotWithin( pSoldier, HANDPOS, NUM_INV_SLOTS );
if ( bBoozeSlot != NO_SLOT )
{
// give Larry booze here
CreateItem( ALCOHOL, 100, &(pSoldier->inv[bBoozeSlot]) );
}
bSlot = bBoozeSlot;
bLarryItemLoop = 1;
}
if ( bSlot != NO_SLOT )
{
// ahhhh!!!
UseKitPoints( &(pSoldier->inv[ bSlot ]), LarryItems[ bLarryItemLoop ][ 2 ], pSoldier );
}
}
}
else if ( pSoldier->ubProfile == LARRY_DRUNK )
{
gMercProfiles[ LARRY_NORMAL ].bNPCData -= (INT8) Random( 2 );
if ( gMercProfiles[ LARRY_NORMAL ].bNPCData <= 0 )
{
// goes sober!
SwapLarrysProfiles( pSoldier );
}
}
}
}
#ifdef JA2UB
// no JA25 UB
#else
void HourlyCheckIfSlayAloneSoHeCanLeave()
{
SOLDIERTYPE *pSoldier;
pSoldier = FindSoldierByProfileID( SLAY, TRUE );
if( !pSoldier )
{
return;
}
if( pSoldier->flags.fBetweenSectors )
{
return;
}
if( !pSoldier->bActive || !pSoldier->stats.bLife )
{
return;
}
if( PlayerMercsInSector( (UINT8)pSoldier->sSectorX, (UINT8)pSoldier->sSectorY, pSoldier->bSectorZ ) == 1 )
{
if( Chance( 15 ) )
{
pSoldier->ubLeaveHistoryCode = HISTORY_SLAY_MYSTERIOUSLY_LEFT;
TacticalCharacterDialogueWithSpecialEvent( pSoldier, 0, DIALOGUE_SPECIAL_EVENT_CONTRACT_ENDING_NO_ASK_EQUIP, 0, 0 );
}
}
}
#endif