forked from Mirrors/openclonk
change time interface to remove connection between System.ocg and Objects.ocd
parent
d4c5815173
commit
4c66cc4ad7
|
@ -10,7 +10,7 @@ protected func Initialize()
|
|||
{
|
||||
// Environment
|
||||
CreateObject(Rule_ObjectFade)->DoFadeTime(10 * 36);
|
||||
var time=CreateObject(Environment_Time);
|
||||
var time=CreateObject(Time);
|
||||
time->SetTime();
|
||||
time->SetCycleSpeed();
|
||||
FindObject(Find_ID(Moon))->SetMoonPhase(3);
|
||||
|
|
|
@ -281,8 +281,7 @@ private func EnvCheck_Snow(object cursor, int x, int y, bool is_current)
|
|||
private func EnvCheck_Night(object cursor, int x, int y, bool is_current)
|
||||
{
|
||||
// Night time.
|
||||
var time = FindObject(Find_ID(Environment_Time));
|
||||
if (!time || !time->IsNight()) return nil;
|
||||
if (!Time->IsNight()) return nil;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ protected func Construction()
|
|||
|
||||
public func WatchUpdate()
|
||||
{
|
||||
var time = FindObject(Find_ID(Environment_Time));
|
||||
var time = FindObject(Find_ID(Time));
|
||||
|
||||
if(time)
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ func DoInit(int first_player)
|
|||
|
||||
// Set time of day to evening and create some clouds and celestials.
|
||||
Cloud->Place(20);
|
||||
var time = CreateObject(Environment_Time);
|
||||
var time = CreateObject(Time);
|
||||
time->SetTime(600);
|
||||
time->SetCycleSpeed(20);
|
||||
// Waterfall
|
||||
|
|
|
@ -16,7 +16,7 @@ func DoInit(int first_player)
|
|||
{
|
||||
// Set time of day to morning and create some clouds and celestials.
|
||||
Cloud->Place(20);
|
||||
var time = CreateObject(Environment_Time);
|
||||
var time = CreateObject(Time);
|
||||
time->SetTime(400);
|
||||
time->SetCycleSpeed(6);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ func DoInit(int first_player)
|
|||
var storm = EnsureObject(Storm,0,0,NO_OWNER);
|
||||
storm->SetStorm(-20,0,1000);
|
||||
SetSkyParallax(1); // move background with the wind
|
||||
var time = EnsureObject(Environment_Time,0,0,-1);
|
||||
var time = EnsureObject(Time,0,0,-1);
|
||||
time->SetTime(600);
|
||||
time->SetCycleSpeed(20);
|
||||
// Goal
|
||||
|
|
|
@ -27,7 +27,7 @@ private func Death()
|
|||
|
||||
private func MissionComplete()
|
||||
{
|
||||
if (IsDay()) return;
|
||||
if (Time->IsDay()) return;
|
||||
|
||||
// Mosquitos are very active
|
||||
MoveToTarget();
|
||||
|
|
|
@ -323,9 +323,7 @@ private func EnvCheck_Snow(object cursor, int x, int y, bool is_current)
|
|||
private func EnvCheck_Night(object cursor, int x, int y, bool is_current)
|
||||
{
|
||||
// Night time.
|
||||
var time = FindObject(Find_ID(Environment_Time));
|
||||
if (!time || !time->IsNight()) return false;
|
||||
return true;
|
||||
return Time->IsNight();
|
||||
}
|
||||
|
||||
private func EnvCheck_Day(object cursor, int x, int y, bool is_current)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[DefCore]
|
||||
id=Environment_Time
|
||||
id=Time
|
||||
Version=6,0
|
||||
Category=C4D_StaticBack|C4D_Environment
|
||||
Picture=0,0,128,128
|
||||
|
|
|
@ -9,8 +9,7 @@ local phase;
|
|||
protected func Initialize()
|
||||
{
|
||||
var alpha = 0;
|
||||
var time = FindObject(Find_ID(Environment_Time));
|
||||
if (time && time->IsNight())
|
||||
if (Time->IsNight())
|
||||
alpha = 255;
|
||||
SetClrModulation(RGBa(255, 255, 255, alpha));
|
||||
|
||||
|
|
|
@ -1,10 +1,18 @@
|
|||
/**
|
||||
Time Controller
|
||||
Creates time based on the 24-hour time scheme.
|
||||
Time is computed in minutes, which are by default
|
||||
1/2 a second in real life (18 frames). This will
|
||||
make each complete day/night cycle last 12 minutes
|
||||
in real life.
|
||||
Creates time based on the 24-hour time scheme. Time is
|
||||
computed in minutes, which are by default 1/2 a second in
|
||||
real life (18 frames). This will make each complete
|
||||
day/night cycle last 12 minutes in real life.
|
||||
|
||||
The time controller has an interface which is accessed by:
|
||||
Time->HasDayNightCycle(): whether time controller is active.
|
||||
Time->SetTime(int to_time): sets the time.
|
||||
Time->GetTime(): returns the time.
|
||||
Time->IsDay(): whether it is day.
|
||||
Time->IsNight(): whether it is night.
|
||||
Time->SetCycleSpeed(int seconds_per_tick): set the speed of the day/night cycle.
|
||||
Time->GetCycleSpeed(): returns the speed of the day/night cycle.
|
||||
|
||||
@author Ringwall, Maikel
|
||||
*/
|
||||
|
@ -16,9 +24,27 @@ local advance_seconds_per_tick;
|
|||
|
||||
/*-- Interface --*/
|
||||
|
||||
// Sets the current time using a 24*60 minute clock scheme.
|
||||
// Returns whether the time controller is active.
|
||||
public func HasDayNightCycle()
|
||||
{
|
||||
// Do definition call if needed.
|
||||
if (GetType(this) == C4V_Def)
|
||||
return FindObject(Find_ID(Time));
|
||||
return;
|
||||
}
|
||||
|
||||
// Sets the current time using a 24*60 minute clock scheme.
|
||||
public func SetTime(int to_time)
|
||||
{
|
||||
// Do definition call if needed.
|
||||
if (GetType(this) == C4V_Def)
|
||||
{
|
||||
var time_controller = FindObject(Find_ID(Time));
|
||||
if (time_controller)
|
||||
time_controller->SetTime(to_time);
|
||||
return;
|
||||
}
|
||||
// Otherwise normal behavior.
|
||||
// Set time.
|
||||
time = (to_time * 60) % (24 * 60 * 60);
|
||||
// Hide celestials during day.
|
||||
|
@ -34,19 +60,82 @@ public func SetTime(int to_time)
|
|||
// Returns the time in minutes.
|
||||
public func GetTime()
|
||||
{
|
||||
// Do definition call if needed.
|
||||
if (GetType(this) == C4V_Def)
|
||||
{
|
||||
var time_controller = FindObject(Find_ID(Time));
|
||||
if (time_controller)
|
||||
return time_controller->GetTime();
|
||||
return;
|
||||
}
|
||||
// Otherwise normal behavior.
|
||||
return time / 60;
|
||||
}
|
||||
|
||||
public func IsDay()
|
||||
{
|
||||
// Do definition call if needed.
|
||||
if (GetType(this) == C4V_Def)
|
||||
{
|
||||
var time_controller = FindObject(Find_ID(Time));
|
||||
if (time_controller)
|
||||
return time_controller->IsDay();
|
||||
return;
|
||||
}
|
||||
// Otherwise normal behavior.
|
||||
var day_start = (time_set.sunrise_start + time_set.sunrise_end) / 2;
|
||||
var day_end = (time_set.sunset_start + time_set.sunset_end) / 2;
|
||||
if (Inside(time, day_start, day_end))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public func IsNight()
|
||||
{
|
||||
// Do definition call if needed.
|
||||
if (GetType(this) == C4V_Def)
|
||||
{
|
||||
var time_controller = FindObject(Find_ID(Time));
|
||||
if (time_controller)
|
||||
return time_controller->IsNight();
|
||||
return;
|
||||
}
|
||||
// Otherwise normal behavior.
|
||||
var night_start = (time_set.sunset_start + time_set.sunset_end) / 2;
|
||||
var night_end = (time_set.sunrise_start + time_set.sunrise_end) / 2;
|
||||
if (!Inside(time, night_end, night_start))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sets the number of seconds the day will advance each tick (10 frames).
|
||||
// Setting to 0 will stop day-night cycle. Default is 30 seconds.
|
||||
public func SetCycleSpeed(int seconds_per_tick)
|
||||
{
|
||||
// Do definition call if needed.
|
||||
if (GetType(this) == C4V_Def)
|
||||
{
|
||||
var time_controller = FindObject(Find_ID(Time));
|
||||
if (time_controller)
|
||||
time_controller->SetCycleSpeed(seconds_per_tick);
|
||||
return;
|
||||
}
|
||||
// Otherwise normal behavior.
|
||||
advance_seconds_per_tick = seconds_per_tick;
|
||||
}
|
||||
|
||||
// Returns the number of seconds the day advances each tick (10 frames).
|
||||
public func GetCycleSpeed()
|
||||
{
|
||||
// Do definition call if needed.
|
||||
if (GetType(this) == C4V_Def)
|
||||
{
|
||||
var time_controller = FindObject(Find_ID(Time));
|
||||
if (time_controller)
|
||||
return time_controller->GetCycleSpeed();
|
||||
return;
|
||||
}
|
||||
// Otherwise normal behavior.
|
||||
return advance_seconds_per_tick;
|
||||
}
|
||||
|
||||
|
@ -56,7 +145,7 @@ public func GetCycleSpeed()
|
|||
protected func Initialize()
|
||||
{
|
||||
// Only one time control object.
|
||||
if (ObjectCount(Find_ID(Environment_Time)) > 1)
|
||||
if (ObjectCount(Find_ID(Time)) > 1)
|
||||
return RemoveObject();
|
||||
|
||||
// Determine the frame times for day and night events.
|
||||
|
@ -83,24 +172,6 @@ protected func Initialize()
|
|||
return;
|
||||
}
|
||||
|
||||
public func IsDay()
|
||||
{
|
||||
var day_start = (time_set.sunrise_start + time_set.sunrise_end) / 2;
|
||||
var day_end = (time_set.sunset_start + time_set.sunset_end) / 2;
|
||||
if (Inside(time, day_start, day_end))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public func IsNight()
|
||||
{
|
||||
var night_start = (time_set.sunset_start + time_set.sunset_end) / 2;
|
||||
var night_end = (time_set.sunrise_start + time_set.sunrise_end) / 2;
|
||||
if (!Inside(time, night_end, night_start))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private func PlaceStars()
|
||||
{
|
||||
// Since stars are almost completely parallax (=in screen coordinates), we only need
|
||||
|
|
|
@ -11,8 +11,7 @@ protected func Initialize()
|
|||
SetGraphics(Format("%d", g));
|
||||
|
||||
var alpha = 0;
|
||||
var time = FindObject(Find_ID(Environment_Time));
|
||||
if (time && time->IsNight())
|
||||
if (Time->IsNight())
|
||||
alpha = 255;
|
||||
SetClrModulation(RGBa(255, 255, 255, alpha));
|
||||
SetObjectBlitMode(GFX_BLIT_Additive);
|
||||
|
|
|
@ -206,11 +206,11 @@ private func Activity()
|
|||
// Escape ended
|
||||
if (lib_insect_escape) lib_insect_escape = false;
|
||||
// Go to sleep?
|
||||
if (HasDayNightCycle())
|
||||
if (Time->HasDayNightCycle())
|
||||
{
|
||||
if (!lib_insect_nocturnal && IsNight())
|
||||
if (!lib_insect_nocturnal && Time->IsNight())
|
||||
return Sleep();
|
||||
if (lib_insect_nocturnal && IsDay())
|
||||
if (lib_insect_nocturnal && Time->IsDay())
|
||||
return Sleep();
|
||||
if (IsSleeping())
|
||||
WakeUp();
|
||||
|
|
|
@ -48,7 +48,7 @@ protected func Initialize()
|
|||
/* --Environmental Effects-- */
|
||||
|
||||
// Time
|
||||
var time = CreateObject(Environment_Time);
|
||||
var time = CreateObject(Time);
|
||||
time->SetCycleSpeed(0);
|
||||
time->SetTime(900);
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
/*--
|
||||
Time.c
|
||||
Authors: Clonkonaut
|
||||
|
||||
Wrapper for local functions of Environment_Time (Objects.ocd\Environment.ocd\Time.ocd).
|
||||
See there for detailed function descriptions.
|
||||
--*/
|
||||
|
||||
// Returns the time object if there is any
|
||||
global func HasDayNightCycle()
|
||||
{
|
||||
return FindObject(Find_ID(Environment_Time));
|
||||
}
|
||||
|
||||
global func SetTime(int time)
|
||||
{
|
||||
var e_time = HasDayNightCycle();
|
||||
if (!e_time) return;
|
||||
return e_time->SetTime(time);
|
||||
}
|
||||
|
||||
global func GetTime()
|
||||
{
|
||||
var e_time = HasDayNightCycle();
|
||||
if (!e_time) return;
|
||||
return e_time->GetTime();
|
||||
}
|
||||
|
||||
global func IsDay()
|
||||
{
|
||||
var e_time = HasDayNightCycle();
|
||||
if (!e_time) return;
|
||||
return e_time->IsDay();
|
||||
}
|
||||
|
||||
global func IsNight()
|
||||
{
|
||||
var e_time = HasDayNightCycle();
|
||||
if (!e_time) return;
|
||||
return e_time->IsNight();
|
||||
}
|
|
@ -33,7 +33,7 @@ protected func Initialize()
|
|||
InitAnimals();
|
||||
|
||||
// Environment.
|
||||
var time = CreateObject(Environment_Time);
|
||||
var time = CreateObject(Time);
|
||||
time->SetTime(18*60 + 30);
|
||||
time->SetCycleSpeed(0);
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ protected func InitializePlayer(int plr)
|
|||
private func InitEnvironment(int difficulty)
|
||||
{
|
||||
// Set time to almost night and have stars.
|
||||
var time = CreateObject(Environment_Time);
|
||||
var time = CreateObject(Time);
|
||||
time->SetTime(20 * 60 + 15);
|
||||
time->SetCycleSpeed(0);
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ private func InitEnvironment()
|
|||
// Set time of day to evening and create some clouds and celestials.
|
||||
Cloud->Place(10);
|
||||
Cloud->SetPrecipitation("Water", 8);
|
||||
var time = CreateObject(Environment_Time);
|
||||
var time = CreateObject(Time);
|
||||
time->SetTime(60 * 12);
|
||||
time->SetCycleSpeed(20);
|
||||
return;
|
||||
|
|
|
@ -107,7 +107,7 @@ private func InitEnvironment(int difficulty)
|
|||
// Set time of day to evening and create some clouds and celestials.
|
||||
Cloud->Place(20);
|
||||
Cloud->SetPrecipitation("Snow", 20 + 5 * difficulty);
|
||||
var time = CreateObject(Environment_Time);
|
||||
var time = CreateObject(Time);
|
||||
time->SetTime(60 * 22);
|
||||
time->SetCycleSpeed(0);
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ private func InitEnvironment(int difficulty)
|
|||
SetGamma(100-dark,100-dark,100-dark);
|
||||
|
||||
// Time of days and celestials.
|
||||
var time = CreateObject(Environment_Time);
|
||||
var time = CreateObject(Time);
|
||||
time->SetTime(60 * 20);
|
||||
time->SetCycleSpeed(20);
|
||||
|
||||
|
|
Loading…
Reference in New Issue