[Add] Time in the form of Galactic Date.
This commit is contained in:
parent
39b63ce669
commit
7c1816aa2b
@ -6,6 +6,10 @@
|
||||
<low>500000</low>
|
||||
<high>1500000</high>
|
||||
</credits>
|
||||
<date>
|
||||
<low>1300</low>
|
||||
<high>1400</high>
|
||||
</date>
|
||||
<system>
|
||||
<name>KonoSys</name>
|
||||
<x>0</x>
|
||||
|
12
src/hook.h
12
src/hook.h
@ -6,7 +6,17 @@ int hook_add(unsigned int parent, char* func, char* stack);
|
||||
void hook_rm(int id);
|
||||
void hook_rmParent(unsigned int parent);
|
||||
|
||||
// Run hook.
|
||||
// ========================================================
|
||||
// Run Hooks:
|
||||
//
|
||||
// Currently used:
|
||||
// -- "land" - When landed.
|
||||
// -- "takeoff" - When taking off.
|
||||
// -- "jump" - When changing systems.
|
||||
// -- "time" - When time is increment drastically
|
||||
// (hyperspace and taking off.
|
||||
// ========================================================
|
||||
|
||||
int hooks_run(char* stack);
|
||||
|
||||
// Destroy hook.
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "economy.h"
|
||||
#include "hook.h"
|
||||
#include "mission.h"
|
||||
#include "ltime.h"
|
||||
#include "land.h"
|
||||
|
||||
// Global/main window.
|
||||
@ -973,6 +974,7 @@ void land(Planet* p) {
|
||||
// Takeoff from the planet.
|
||||
void takeoff(void) {
|
||||
int sw, sh, i;
|
||||
char* lt;
|
||||
|
||||
if(!landed) return;
|
||||
|
||||
@ -996,6 +998,12 @@ void takeoff(void) {
|
||||
player->shield = player->shield_max;
|
||||
player->energy = player->energy_max;
|
||||
|
||||
// Time goes by, triggers hook before takeoff.
|
||||
ltime_inc(RNG(2*LTIME_UNIT_LENGTH, 3*LTIME_UNIT_LENGTH));
|
||||
lt = ltime_pretty(0);
|
||||
player_message("taking off from %s on %s", land_planet->name, lt);
|
||||
free(lt);
|
||||
|
||||
space_init(NULL);
|
||||
|
||||
land_planet = NULL;
|
||||
|
45
src/ltime.c
Normal file
45
src/ltime.c
Normal file
@ -0,0 +1,45 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lephisto.h"
|
||||
#include "hook.h"
|
||||
#include "ltime.h"
|
||||
|
||||
static unsigned int lephisto_time = 0;
|
||||
|
||||
// Get the current time.
|
||||
unsigned int ltime_get(void) {
|
||||
return lephisto_time;
|
||||
}
|
||||
|
||||
// Return the time in pretty text.
|
||||
char* ltime_pretty(unsigned int t) {
|
||||
unsigned int lt;
|
||||
char str[128], *ret;
|
||||
|
||||
if(t == 0) lt = lephisto_time;
|
||||
else lt = t;
|
||||
|
||||
// Galactic Date.
|
||||
snprintf(str, 128, "GD %d.%03d",
|
||||
lt / (1000*LTIME_UNIT_LENGTH),
|
||||
(lt / (LTIME_UNIT_LENGTH)) % 1000);
|
||||
|
||||
ret = strdup(str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Set the time absolutely, does *not* generate an event, used at init.
|
||||
void ltime_set(unsigned int t) {
|
||||
lephisto_time = t;
|
||||
}
|
||||
|
||||
// Set the time relatively.
|
||||
void ltime_inc(unsigned int t) {
|
||||
lephisto_time += t;
|
||||
|
||||
hooks_run("time");
|
||||
}
|
||||
|
||||
|
13
src/ltime.h
Normal file
13
src/ltime.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// How long a 'unit' of time is.
|
||||
#define LTIME_UNIT_LENGTH 1000
|
||||
|
||||
// Get.
|
||||
unsigned int ltime_get(void);
|
||||
char* ltime_pretty(unsigned int t);
|
||||
|
||||
// Set.
|
||||
void ltime_set(unsigned int t);
|
||||
void ltime_inc(unsigned int t);
|
||||
|
30
src/player.c
30
src/player.c
@ -17,6 +17,8 @@
|
||||
#include "toolkit.h"
|
||||
#include "mission.h"
|
||||
#include "misn_lua.h"
|
||||
#include "ltime.h"
|
||||
#include "hook.h"
|
||||
#include "player.h"
|
||||
|
||||
#define XML_GUI_ID "GUIs" // XML section identifier.
|
||||
@ -167,7 +169,7 @@ static void player_newMake(void) {
|
||||
char system[20];
|
||||
uint32_t bufsize;
|
||||
char* buf = pack_readfile(DATA, START_DATA, &bufsize);
|
||||
int l, h;
|
||||
int l, h, tl, th;
|
||||
double x, y;
|
||||
|
||||
xmlNodePtr node, cur, tmp;
|
||||
@ -196,7 +198,7 @@ static void player_newMake(void) {
|
||||
do {
|
||||
if(xml_isNode(tmp, "low")) l = xml_getInt(tmp);
|
||||
else if(xml_isNode(tmp, "high")) h = xml_getInt(tmp);
|
||||
} while((tmp = tmp->next));
|
||||
} while(xml_nextNode(tmp));
|
||||
}
|
||||
else if(xml_isNode(cur, "system")) {
|
||||
tmp = cur->children;
|
||||
@ -206,10 +208,18 @@ static void player_newMake(void) {
|
||||
// Position.
|
||||
else if(xml_isNode(tmp, "x")) x = xml_getFloat(tmp);
|
||||
else if(xml_isNode(tmp, "y")) y = xml_getFloat(tmp);
|
||||
} while((tmp = tmp->next));
|
||||
} while(xml_nextNode(tmp));
|
||||
}
|
||||
else if(xml_isNode(cur, "combat_crating"))
|
||||
combat_crating = xml_getInt(cur);
|
||||
|
||||
else if(xml_isNode(cur, "date")) {
|
||||
tmp = cur->children;
|
||||
do {
|
||||
if(xml_isNode(tmp, "low")) tl = xml_getInt(tmp);
|
||||
else if(xml_isNode(tmp, "high")) th = xml_getInt(tmp);
|
||||
} while(xml_nextNode(tmp));
|
||||
}
|
||||
} while((cur = cur->next));
|
||||
}
|
||||
}while((node = node->next));
|
||||
@ -221,6 +231,9 @@ static void player_newMake(void) {
|
||||
// Money.
|
||||
player_credits = RNG(l, h);
|
||||
|
||||
// Time.
|
||||
ltime_set(RNG(tl*1000*LTIME_UNIT_LENGTH, th*1000*LTIME_UNIT_LENGTH));
|
||||
|
||||
// Welcome message.
|
||||
player_message("Welcome to "APPNAME"!");
|
||||
player_message("v%d.%d.%d", VMAJOR, VMINOR, VREV);
|
||||
@ -1236,6 +1249,15 @@ void player_jump(void) {
|
||||
|
||||
// Player actually broke hyperspace (Let's enter a new system).
|
||||
void player_brokeHyperspace(void) {
|
||||
unsigned int tl, th;
|
||||
|
||||
// Calculate the time it takes, call before space_init.
|
||||
tl = (unsigned int) floor(sqrt((double)player->solid->mass)/5.);
|
||||
th = (unsigned int) ceil(sqrt((double)player->solid->mass)/5.);
|
||||
tl *= LTIME_UNIT_LENGTH;
|
||||
th *= LTIME_UNIT_LENGTH;
|
||||
ltime_inc(RNG(tl, th));
|
||||
|
||||
// Enter the new system.
|
||||
space_init(systems_stack[cur_system->jumps[hyperspace_target]].name);
|
||||
|
||||
@ -1246,6 +1268,8 @@ void player_brokeHyperspace(void) {
|
||||
// Stop hyperspace.
|
||||
pilot_rmFlag(player, PILOT_HYPERSPACE | PILOT_HYP_BEGIN | PILOT_HYP_PREP);
|
||||
|
||||
hooks_run("jump");
|
||||
|
||||
player_message("BANG!");
|
||||
}
|
||||
|
||||
|
10
src/space.c
10
src/space.c
@ -12,6 +12,7 @@
|
||||
#include "weapon.h"
|
||||
#include "toolkit.h"
|
||||
#include "spfx.h"
|
||||
#include "ltime.h"
|
||||
#include "player.h"
|
||||
|
||||
#define XML_PLANET_ID "Planets"
|
||||
@ -50,10 +51,6 @@ int systems_nstack = 0; // Number of star systems.
|
||||
static int nplanets = 0; // Total number of loaded planets - A little silly.
|
||||
StarSystem* cur_system = NULL; // Current star system.
|
||||
|
||||
// Current stardate in nice format.
|
||||
char* stardate = "Stardate";
|
||||
unsigned int date = 0; // time since epoch.
|
||||
|
||||
// Fleet spawn rate.
|
||||
unsigned int spawn_timer = 0; // Controls spawn rate.
|
||||
|
||||
@ -333,6 +330,7 @@ static void space_addFleet(Fleet* fleet) {
|
||||
|
||||
// Init the system.
|
||||
void space_init(const char* sysname) {
|
||||
char* lt;
|
||||
int i;
|
||||
|
||||
// Cleanup some stuff.
|
||||
@ -350,7 +348,9 @@ void space_init(const char* sysname) {
|
||||
if(i == systems_nstack) ERR("System %s not found in stack", sysname);
|
||||
cur_system = systems_stack+i;
|
||||
|
||||
player_message("Entering System %s on %s", sysname, stardate);
|
||||
lt = ltime_pretty(0);
|
||||
player_message("Entering System %s on %s", sysname, lt);
|
||||
free(lt);
|
||||
|
||||
// Set up stars.
|
||||
nstars = (cur_system->stars*gl_screen.w*gl_screen.h+STAR_BUF*STAR_BUF)/(800*640);
|
||||
|
@ -9,6 +9,10 @@
|
||||
#define xml_isNode(n,s) (((n)->type == XML_NODE_START) && \
|
||||
(strcmp((char*)(n)->name, s)==0))
|
||||
|
||||
// Get the next node.
|
||||
#define xml_nextNode(n) \
|
||||
((n!=NULL) && ((n = n->next) != NULL))
|
||||
|
||||
// Get the property s of node n. This mallocs.
|
||||
#define xml_nodeProp(n,s) (char*)xmlGetProp(n, (xmlChar*)s)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user