UFO: Alien Invasion
Loading...
Searching...
No Matches
cp_time.cpp File Reference

Campaign geoscape time code. More...

#include "cp_time.h"
#include "../../DateTime.h"
#include "../../cl_shared.h"
#include "cp_campaign.h"
Include dependency graph for cp_time.cpp:

Go to the source code of this file.

Data Structures

struct  gameLapse_t

Macros

#define NUM_TIMELAPSE   8

Functions

 CASSERT (lengthof(lapse)==NUM_TIMELAPSE)
const char * CP_SecondConvert (int second)
 Converts a number of second into a char to display.
void CP_DateConvertLong (const DateTime &date, dateLong_t *dateLong)
 Converts a date from the engine in a (longer) human-readable format.
void CP_UpdateTime (void)
 Updates date/time and timescale (=timelapse) on the geoscape menu.
void CP_GameTimeStop (void)
 Stop game time speed.
bool CP_IsTimeStopped (void)
 Check if time is stopped.
static bool CP_AllowTimeScale (void)
void CP_GameTimeSlow (void)
 Decrease game time speed.
void CP_GameTimeFast (void)
 Increase game time speed.
static void CP_SetGameTime (int gameLapseValue)
 Set game time speed.
void CP_SetGameTime_f (void)
 Set a new time game from id.
int Date_DateToSeconds (const DateTime &date)
 Convert a date to seconds.
DateTime Date_Random (const DateTime &minFrame, const DateTime &maxFrame)
 Return a random relative date which lies between a lower and upper limit.
const char * Date_GetMonthName (int month)
 Returns the short monthame to the given month index.

Variables

const int DAYS_PER_MONTH [DateTime::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.

Detailed Description

Campaign geoscape time code.

Definition in file cp_time.cpp.

Macro Definition Documentation

◆ NUM_TIMELAPSE

#define NUM_TIMELAPSE   8

Definition at line 35 of file cp_time.cpp.

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

Function Documentation

◆ CASSERT()

CASSERT ( lengthof(lapse) = =NUM_TIMELAPSE)

References lapse, and NUM_TIMELAPSE.

◆ CP_AllowTimeScale()

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 ccs, and CP_OnGeoscape().

Referenced by CP_GameTimeFast(), and CP_GameTimeSlow().

◆ CP_DateConvertLong()

void CP_DateConvertLong ( const DateTime & 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 73 of file cp_time.cpp.

References dateLong_t::day, DAYS_PER_MONTH, DateTime::DAYS_PER_YEAR, DateTime::getDateAsDays(), DateTime::getTimeAsSeconds(), dateLong_t::hour, i, dateLong_t::min, dateLong_t::month, DateTime::MONTHS_PER_YEAR, dateLong_t::sec, DateTime::SECONDS_PER_HOUR, and dateLong_t::year.

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

◆ CP_GameTimeFast()

void CP_GameTimeFast ( void )

Increase game time speed.

Definition at line 174 of file cp_time.cpp.

References ccs, CP_AllowTimeScale(), CP_UpdateTime(), and NUM_TIMELAPSE.

◆ CP_GameTimeSlow()

void CP_GameTimeSlow ( void )

Decrease game time speed.

Definition at line 160 of file cp_time.cpp.

References ccs, CP_AllowTimeScale(), and CP_UpdateTime().

◆ CP_GameTimeStop()

◆ CP_IsTimeStopped()

bool CP_IsTimeStopped ( void )

Check if time is stopped.

Definition at line 139 of file cp_time.cpp.

References ccs.

Referenced by CP_CampaignRun(), and TEST_F().

◆ CP_SecondConvert()

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 57 of file cp_time.cpp.

References Com_sprintf(), and DateTime::SECONDS_PER_HOUR.

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

◆ CP_SetGameTime()

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 ccs, CP_UpdateTime(), and NUM_TIMELAPSE.

Referenced by CP_SetGameTime_f().

◆ 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, and CP_SetGameTime().

◆ CP_UpdateTime()

◆ Date_DateToSeconds()

int Date_DateToSeconds ( const DateTime & date)

Convert a date to seconds.

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

Definition at line 228 of file cp_time.cpp.

References DateTime::getDateAsDays(), DateTime::getTimeAsSeconds(), and DateTime::SECONDS_PER_DAY.

Referenced by TR_List_f(), and US_SelectStoredUfo_f().

◆ Date_GetMonthName()

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 250 of file cp_time.cpp.

References _.

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

◆ Date_Random()

DateTime Date_Random ( const DateTime & minFrame,
const DateTime & 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 239 of file cp_time.cpp.

References frand(), DateTime::getDateAsDays(), DateTime::getTimeAsSeconds(), and DateTime::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().

Variable Documentation

◆ DAYS_PER_MONTH

const int DAYS_PER_MONTH[DateTime::MONTHS_PER_YEAR] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}

Definition at line 37 of file cp_time.cpp.

Referenced by CP_DateConvertLong().

◆ lapse

const gameLapse_t lapse[NUM_TIMELAPSE]
static
Initial value:
= {
{N_("stopped"), 0},
{N_("5 sec"), 5},
{N_("5 mins"), 5 * DateTime::SECONDS_PER_MINUTE},
{N_("20 mins"), 20 * DateTime::SECONDS_PER_MINUTE},
{N_("12 hours"), 12 * DateTime::SECONDS_PER_HOUR},
{N_("5 days"), 5 * DateTime::SECONDS_PER_DAY}
}
#define N_(String)
Definition cl_shared.h:46
static const int SECONDS_PER_DAY
Definition DateTime.h:43
static const short SECONDS_PER_MINUTE
Definition DateTime.h:34
static const short SECONDS_PER_HOUR
Definition DateTime.h:42

The possible geoscape time intervalls.

Definition at line 40 of file cp_time.cpp.

Referenced by CASSERT(), and CP_UpdateTime().