Dynamite Box is now a container holding 5 sticks of dynamite. Can be taken out separately (and put back in).

qteditor^2
Clonkonaut 2016-08-09 23:44:14 +02:00
parent daf45a17f5
commit 07ea0fe438
3 changed files with 220 additions and 116 deletions

View File

@ -1,13 +1,91 @@
/**
Dynamite
A volatile tool that can be pressed into wallsfor accurate
mining, burning a short fuse before exploding.
@author Newton
A volatile tool that can be pressed into wallsfor accurate mining, burning a short fuse before exploding.
@author: Newton
*/
// time in frames until explosion
func FuseTime() { return 140; }
/*-- Engine Callbacks --*/
func Hit()
{
Sound("Hits::GeneralHit?");
}
func Incineration(int caused_by)
{
Extinguish();
Fuse();
SetController(caused_by);
}
func RejectEntrance()
{
return GetAction() == "Ready";
}
/*-- Callbacks --*/
public func OnCannonShot(object cannon)
{
Fuse();
}
// Drop fusing dynamite on death to prevent explosion directly after respawn
public func IsDroppedOnDeath(object clonk)
{
return (GetAction() == "Fuse");
}
public func IsFusing()
{
return GetAction() == "Fuse";
}
// Called by the Dynamite box
public func SetReady()
{
SetAction("Ready");
}
// Called by the Dynamite box
public func SetFuse()
{
SetAction("Fuse");
// Object can't be collected anymore when it fuses.
this.Collectible = false;
}
public func Reset()
{
SetAction("Idle");
// Object can be collected again.
this.Collectible = true;
}
public func OnFuseFinished(object fuse)
{
SetController(fuse->GetController());
DoExplode();
}
// This will only when inside a dynamite box to display the remaining dynamite sticks in the HUD
public func GetStackCount()
{
if (Contained())
if (Contained()->GetID() == DynamiteBox)
{
return Contained()->ContentsCount(GetID());
}
}
public func IsInfiniteStackCount()
{
return false;
}
public func IsGrenadeLauncherAmmo() { return true; }
/*-- Usage --*/
public func ControlUse(object clonk, int x, int y, bool box)
{
@ -52,7 +130,25 @@ public func ControlUse(object clonk, int x, int y, bool box)
return false;
}
private func Place(object clonk, int x, int y, bool box)
public func Fuse()
{
if (GetAction() != "Fuse")
{
if (!FindObject(Find_Category(C4D_StaticBack), Find_Func("IsFuse"), Find_ActionTargets(this)))
Sound("Fire::Fuse");
SetAction("Fuse");
// Object can't be collected anymore when it fuses.
this.Collectible = false;
}
}
// time in frames until explosion
func FuseTime()
{
return 140;
}
func Place(object clonk, int x, int y, bool box)
{
var angle = Angle(0,0,x,y);
var pos = GetWall(angle);
@ -69,26 +165,9 @@ private func Place(object clonk, int x, int y, bool box)
return false;
}
public func Fuse()
{
if (GetAction() != "Fuse")
{
if (!FindObject(Find_Category(C4D_StaticBack), Find_Func("IsFuse"), Find_ActionTargets(this)))
Sound("Fire::Fuse");
SetAction("Fuse");
// Object can't be collected anymore when it fuses.
this.Collectible = false;
}
}
public func OnCannonShot(object cannon)
{
Fuse();
}
// returns true if there is a wall in direction in which "clonk" looks
// and puts the offset to the wall into "xo, yo" - looking from the clonk
private func GetWall(int angle)
func GetWall(int angle)
{
var dist = 12;
for (var dist = 12; dist < 18; dist++)
@ -101,41 +180,7 @@ private func GetWall(int angle)
return false;
}
protected func Hit() { Sound("Hits::GeneralHit?"); }
protected func Incineration(int caused_by)
{
Extinguish();
Fuse();
SetController(caused_by);
}
protected func RejectEntrance()
{
return GetAction() == "Ready";
}
// Controle of the Dynamite box
public func SetReady()
{
SetAction("Ready");
}
// Controle of the Dynamite box
public func SetFuse()
{
SetAction("Fuse");
// Object can't be collected anymore when it fuses.
this.Collectible = false;
}
public func Reset()
{
SetAction("Idle");
// Object can be collected again.
this.Collectible = true;
}
private func Fusing()
func Fusing()
{
var x = Sin(GetR(), 5);
var y = -Cos(GetR(), 5);
@ -155,11 +200,6 @@ private func Fusing()
return;
}
public func OnFuseFinished(object fuse)
{
SetController(fuse->GetController());
DoExplode();
}
public func DoExplode()
{
@ -169,17 +209,9 @@ public func DoExplode()
Explode(26);
}
/*-- Production --*/
public func IsChemicalProduct() { return true; }
public func IsGrenadeLauncherAmmo() { return true; }
public func IsFusing() { return GetAction() == "Fuse"; }
// Drop fusing dynamite on death to prevent explosion directly after respawn
public func IsDroppedOnDeath(object clonk)
{
return (GetAction() == "Fuse");
}
/*-- Properties --*/
@ -207,8 +239,7 @@ local ActMap = {
};
local Name = "$Name$";
local Description = "$Description$";
local Collectible = 1;
local Collectible = true;
local BlastIncinerate = 1;
local ContactIncinerate = 1;
local Components = {Coal = 1, Firestone = 1};

View File

@ -38,9 +38,11 @@ public func ControlUse(object clonk, int x, int y)
{
if (clonk->GetAction() != "Walk")
return true;
ignited = 1;
if (ignited)
return true;
ignited = true;
// The clonk has to stand.
clonk->SetAction("Stand");
clonk->SetXDir(0);
@ -91,7 +93,13 @@ public func GetCarryMode()
public func GetCarryPhase() { return 250; }
public func GetCarrySpecial(clonk)
public func GetCarryTransform()
{
if (ignited)
return Trans_Mul(Trans_Rotate(0, 1), Trans_Translate(-1000));
}
public func GetCarrySpecial()
{
if (ignited)
return "pos_hand2";

View File

@ -1,10 +1,12 @@
/**
Dynamite box
Contains five dynamite sticks which can be placed and detonated from a distance.
Contains five dynamite sticks which can be placed and detonated from a distance.
@author: Newton
*/
#include Library_HasExtraSlot
static const DYNA_MaxLength = 500;
static const DYNA_MaxCount = 5;
@ -17,6 +19,8 @@ local wire;
func Initialize()
{
CreateContents(Dynamite, DYNA_MaxCount);
count = DYNA_MaxCount;
dynamite_sticks = [];
wires = [];
@ -29,7 +33,6 @@ func Initialize()
// Hide it TODO: Remove if the mesh isn't shown if there is a picture set
this.PictureTransformation = Trans_Scale();
UpdatePicture();
return;
}
func Hit()
@ -37,24 +40,84 @@ func Hit()
Sound("Hits::Materials::Wood::DullWoodHit?");
}
func Incineration(int caused_by)
func Incineration(int caused_by)
{
ActivateFuse();
if (!GetEffect("Fuse", this)) AddEffect("Fuse", this, 100, 1, this);
Sound("Fire::Fuse");
SetController(caused_by);
return;
}
func Damage(int change, int type, int by_player)
{
Incinerate(nil, by_player);
return;
}
public func OnCannonShot(object cannon)
func RejectCollect(id def, object obj)
{
Incinerate(nil, cannon->GetController());
if (obj->GetID() != Dynamite)
return true;
// One dynamite box can only support 5 sticks of dynamite, regardless if these are in the box
// or already taken out (connected with wires)
var sticks = ContentsCount(Dynamite);
for (var i = 0; i < GetLength(wires); i++)
if (wires[i])
sticks++;
if (sticks >= DYNA_MaxCount)
return true;
return false;
}
func Ejection()
{
count--;
if (count == 0)
{
ChangeToIgniter();
if (Contained())
{
var pos = Contained()->~GetItemPos(this);
Contained()->~UpdateAttach();
Contained()->~OnSlotFull(pos);
}
}
else
{
UpdatePicture();
}
// Make sure the inventory gets notified of the changes.
if (Contained())
Contained()->~OnInventoryChange();
}
func ContentsDestruction()
{
Ejection();
}
func Collection2()
{
if (count == 0 && GetID() == Igniter)
{
ChangeToBox();
if (Contained())
{
var pos = Contained()->~GetItemPos(this);
Contained()->~UpdateAttach();
Contained()->~OnSlotFull(pos);
}
}
count++;
UpdatePicture();
if (Contained())
Contained()->~OnInventoryChange();
}
/*-- Callbacks --*/
@ -78,6 +141,11 @@ public func OnFuseFinished(object fuse)
DoExplode();
}
public func OnCannonShot(object cannon)
{
Incinerate(nil, cannon->GetController());
}
/*-- Usage --*/
public func SetDynamiteCount(int new_count)
@ -87,49 +155,34 @@ public func SetDynamiteCount(int new_count)
// Update inventory if contained in a crew member.
if (Contained())
Contained()->~OnInventoryChange();
return;
}
public func HoldingEnabled() { return true; }
public func ControlUse(object clonk, int x, int y)
{
var dynamite = dynamite_sticks[count - 1] = CreateContents(Dynamite);
var dynamite = Contents();
if (!dynamite || dynamite->GetID() != Dynamite)
return false;
if (!dynamite->ControlUse(clonk, x, y, 1))
{
dynamite->RemoveObject();
return true;
}
if(wire)
wire->Connect(dynamite_sticks[count], dynamite);
wire = CreateObject(Fuse);
wire->Connect(dynamite, this);
Sound("Objects::Connect");
wires[count - 1] = wire;
count--;
if (count == 0)
{
var pos = clonk->GetItemPos(this);
ChangeToIgniter();
clonk->UpdateAttach();
clonk->OnSlotFull(pos);
}
else
{
UpdatePicture();
}
wires[count] = wire;
// Make sure the inventory gets notified of the changes.
clonk->~OnInventoryChange();
return true;
}
// Empty this box and turn it into an igniter
public func ChangeToIgniter()
{
if (GetID() == Igniter) return;
count = 0;
UpdatePicture();
ChangeDef(Igniter);
@ -137,6 +190,16 @@ public func ChangeToIgniter()
return true;
}
// Change back into a box
public func ChangeToBox()
{
if (GetID() == DynamiteBox) return;
ChangeDef(DynamiteBox);
UpdatePicture();
return true;
}
public func ActivateFuse()
{
// Activate all fuses.
@ -199,7 +262,7 @@ func UpdatePicture()
}
// Display the remaining dynamite sticks in menus.
public func GetInventoryIconOverlay()
/*public func GetInventoryIconOverlay()
{
// Full boxes don't need an overlay. Same for igniters.
if (count == DYNA_MaxCount || count <= 0) return nil;
@ -231,17 +294,19 @@ public func GetInventoryIconOverlay()
}
return overlay;
}
}*/
func Definition(def) {
func Definition(def)
{
SetProperty("PictureTransformation", Trans_Mul(Trans_Rotate(150, 1, 0, 0), Trans_Rotate(140, 0, 1, 0)), def);
}
/*-- Properties --*/
local Collectible = 1;
local Name = "$Name$";
local Description = "$Description$";
local Collectible = true;
local BlastIncinerate = 1;
local ContactIncinerate = 2;
local Components = {Wood = 1, Coal = 2, Firestone = 2};
local MaxContentsCount = 5;