UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_time.cpp File Reference

Campaign geoscape time code. More...

#include "../../cl_shared.h"
#include "cp_campaign.h"
#include "cp_time.h"

Go to the source code of this file.

Data Structures

struct  gameLapse_s
 

Macros

#define NUM_TIMELAPSE   8
 

Typedefs

typedef struct gameLapse_s gameLapse_t
 

Functions

 CASSERT (lengthof(lapse)==NUM_TIMELAPSE)
 
const char * CP_SecondConvert (int second)
 Converts a number of second into a char to display. More...
 
void CP_DateConvertLong (const date_t *date, dateLong_t *dateLong)
 Converts a date from the engine in a (longer) human-readable format. More...
 
void CP_UpdateTime (void)
 Updates date/time and timescale (=timelapse) on the geoscape menu. More...
 
void CP_GameTimeStop (void)
 Stop game time speed. More...
 
bool CP_IsTimeStopped (void)
 Check if time is stopped. More...
 
static bool CP_AllowTimeScale (void)
 
void CP_GameTimeSlow (void)
 Decrease game time speed. More...
 
void CP_GameTimeFast (void)
 Increase game time speed. More...
 
static void CP_SetGameTime (int gameLapseValue)
 Set game time speed. More...
 
void CP_SetGameTime_f (void)
 Set a new time game from id. More...
 
int Date_DateToSeconds (const date_t *date)
 Convert a date_t date to seconds. More...
 
bool Date_LaterThan (const date_t *now, const date_t *compare)
 Check whether the given date and time is later than current date. More...
 
bool Date_IsDue (const date_t *date)
 Checks whether a given date is equal or earlier than the current campaign date. More...
 
date_t Date_Add (date_t a, const date_t &b)
 Add two dates and return the result. More...
 
date_t Date_Substract (date_t a, const date_t &b)
 Substract the second date from the first and return the result. More...
 
date_t Date_Random (date_t minFrame, date_t maxFrame)
 Return a random relative date which lies between a lower and upper limit. More...
 
const char * Date_GetMonthName (int month)
 Returns the short monthame to the given month index. More...
 

Variables

static const int monthLength [MONTHS_PER_YEAR] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
 
static const gameLapse_t lapse [NUM_TIMELAPSE]
 The possible geoscape time intervalls. More...
 

Detailed Description

Campaign geoscape time code.

Definition in file cp_time.cpp.

Macro Definition Documentation

#define NUM_TIMELAPSE   8

Definition at line 36 of file cp_time.cpp.

Referenced by CP_GameTimeFast(), CP_SetGameTime(), and CP_UpdateTime().

Typedef Documentation

typedef struct gameLapse_s gameLapse_t

Function Documentation

CASSERT ( lengthof(lapse = =NUM_TIMELAPSE)
static bool CP_AllowTimeScale ( void  )
static

Time scaling is only allowed when you are on the geoscape and when you had at least one base built.

Definition at line 147 of file cp_time.cpp.

References stats_s::basesBuilt, ccs_s::campaignStats, ccs, and CP_OnGeoscape().

Referenced by CP_GameTimeFast(), and CP_GameTimeSlow().

void CP_DateConvertLong ( const date_t date,
dateLong_t dateLong 
)

Converts a date from the engine in a (longer) human-readable format.

Note
The seconds from "date" are ignored here.
The function always starts calculation from Jan. and also catches new years.
Parameters
[in]dateContains the date to be converted.
[out]dateLongThe converted date.

Definition at line 72 of file cp_time.cpp.

References dateLong_s::day, date_s::day, DAYS_PER_YEAR, dateLong_s::hour, i, length, lengthof, dateLong_s::min, dateLong_s::month, monthLength, MONTHS_PER_YEAR, dateLong_s::sec, date_s::sec, SECONDS_PER_HOUR, and dateLong_s::year.

Referenced by CL_EventAddMail(), CP_CampaignRun(), CP_UpdateTime(), MS_LoadXML(), MS_TimestampedText(), SAV_GameSave(), UP_OpenMail_f(), and UP_SetMailHeader().

void CP_GameTimeFast ( void  )

Increase game time speed.

Definition at line 174 of file cp_time.cpp.

References ccs, CP_AllowTimeScale(), CP_UpdateTime(), ccs_s::gameLapse, and NUM_TIMELAPSE.

void CP_GameTimeSlow ( void  )

Decrease game time speed.

Definition at line 160 of file cp_time.cpp.

References ccs, CP_AllowTimeScale(), CP_UpdateTime(), and ccs_s::gameLapse.

bool CP_IsTimeStopped ( void  )

Check if time is stopped.

Definition at line 139 of file cp_time.cpp.

References ccs, and ccs_s::gameLapse.

Referenced by CP_CampaignRun(), and TEST_F().

const char* CP_SecondConvert ( int  second)

Converts a number of second into a char to display.

Parameters
[in]secondNumber of second.
Todo:
Abstract the code into an extra function (DateConvertSeconds?) see also CP_DateConvertLong

Definition at line 56 of file cp_time.cpp.

References Com_sprintf(), and SECONDS_PER_HOUR.

Referenced by CL_DisplayPopupInterceptMission(), GEO_GetAircraftText(), TR_List_f(), and US_SelectStoredUfo_f().

static void CP_SetGameTime ( int  gameLapseValue)
static

Set game time speed.

Parameters
[in]gameLapseValueThe value to set the game time to.

Definition at line 189 of file cp_time.cpp.

References stats_s::basesBuilt, ccs_s::campaignStats, ccs, CP_UpdateTime(), ccs_s::gameLapse, and NUM_TIMELAPSE.

Referenced by CP_SetGameTime_f().

void CP_SetGameTime_f ( void  )

Set a new time game from id.

See also
CL_SetGameTime
lapse

Definition at line 214 of file cp_time.cpp.

References cgi, cgame_import_s::Cmd_Argv(), and CP_SetGameTime().

int Date_DateToSeconds ( const date_t date)

Convert a date_t date to seconds.

Parameters
[in]dateThe date in date_t format
Returns
the date in seconds

Definition at line 228 of file cp_time.cpp.

References date_s::day, and date_s::sec.

Referenced by TR_List_f(), and US_SelectStoredUfo_f().

const char* Date_GetMonthName ( int  month)

Returns the short monthame to the given month index.

Parameters
[in]monthThe month index - [0-11]
Returns
month name as char*

Definition at line 317 of file cp_time.cpp.

References _.

Referenced by CL_EventAddMail(), CP_UpdateTime(), MS_LoadXML(), MS_TimestampedText(), SAV_GameSave(), UP_OpenMail_f(), and UP_SetMailHeader().

bool Date_IsDue ( const date_t date)

Checks whether a given date is equal or earlier than the current campaign date.

Parameters
dateThe date to check
Returns
true if the given date is equal or earlier than the current campaign date, false otherwise

Definition at line 255 of file cp_time.cpp.

References ccs, ccs_s::date, date_s::day, and date_s::sec.

Referenced by B_IsBuildingBuiltUp(), CP_CheckTriggerEvent(), TEST_F(), and TR_TransferRun().

bool Date_LaterThan ( const date_t now,
const date_t compare 
)

Check whether the given date and time is later than current date.

Parameters
[in]nowCurrent date.
[in]compareDate to compare.
Returns
True if current date is later than given one.

Definition at line 239 of file cp_time.cpp.

References date_s::day, and date_s::sec.

Referenced by CP_CheckMissionEnd(), CP_EndRescueMission(), TEST_F(), UR_ProcessActive(), and US_StoreUFO().

date_t Date_Random ( date_t  minFrame,
date_t  maxFrame 
)

Return a random relative date which lies between a lower and upper limit.

Parameters
[in]minFrameMinimal date.
[in]maxFrameMaximal date.
Returns
A date value between minFrame and maxFrame.

Definition at line 302 of file cp_time.cpp.

References date_s::day, frand(), date_s::sec, and SECONDS_PER_DAY.

Referenced by CP_BeginRescueMission(), CP_BuildBaseSetUpBase(), CP_BuildBaseSubvertGovernment(), CP_CreateNewMission(), CP_HarvestMissionStart(), CP_InterceptAircraftMissionSet(), CP_InterceptAttackInstallation(), CP_ReconMissionAerial(), CP_ReconMissionGround(), CP_SpawnCrashSiteMission(), CP_SupplySetStayAtBase(), CP_TerrorMissionStart(), and CP_XVIMissionStart().

date_t Date_Substract ( date_t  a,
const date_t b 
)

Substract the second date from the first and return the result.

Parameters
[in]aFirst date.
[in]bSecond date.

Definition at line 285 of file cp_time.cpp.

References date_s::day, date_s::sec, and SECONDS_PER_DAY.

Referenced by B_GetConstructionTimeRemain(), TR_List_f(), and US_SelectStoredUfo_f().

Variable Documentation

const gameLapse_t lapse[NUM_TIMELAPSE]
static
Initial value:
= {
{N_("stopped"), 0},
{N_("5 sec"), 5},
{N_("5 mins"), 5 * 60},
{N_("20 mins"), SECONDS_PER_HOUR / 3},
{N_("1 hour"), SECONDS_PER_HOUR},
{N_("12 hours"), 12 * SECONDS_PER_HOUR},
{N_("1 day"), 24 * SECONDS_PER_HOUR},
{N_("5 days"), 5 * SECONDS_PER_DAY}
}
#define SECONDS_PER_HOUR
Definition: common.h:302
#define SECONDS_PER_DAY
Definition: common.h:301
#define N_(String)
Definition: cl_shared.h:45

The possible geoscape time intervalls.

Definition at line 39 of file cp_time.cpp.

const int monthLength[MONTHS_PER_YEAR] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
static

Definition at line 29 of file cp_time.cpp.

Referenced by CP_DateConvertLong().