forked from Mirrors/openclonk
lorry: pass controller to objects which are casted on destruction
parent
bfa6e7fbac
commit
f86495da89
|
@ -1,8 +1,18 @@
|
|||
/*-- Lorry --*/
|
||||
/**
|
||||
Lorry
|
||||
Transportation and storage for up to 50 objects.
|
||||
|
||||
@authors Maikel
|
||||
*/
|
||||
|
||||
#include Library_ElevatorControl
|
||||
|
||||
local content_menu;
|
||||
local drive_anim;
|
||||
local tremble_anim;
|
||||
local wheel_sound;
|
||||
local rot_wheels;
|
||||
local tremble;
|
||||
|
||||
protected func Construction()
|
||||
{
|
||||
|
@ -10,25 +20,71 @@ protected func Construction()
|
|||
SetProperty("MeshTransformation", Trans_Rotate(13, 0, 1, 0));
|
||||
}
|
||||
|
||||
public func IsLorry() { return true; }
|
||||
public func IsVehicle() { return true; }
|
||||
public func IsContainer() { return true; }
|
||||
public func IsToolProduct() { return true; }
|
||||
|
||||
local drive_anim;
|
||||
local tremble_anim;
|
||||
local wheel_sound;
|
||||
|
||||
protected func Initialize()
|
||||
{
|
||||
drive_anim = PlayAnimation("Drive", 5, Anim_Const(0), Anim_Const(500) /* ignored anyway */);
|
||||
tremble_anim = PlayAnimation("Tremble", 5, Anim_Const(0), Anim_Const(500));
|
||||
|
||||
iRotWheels = 0;
|
||||
iTremble = 0;
|
||||
rot_wheels = 0;
|
||||
tremble = 0;
|
||||
AddTimer("TurnWheels", 1);
|
||||
}
|
||||
|
||||
public func IsLorry() { return true; }
|
||||
public func IsVehicle() { return true; }
|
||||
public func IsContainer() { return true; }
|
||||
public func IsToolProduct() { return true; }
|
||||
|
||||
protected func Hit3()
|
||||
{
|
||||
Sound("DullMetalHit?");
|
||||
}
|
||||
|
||||
/*-- Contents --*/
|
||||
|
||||
private func MaxContentsCount()
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
|
||||
protected func RejectCollect(id object_id, object obj)
|
||||
{
|
||||
// Objects can still be collected.
|
||||
if (ContentsCount() < this->MaxContentsCount())
|
||||
{
|
||||
Sound("Clonk");
|
||||
return false;
|
||||
}
|
||||
|
||||
// The object cannot be collected, notify carrier?
|
||||
if (obj->Contained())
|
||||
Message("$TxtLorryisfull$");
|
||||
else
|
||||
{
|
||||
// If not carried, objects slide over the lorry.
|
||||
if (Abs(obj->GetXDir()) > 5)
|
||||
{
|
||||
obj->SetYDir(-2);
|
||||
obj->SetRDir(0);
|
||||
Sound("SoftHit*");
|
||||
}
|
||||
}
|
||||
// Reject collection.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Automatic unloading in buildings.
|
||||
protected func Entrance(object container)
|
||||
{
|
||||
// Only in buildings
|
||||
if (container->GetCategory() & (C4D_StaticBack | C4D_Structure))
|
||||
// Not if the building prohibits this action.
|
||||
if (!container->~NoLorryEjection(this))
|
||||
// Empty lorry.
|
||||
container->GrabContents(this);
|
||||
}
|
||||
|
||||
|
||||
/*-- Movement --*/
|
||||
|
||||
protected func ContactLeft()
|
||||
|
@ -43,76 +99,27 @@ protected func ContactRight()
|
|||
SetRDir(RandomX(-7, +7));
|
||||
}
|
||||
|
||||
func Hit3()
|
||||
{
|
||||
Sound("DullMetalHit?");
|
||||
}
|
||||
|
||||
/*-- Contents --*/
|
||||
|
||||
private func MaxContentsCount()
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
|
||||
protected func RejectCollect(id object_id, object obj)
|
||||
{
|
||||
// objects can still be collected
|
||||
if (ContentsCount() < this->MaxContentsCount())
|
||||
{
|
||||
Sound("Clonk");
|
||||
return false;
|
||||
}
|
||||
|
||||
// the object cannot be collected, notify carrier?
|
||||
if (obj->Contained())
|
||||
Message("$TxtLorryisfull$");
|
||||
else
|
||||
{
|
||||
// if not carried, objects slide over the lorry
|
||||
if(Abs(obj->GetXDir()) > 5)
|
||||
{
|
||||
obj->SetYDir(-2);
|
||||
obj->SetRDir(0);
|
||||
Sound("SoftHit*");
|
||||
}
|
||||
}
|
||||
// reject collection
|
||||
return true;
|
||||
}
|
||||
|
||||
// Automatic unloading in buildings.
|
||||
protected func Entrance(object container)
|
||||
{
|
||||
// Only in buildings
|
||||
if (container->GetCategory() & (C4D_StaticBack | C4D_Structure))
|
||||
// Not if the building prohibits this action.
|
||||
if (!container->~NoLorryEjection(this))
|
||||
// Empty lorry.
|
||||
container->GrabContents(this);
|
||||
}
|
||||
|
||||
local iRotWheels;
|
||||
local iTremble;
|
||||
|
||||
func TurnWheels()
|
||||
public func TurnWheels()
|
||||
{
|
||||
// TODO: Use Anim_X(Dir), keep from timer=1
|
||||
// TODO: Could also use GetAnimationPosition() instead of these local variables...
|
||||
iRotWheels += GetXDir()*2000/100; // Einmal rum (20 frames mal 10fps) nach 10 m
|
||||
while(iRotWheels < 0) iRotWheels += 2000;
|
||||
while(iRotWheels > 2000) iRotWheels -= 2000;
|
||||
SetAnimationPosition(drive_anim, Anim_Const(iRotWheels));
|
||||
rot_wheels += GetXDir() * 20;
|
||||
while (rot_wheels < 0)
|
||||
rot_wheels += 2000;
|
||||
while (rot_wheels > 2000)
|
||||
rot_wheels -= 2000;
|
||||
SetAnimationPosition(drive_anim, Anim_Const(rot_wheels));
|
||||
if (Random(100) < Abs(GetXDir()))
|
||||
{
|
||||
iTremble += 100;
|
||||
if(iTremble < 0) iTremble += 2000;
|
||||
if(iTremble > 2000) iTremble -= 2000;
|
||||
SetAnimationPosition(tremble_anim, Anim_Const(iTremble));
|
||||
tremble += 100;
|
||||
if (tremble < 0) tremble += 2000;
|
||||
if (tremble > 2000) tremble -= 2000;
|
||||
SetAnimationPosition(tremble_anim, Anim_Const(tremble));
|
||||
}
|
||||
if (Abs(GetXDir()) > 1 && !wheel_sound)
|
||||
{
|
||||
if (!wheel_sound) Sound("WheelsTurn", false, nil, nil, 1);
|
||||
if (!wheel_sound)
|
||||
Sound("WheelsTurn", false, nil, nil, 1);
|
||||
wheel_sound = true;
|
||||
}
|
||||
else if (wheel_sound && !GetXDir())
|
||||
|
@ -141,6 +148,7 @@ protected func Damage(int change, int cause, int by_player)
|
|||
var dx = Cos(angle, speed);
|
||||
var dy = Sin(angle, speed);
|
||||
obj->Exit(RandomX(-4, 4), RandomX(-4, 4), Random(360), dx, dy, RandomX(-20, 20));
|
||||
obj->SetController(by_player);
|
||||
}
|
||||
|
||||
// Toss around some fragments with particles attached.
|
||||
|
@ -168,6 +176,9 @@ protected func Damage(int change, int cause, int by_player)
|
|||
return _inherited(change, cause, by_player, ...);
|
||||
}
|
||||
|
||||
|
||||
/*-- Properties --*/
|
||||
|
||||
local ActMap = {
|
||||
Drive = {
|
||||
Prototype = Action,
|
||||
|
@ -186,7 +197,7 @@ local ActMap = {
|
|||
},
|
||||
};
|
||||
|
||||
func Definition(def)
|
||||
public func Definition(proplist def)
|
||||
{
|
||||
SetProperty("PictureTransformation", Trans_Mul(Trans_Rotate(-25, 1, 0, 0), Trans_Rotate(40, 0, 1, 0)), def);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue