File: Script.c

package info (click to toggle)
openclonk 8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 169,484 kB
  • sloc: cpp: 180,478; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 139; sh: 101
file content (139 lines) | stat: -rw-r--r-- 3,925 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
	Wooden Bridge
	A bridge which can be placed using the hammer.

	@author Pyrit, Randrian, Maikel	
*/

#include Library_Structure


local connection_left;
local connection_right;

protected func Construction()
{
	SetCategory(C4D_StaticBack);
	return _inherited(...);
}

protected func Initialize()
{
	// Move objects out of the bridge to prevent them being stuck on completion of the bridge.
	 MoveOutOfSolidMask();
	return _inherited(...);
}


/*-- Construction --*/

public func NoConstructionFlip() { return true; }

// Is a construction that is built just below the surface.
public func IsBelowSurfaceConstruction() { return true; }

public func IsHammerBuildable() { return true; }

public func ConstructionCombineWith()
{
	return "ConnectWoodenBridge";
}

public func ConnectWoodenBridge(object previewer)
{
	if (!previewer) 
		return true;
	if (previewer-> GetX() > GetX() && !connection_right)
		return true;
	if (previewer-> GetX() < GetX() && !connection_left)
		return true;
	return false;
}

public func ConstructionCombineDirection() { return CONSTRUCTION_STICK_Left | CONSTRUCTION_STICK_Right; }

public func IsStructureWithoutBasement() { return false; }

/* Called when the wooden bridge construction site is created.
   Returns the parameter "other_bridge", so that you can place
   multiple bridges via script:
   A->CombineWith(CreateObject(B))->...->CombineWith(CreateObject(C))
*/
public func CombineWith(object other_bridge)
{
	// Store the connected bridge.
	SetConnectedBridge(other_bridge);
	other_bridge->SetConnectedBridge(this);
	return other_bridge;
}

public func SetConnectedBridge(object other_bridge)
{
	if (other_bridge->GetX() > GetX())
		connection_right = other_bridge;
	else
		connection_left = other_bridge;
	return;
}

public func RemoveConnectedBridge(object other_bridge)
{
	if (other_bridge == connection_left)
		connection_left = nil;
	if (other_bridge == connection_right)
		connection_right = nil;
	return;
}


/*-- Destruction --*/

public func Destruction()
{
	// Notify connected bridges about destruction.
	if (connection_left)
		connection_left->RemoveConnectedBridge(this);
	if (connection_right)
		connection_right->RemoveConnectedBridge(this);
		
	// Create global particles, so they don't get removed when the bridge is removed.
	Global->CreateParticle("WoodChip", GetX(), GetY() + 5, PV_Random(-15, 15), PV_Random(-13, -6), PV_Random(36 * 3, 36 * 10), Particles_WoodChip(), 20);
	var particles =
	{
		Prototype = Particles_Dust(),
		R = 50, G = 50, B = 50,
		Size = PV_KeyFrames(0, 0, 0, 200, PV_Random(2, 10), 1000, 0),
	};
	for (var cnt = 0; cnt < 24; ++cnt)
	{
		var x = RandomX(-36, 36);
		var y = RandomX(-6, 6);
		Global->CreateParticle("Dust", GetX() + x, GetY() + y, PV_Random(-3, 3), PV_Random(-3, -3), PV_Random(18, 36), particles, 2);
		CastPXS("Ashes", 5, 30, x, y);
	}
	return _inherited(...);
}

public func Damage(int change, int cause, int cause_plr)
{
	// Damaged and burnt bridges appear darker.
	var darkness = 255 - 180 * GetDamage() / this.HitPoints;
	SetClrModulation(RGB(darkness, darkness, darkness));
	// Let the structure library handle the rest.
	return _inherited(change, cause, cause_plr, ...);
}


/*-- Properties --*/

// this.MeshTransformation = Trans_Mul(Trans_Rotate(90, 0, 0, 1), Trans_Scale(1000, 916, 1000), Trans_Translate(-6000, -37800, 0))
local MeshTransformation = [0, -916, 0, 34624, 1000, 0, 0, -6000, 0, 0, 1000, 0];
// def.PictureTransformation = Trans_Mul(Trans_Rotate(90, 0, 0, 1), Trans_Rotate(30, 1, 0, 0), Trans_Rotate(10, 0, 1, 0), Trans_Scale(1280), Trans_Scale(1000, 916, 1000), Trans_Translate(-6000, -12000, 0))
local PictureTransformation = [-111, -1014, 629, 12834, 1260, 0, 222, -7560, -192, 586, 1091, -5880];
local Name = "$Name$";
local Description = "$Description$";
local BlastIncinerate = 2;
local ContactIncinerate = 8;
local NoBurnDecay = true;
local HitPoints = 80;
local Components = {Wood = 3};