forked from Mirrors/openclonk
Added 3 libraries: Lamp Post, Lamp and Lamp Dummy
Reworked the lantern and buildings to use the libraries. Lamp Post: Included by buildings if lamps should hang outside. Lamp: Included by lamps! Lamp Dummy: Included by the dummy object that resembles the (outisde) hanging lamp.Controls
parent
88389eb727
commit
609df7df88
|
@ -5,38 +5,7 @@
|
|||
@author Clonkonaut
|
||||
*/
|
||||
|
||||
local attach_building; // Building I'm hanging on to
|
||||
local building_pos; // Last position the building was in
|
||||
local my_offset; // My offset the building's position
|
||||
|
||||
// Attach the dummy to a building, position is an array defining the offet the building: [x, y]
|
||||
// graphics is the object whose graphics (mesh) will be used for display. Preferably a lantern.
|
||||
public func Set(object building, array position, object graphics)
|
||||
{
|
||||
if (!building) return RemoveObject();
|
||||
if (!position) position = [0,0];
|
||||
|
||||
if (Contained()) Exit();
|
||||
|
||||
attach_building = building;
|
||||
building_pos = [building->GetX(), building->GetY()];
|
||||
my_offset = position;
|
||||
|
||||
SetGraphics(nil,nil,1, GFXOV_MODE_Object, nil,nil, graphics);
|
||||
this.Plane = building.Plane + 1;
|
||||
SetPosition(building_pos[0] + my_offset[0], building_pos[1] + my_offset[1]);
|
||||
AddTimer("CheckPosition", 1);
|
||||
}
|
||||
|
||||
private func CheckPosition()
|
||||
{
|
||||
if (attach_building->GetX() == building_pos[0])
|
||||
if (attach_building->GetY() == building_pos[1])
|
||||
return;
|
||||
|
||||
building_pos = [attach_building->GetX(), attach_building->GetY()];
|
||||
SetPosition(building_pos[0] + my_offset[0], building_pos[1] + my_offset[1]);
|
||||
}
|
||||
#include Library_LampDummy
|
||||
|
||||
local Name = "$Name$";
|
||||
local Description = "$Description$";
|
|
@ -5,80 +5,26 @@
|
|||
@author Armin, Maikel, Clonkonaut
|
||||
*/
|
||||
|
||||
#include Library_Lamp
|
||||
|
||||
private func Construction()
|
||||
{
|
||||
SetProperty("MeshTransformation", Trans_Mul(Trans_Scale(3500), Trans_Rotate(280,0,1,0)));
|
||||
}
|
||||
|
||||
/*-- Convenient calls --*/
|
||||
|
||||
public func TurnOn()
|
||||
{
|
||||
if (lit) return false;
|
||||
SetLightRange(80, 60);
|
||||
SetMeshMaterial("LanternLit", 1);
|
||||
lit = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public func TurnOff()
|
||||
{
|
||||
if (!lit) return false;
|
||||
SetLightRange(0, 0);
|
||||
SetMeshMaterial("LanternGlass", 1);
|
||||
lit = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*-- Usage --*/
|
||||
|
||||
local lit = false;
|
||||
|
||||
public func ControlUse(object clonk)
|
||||
public func DummyDefinition()
|
||||
{
|
||||
// Only do something if the clonk can do an action.
|
||||
if (!clonk->HasHandAction())
|
||||
return true;
|
||||
// Turn on or off
|
||||
if (lit) {
|
||||
TurnOff();
|
||||
} else {
|
||||
TurnOn();
|
||||
}
|
||||
Sound("Click2");
|
||||
return true;
|
||||
}
|
||||
|
||||
/*-- Entrance --*/
|
||||
|
||||
local dummy;
|
||||
|
||||
public func ForceEntry(object container)
|
||||
{
|
||||
if (container->~LanternPosition())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public func Entrance(object container)
|
||||
{
|
||||
if (container->~LanternPosition())
|
||||
{
|
||||
dummy = CreateObject(DummyLantern,0,0,NO_OWNER);
|
||||
dummy->Set(container, container->LanternPosition(), this);
|
||||
}
|
||||
}
|
||||
|
||||
public func Departure()
|
||||
{
|
||||
if (dummy)
|
||||
dummy->RemoveObject();
|
||||
}
|
||||
|
||||
public func Destruction()
|
||||
{
|
||||
if (dummy)
|
||||
dummy->RemoveObject();
|
||||
return DummyLantern;
|
||||
}
|
||||
|
||||
/*-- Ground Hitting --*/
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
[DefCore]
|
||||
id=Library_LampPost
|
||||
Version=6,1
|
||||
Category=C4D_StaticBack
|
|
@ -0,0 +1,4 @@
|
|||
[DefCore]
|
||||
id=Library_Lamp
|
||||
Version=6,1
|
||||
Category=C4D_StaticBack
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
Lamp Library
|
||||
Include this by all lamps that should hang outside buildings.
|
||||
|
||||
@author Clonkonaut
|
||||
*/
|
||||
|
||||
/** Must define a dummy definition (i.e. the object which is shown outside the building)
|
||||
*/
|
||||
public func DummyDefinition() {}
|
||||
|
||||
/** Whether or not the lamp is on (true then).
|
||||
*/
|
||||
local lib_lamp_lit;
|
||||
|
||||
/** This is a lamp.
|
||||
*/
|
||||
public func IsLamp() { return true; }
|
||||
|
||||
/** Overload as needed to define a custom offset by the lamp.
|
||||
*/
|
||||
public func LampOffset() {}
|
||||
|
||||
/*-- Convenient calls --*/
|
||||
|
||||
/** Standard turning on procedure. Overload as needed.
|
||||
Default behaviour: lib_lamp_lit to true, light range 80,60, inherited
|
||||
*/
|
||||
public func TurnOn()
|
||||
{
|
||||
if (lib_lamp_lit) return false;
|
||||
_inherited();
|
||||
SetLightRange(80, 60);
|
||||
lib_lamp_lit = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Standard turning off procedure. Overload as needed.
|
||||
Default behaviour: lib_lamp_lit to false, light range 0,0, inherited
|
||||
*/
|
||||
public func TurnOff()
|
||||
{
|
||||
if (!lib_lamp_lit) return false;
|
||||
_inherited();
|
||||
SetLightRange(0, 0);
|
||||
lib_lamp_lit = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*-- Usage --*/
|
||||
|
||||
/** Standard control procedure. Overload as needed.
|
||||
Default behaviour: If clonk is ready, either turn on or off.
|
||||
*/
|
||||
public func ControlUse(object clonk)
|
||||
{
|
||||
// Only do something if the clonk can do an action.
|
||||
if (!clonk->HasHandAction())
|
||||
return true;
|
||||
// Turn on or off
|
||||
if (lib_lamp_lit) {
|
||||
TurnOff();
|
||||
} else {
|
||||
TurnOn();
|
||||
}
|
||||
Sound("Click2");
|
||||
return true;
|
||||
}
|
||||
|
||||
/*-- Further stuff --*/
|
||||
|
||||
/** Calls LampDeparture() in the departed object.
|
||||
*/
|
||||
public func Departure(object container)
|
||||
{
|
||||
container->~LampDeparture(this);
|
||||
}
|
||||
|
||||
/** Calls LampDestruction() in a container if contained.
|
||||
*/
|
||||
public func Destruction()
|
||||
{
|
||||
if (Contained()) Contained()->~LampDestruction(this);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
[DefCore]
|
||||
id=Library_LampDummy
|
||||
Version=6,1
|
||||
Category=C4D_StaticBack
|
|
@ -0,0 +1,50 @@
|
|||
/**
|
||||
Lamp Dummy Library
|
||||
Include this by all dummy lamps.
|
||||
|
||||
@author Clonkonaut
|
||||
*/
|
||||
|
||||
/** The building this dummy is attached to.
|
||||
*/
|
||||
local lib_lamp_building;
|
||||
|
||||
/** The building's last position.
|
||||
*/
|
||||
local lib_lamp_buildpos;
|
||||
|
||||
/** The dummy's offset to the building.
|
||||
*/
|
||||
local lib_lamp_offset;
|
||||
|
||||
/** Attach the dummy to a building.
|
||||
@param building The building to attach to.
|
||||
@param position An array defining the offet the building: [x, y].
|
||||
@param graphics The object whose graphics (mesh) will be used for display.
|
||||
*/
|
||||
public func Set(object building, array position, object graphics)
|
||||
{
|
||||
if (!building) return RemoveObject();
|
||||
if (!position) position = [0,0];
|
||||
|
||||
if (Contained()) Exit();
|
||||
|
||||
lib_lamp_building = building;
|
||||
lib_lamp_buildpos = [building->GetX(), building->GetY()];
|
||||
lib_lamp_offset = position;
|
||||
|
||||
SetGraphics(nil,nil,1, GFXOV_MODE_Object, nil,nil, graphics);
|
||||
this.Plane = building.Plane + 1;
|
||||
SetPosition(lib_lamp_buildpos[0] + lib_lamp_offset[0], lib_lamp_buildpos[1] + lib_lamp_offset[1]);
|
||||
AddTimer("LibraryLampDummy_CheckPosition", 1);
|
||||
}
|
||||
|
||||
private func LibraryLampDummy_CheckPosition()
|
||||
{
|
||||
if (lib_lamp_building->GetX() == lib_lamp_buildpos[0])
|
||||
if (lib_lamp_building->GetY() == lib_lamp_buildpos[1])
|
||||
return;
|
||||
|
||||
lib_lamp_buildpos = [lib_lamp_building->GetX(), lib_lamp_building->GetY()];
|
||||
SetPosition(lib_lamp_buildpos[0] + lib_lamp_offset[0], lib_lamp_buildpos[1] + lib_lamp_offset[1]);
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
Lamp Post Library
|
||||
Include this by all structures that may have a lamp (light source) hanging outside.
|
||||
Lamps must include the Lamp Library.
|
||||
Dummies must include the Lamp Dummy Library.
|
||||
|
||||
@author Clonkonaut
|
||||
*/
|
||||
|
||||
/** Whenever a lamp enters the building, a dummy lamp is created to visualise the effect.
|
||||
*/
|
||||
local lib_lamp_dummy;
|
||||
|
||||
local lib_lamp_lamp;
|
||||
|
||||
/** Return a 2-value array with the (offset) position of the dummy lamp.
|
||||
*/
|
||||
public func LampPosition(id def) { return [0,0]; }
|
||||
|
||||
/** This is a lamp post
|
||||
*/
|
||||
public func LampPost() { return true; }
|
||||
|
||||
private func RejectCollect(id item, object obj)
|
||||
{
|
||||
// At least one lamp can be collected
|
||||
if (obj->~IsLamp())
|
||||
if (!lib_lamp_dummy)
|
||||
{
|
||||
CreateLampDummy(obj);
|
||||
return false;
|
||||
}
|
||||
return _inherited(item, obj, ...);
|
||||
}
|
||||
|
||||
private func CreateLampDummy(object lamp)
|
||||
{
|
||||
var def = lamp->DummyDefinition();
|
||||
var lamp_offset = lamp->~LampOffset();
|
||||
if (!lamp_offset) lamp_offset = [0,0];
|
||||
// In theory, LampPosition can distinguish between certain types of lamps
|
||||
var my_offset = LampPosition(def);
|
||||
my_offset[0] += lamp_offset[0];
|
||||
my_offset[1] += lamp_offset[1];
|
||||
|
||||
lib_lamp_dummy = CreateObject(def,0,0, GetOwner());
|
||||
lib_lamp_dummy->Set(this, my_offset, lamp);
|
||||
lib_lamp_lamp = lamp;
|
||||
}
|
||||
|
||||
/** Called when a lamp leaves the building.
|
||||
*/
|
||||
public func LampDeparture(object lamp)
|
||||
{
|
||||
if (lamp != lib_lamp_lamp || !lib_lamp_dummy) return;
|
||||
lib_lamp_dummy->RemoveObject();
|
||||
lib_lamp_lamp = nil;
|
||||
lib_lamp_dummy = nil;
|
||||
}
|
||||
|
||||
/** Called when a lamp inside the building is destroyed. Defaults to LampDeparture().
|
||||
*/
|
||||
public func LampDestruction(object lamp)
|
||||
{
|
||||
LampDeparture(lamp);
|
||||
}
|
|
@ -3,10 +3,11 @@
|
|||
#include Library_Structure
|
||||
#include Library_Ownable
|
||||
#include Library_Producer
|
||||
#include Library_LampPost
|
||||
|
||||
local hold_production;
|
||||
|
||||
public func LanternPosition() { return [GetCalcDir()*28,4]; }
|
||||
public func LampPosition(id def) { return [GetCalcDir()*28,4]; }
|
||||
|
||||
func Construction(object creator)
|
||||
{
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
#include Library_Structure
|
||||
#include Library_Ownable
|
||||
#include Library_Producer
|
||||
#include Library_LampPost
|
||||
|
||||
local hold_production;
|
||||
|
||||
public func LanternPosition() { return [GetCalcDir()*24,2]; }
|
||||
public func LampPosition(id def) { return [GetCalcDir()*24,2]; }
|
||||
|
||||
func Construction(object creator)
|
||||
{
|
||||
|
|
|
@ -8,11 +8,12 @@
|
|||
#include Library_Structure
|
||||
#include Library_Ownable
|
||||
#include Library_Producer
|
||||
#include Library_LampPost
|
||||
|
||||
// does not need power
|
||||
public func PowerNeed() { return 0; }
|
||||
|
||||
public func LanternPosition() { return [GetCalcDir()*-11,2]; }
|
||||
public func LampPosition(id def) { return [GetCalcDir()*-11,2]; }
|
||||
|
||||
public func Construction(object creator)
|
||||
{
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
#include Library_Structure
|
||||
#include Library_Ownable
|
||||
#include Library_Producer
|
||||
#include Library_LampPost
|
||||
|
||||
local hold_production;
|
||||
|
||||
public func LanternPosition() { return [GetCalcDir()*24,20]; }
|
||||
public func LampPosition(id def) { return [GetCalcDir()*24,20]; }
|
||||
|
||||
func Construction(object creator)
|
||||
{
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
#include Library_Structure
|
||||
#include Library_Ownable
|
||||
#include Library_Producer
|
||||
#include Library_LampPost
|
||||
|
||||
local hold_production;
|
||||
|
||||
public func LanternPosition() { return [GetCalcDir()*19,-1]; }
|
||||
public func LanternPosition(id def) { return [GetCalcDir()*19,-1]; }
|
||||
|
||||
func Construction(object creator)
|
||||
{
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
#include Library_Structure
|
||||
#include Library_Ownable
|
||||
#include Library_Producer
|
||||
#include Library_LampPost
|
||||
|
||||
local animWork;
|
||||
local meshAttach;
|
||||
|
||||
public func LanternPosition() { return [GetCalcDir()*11,2]; }
|
||||
public func LampPosition(id def) { return [GetCalcDir()*11,2]; }
|
||||
|
||||
func Initialize()
|
||||
{
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
#include Library_Structure
|
||||
#include Library_Ownable
|
||||
#include Library_Producer
|
||||
#include Library_LampPost
|
||||
|
||||
local animWork;
|
||||
local meshAttach;
|
||||
|
||||
public func LanternPosition() { return [GetCalcDir()*-6,30]; }
|
||||
public func LampPosition(id def) { return [GetCalcDir()*-6,30]; }
|
||||
|
||||
func Initialize()
|
||||
{
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
#include Library_Structure
|
||||
#include Library_Ownable
|
||||
#include Library_Producer
|
||||
#include Library_LampPost
|
||||
|
||||
local hold_production;
|
||||
|
||||
public func LanternPosition() { return [GetCalcDir()*14,-6]; }
|
||||
public func LampPosition(id def) { return [GetCalcDir()*14,-6]; }
|
||||
|
||||
public func Construction(object creator)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue