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 (177 lines) | stat: -rw-r--r-- 4,296 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
	Basement
	Provides basements to structures, but can also be built as a single object.
	
	@author: Maikel
*/

#include Library_Structure

local parent;
local width;

func Construction()
{
	// Make sure the basement does not move while constructing.
	SetCategory(C4D_StaticBack);
	return _inherited(...);
}

func Initialize()
{
	var wdt = GetObjWidth();
	if (parent)
	{
		wdt = parent->~GetBasementWidth();
		if (wdt == nil)
			wdt = parent->GetObjWidth();
	}
	SetWidth(BoundBy(wdt, 8, 120));
	// Move objects out of the basement.
	MoveOutOfSolidMask();
	return _inherited(...);
}

func Destruction()
{
	// Cast a single rock.
	CastObjects(Rock, 1, 15, 0, -5);
	// Set basement to nil in parent.
	if (parent)
		parent->~SetBasement(nil);
	return _inherited(...);
}

// Set the width of the basement.
public func SetWidth(int wdt)
{
	width = wdt;
	SetShape(-wdt / 2, -4, wdt, 8);
	SetSolidMask(0, 0, wdt, 8, 20 - wdt / 2, 0);
	SetObjDrawTransform(1000 * wdt / 40, 0, 0, 0, 1000, 0);
	return;
}

public func GetWidth() { return width; }

public func SetParent(object to_parent)
{
	parent = to_parent;
	var wdt = parent->~GetBasementWidth();
	if (wdt == nil)
		wdt = parent->GetObjWidth();
	SetWidth(BoundBy(wdt, 8, 120));
	// Notify the parent.
	parent->~SetBasement(this);
	return;
}

public func GetParent() { return parent; }

/*-- Saving --*/

public func SaveScenarioObject(proplist props)
{
	if (!inherited(props, ...)) 
		return false;
	if (parent)
		props->AddCall("BasementParent", this, "SetParent", parent);
	else if (width != GetDefWidth())
		props->AddCall("BasementWidth", this, "SetWidth", width);
	props->Remove("Category");
	return true;
}

/*-- Construction --*/

public func IsHammerBuildable() { return true; }
// It should not be a structure.
public func IsStructure() { return false; }
// But a basement!
public func IsBasement() { return true; }

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

// This makes it possible to combine basements with each other.
public func IsStructureWithoutBasement() { return true; }

// Sticking to other structures.

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

public func ConstructionCombineDirection(object other)
{
	// All directions are possible for other basements
	if (other && other->~IsBasement())
		return CONSTRUCTION_STICK_Left | CONSTRUCTION_STICK_Right | CONSTRUCTION_STICK_Bottom | CONSTRUCTION_STICK_Top;

	// For everything else, the basement is below.
	return CONSTRUCTION_STICK_Bottom;
}

public func ConstructionCombineOffset(object other)
{
	// Some structures like the elevator require the basement to have an offset.
	return other->~GetBasementOffset();
}

public func NoConstructionFlip() { return true; }

public func AlternativeConstructionPreview(object previewer, int direction, object combine_with)
{
	if (combine_with && combine_with->~IsBasement()) return;

	var wdt = GetSiteWidth(direction, combine_with);
	previewer->SetObjDrawTransform(1000 * wdt / 40, 0, 0, 0, 1000, 0, previewer.GFX_StructureOverlay);
}

public func GetSiteWidth(int direction, object combine_with)
{
	var wdt = GetDefWidth();
	if (combine_with)
	{
		wdt = combine_with->~GetBasementWidth();
		if (wdt == nil)
			wdt = combine_with->GetObjWidth();
	}
	return BoundBy(wdt, 8, 120);
}

public func SetConstructionSiteOverlay(object site, int direction, object combine_with)
{
	if (combine_with && combine_with->~IsBasement()) return;

	var wdt = GetSiteWidth(direction, combine_with);
	site->SetGraphics(nil, Basement, 1, GFXOV_MODE_Base);
	site->SetClrModulation(RGBa(255, 255, 255, 128), 1);
	site->SetObjDrawTransform(1000 * wdt / 40, 0, 0, 0, 1000, -4000, 1);
	return true;
}

// Set the parent if the basement is attached to a structure.
public func CombineWith(object stick_to)
{
	if (stick_to && stick_to->~IsBasement()) return;

	SetParent(stick_to);
}


/*-- Editor --*/

public func Definition(def, ...)
{
	_inherited(def, ...);
	if (!def.EditorProps) def.EditorProps = {};
	def.EditorProps.width = { Name="$Width$", Set="SetWidth", Type="int", Min=8, Max=120 };
}


/*-- Properties --*/

local Name = "$Name$";
local Description ="$Description$";
local HitPoints = 80;
local Plane = 190;
local Components = {Rock = 2};