Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StarDate Class Reference

#include <stardate.h>

Public Member Functions

 StarDate ()
 
 StarDate (double time)
 
void Init (double time)
 
double GetCurrentStarTime (int faction=0)
 
double GetElapsedStarTime (int faction=0)
 
void InitTrek (string date)
 
string GetTrekDate (int faction=0)
 
string GetFullTrekDate (int faction=0)
 
string ConvertFullTrekDate (double date)
 
void InitSDate (string date)
 
string GetSDate (int faction=0)
 
string GetFullSDate (int faction=0)
 
string SDateFromTrekDate (string trekdate)
 
string TrekDateFromSDate (string sdate)
 

Detailed Description

Definition at line 24 of file stardate.h.

Constructor & Destructor Documentation

StarDate::StarDate ( )

Definition at line 18 of file stardate.cpp.

References Mission::getGametime(), and mission.

19 {
20  initial_time = mission->getGametime();
21  initial_star_time = NULL;
22 }
StarDate::StarDate ( double  time)

Member Function Documentation

string StarDate::ConvertFullTrekDate ( double  date)

The stardate format is ddd.hhmm:sec with ddd, hh, mm, sec = star day, hour, minute, seconds The second equals our terran second. The minute however has 480 seconds (HOURS_DIV=8) The hour has 60 minutes and the day has 100 hours

Definition at line 82 of file stardate.cpp.

References int.

Referenced by GetFullTrekDate().

83 {
84  unsigned int days, hours, minutes, seconds;
85  char cdate[32];
86 
87  // Get the number of days dividing seconds number by the number of seconds in a day: 100*60*60*8 = 2880000
88  days = (unsigned int) date/2880000;
89  // Modulo gives us the number of stardate seconds elapsed in the current day
90  date = (unsigned int) date%2880000;
91  // Get the hours elapsed in the day by dividing by number of seconds in a stardate hour: 60*60*8 = 28800
92  hours = (unsigned int) date/28800;
93  // Modulo gives us the number of seconds elapsed in that hour
94  date = (unsigned int) date%28800;
95  //Get the number of minutes elapsed in that hour by dividing by the number of seconds in a minute: 60*8 = 480
96  minutes = (unsigned int) date/480;
97  //The remaining seconds in the date
98  //The seconds are counted from 0 to 480 before the minute effectively is incremented
99  seconds = (unsigned int) date%480;
100 
101  //The hour/minute part is displayed like HHMM divided by HOURS_DIV which is 8 for now
102  unsigned int hhmm = (hours*100+minutes);
103 
104  sprintf( cdate, "%d.%.4d:%.3d", days, hhmm, seconds );
105  return string( cdate );
106 }
double StarDate::GetCurrentStarTime ( int  faction = 0)

Definition at line 35 of file stardate.cpp.

References StarSystemGent::faction, Mission::getGametime(), and mission.

Referenced by GetFullTrekDate(), UniverseUtil::getStarTime(), and GetTrekDate().

36 {
37  //Get the number of seconds elapsed since the server start
38  double time_since_server_started = mission->getGametime()-initial_time;
39  //Add them to the current date
40  if (initial_star_time == NULL)
41  return time_since_server_started;
42  else
43  return initial_star_time[faction]+time_since_server_started;
44 }
double StarDate::GetElapsedStarTime ( int  faction = 0)

Definition at line 48 of file stardate.cpp.

References StarSystemGent::faction.

49 {
50  if (initial_star_time == NULL)
51  return initial_time;
52  else
53  return initial_star_time[faction] - initial_time;
54 }
string StarDate::GetFullSDate ( int  faction = 0)
string StarDate::GetFullTrekDate ( int  faction = 0)
string StarDate::GetSDate ( int  faction = 0)
string StarDate::GetTrekDate ( int  faction = 0)

Definition at line 154 of file stardate.cpp.

References GetCurrentStarTime().

155 {
156  return ConvertTrekDate( this->GetCurrentStarTime( faction ) );
157 }
void StarDate::Init ( double  time)

Definition at line 24 of file stardate.cpp.

References factions, Mission::getGametime(), i, and mission.

25 {
26  if (initial_star_time != NULL)
27  delete[] initial_star_time;
28  initial_time = mission->getGametime();
29  initial_star_time = new double[factions.size()];
30  for (unsigned int i = 0; i < factions.size(); i++)
31  initial_star_time[i] = time;
32 }
void StarDate::InitSDate ( string  date)
void StarDate::InitTrek ( string  date)

Definition at line 62 of file stardate.cpp.

References factions, Mission::getGametime(), i, mission, and VSFileSystem::vs_dprintf().

Referenced by NetClient::loginAccept().

63 {
64  if (initial_star_time != NULL)
65  //we must be reinitializing;
66  delete[] initial_star_time;
67  initial_star_time = 0;
68  initial_time = mission->getGametime();
69  initial_star_time = new double[factions.size()];
70  double init_time = this->ConvertTrekDate( date );
71  VSFileSystem::vs_dprintf( 3, "Initializing stardate from a Trek date for %d factions", factions.size() );
72  for (unsigned int i = 0; i < factions.size(); i++)
73  initial_star_time[i] = init_time;
74 }
string StarDate::SDateFromTrekDate ( string  trekdate)
string StarDate::TrekDateFromSDate ( string  sdate)

The documentation for this class was generated from the following files: