This repository was archived by the owner on Sep 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfoart_server.fos
More file actions
254 lines (210 loc) · 5.43 KB
/
foart_server.fos
File metadata and controls
254 lines (210 loc) · 5.43 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
*
* WHINE TEAM
* We Had Ini, Now Engine
*
*/
#ifndef __FOART_SERVER__
#define __FOART_SERVER__
// inlined in foart.fos
#ifdef _MSC_VER
#include "foart.fos"
#endif
#include "_time.fos"
#include "buffer_h.fos"
#ifdef FOART_DEBUG
#endif // FOART_DEBUG
#define FOART_SayLog#(__cr,__message) \
{ \
Log( __cr.Name+"<"+__cr.Id+"> "+__message ); \
__cr.Say( SAY_NETMSG, __message ); \
}
class FOArt_Running
{
FOArt@ foart;
uint mapId;
int16 centerX;
int16 centerY;
uint hexIndex;
uint ownerId;
uint definitionIndex;
uint started;
bool finished;
FOArt_Running( FOArt& foart, uint mapId, int16 centerX, int16 centerY, uint ownerId )
{
@this.foart = foart;
this.mapId = mapId;
this.centerX = centerX;
this.centerY = centerY;
this.hexIndex = 0;
this.definitionIndex = 0;
this.ownerId = ownerId;
this.finished = false;
this.started = __FullSecond;
}
void Process()
{
if( !valid(this.foart) ) // should never happen
{
Log( "ERROR !!! FOArt invalid, finishing" );
this.finished = true;
return;
}
Map@ map = GetMap( this.mapId );
if( !valid(map) )
{
Log( "FOArt: invalid map<"+mapId+">, finishing" );
this.finished = true;
return;
}
FOArtDefinition@ definition = this.foart.GetDefinition( this.definitionIndex );
if( !valid(definition) )
{
Log( "FOArt: invalid definition index<"+this.definitionIndex+">, finishing" );
this.finished = true;
return;
}
int16 hexX = 0;
int16 hexY = 0;
if( !definition.GetHex( this.hexIndex, hexX, hexY ))
{
Log( "FOArt: invalid hex index<"+this.hexIndex+">, finishing" );
this.finished = true;
return;
}
if( this.foart.Relative() )
{
hexX += this.centerX;
hexY += this.centerY;
}
int itemId = definition.Spawn( map, hexX, hexY );
if( ++this.hexIndex == definition.GetHexesCount() )
{
DebugLog( "hexes end, try next definition" );
hexIndex = 0;
if( ++this.definitionIndex == this.foart.GetDefinitionsCount() )
{
DebugLog( "definitions end, finishing" );
this.finished = true;
}
}
}
}; array<FOArt_Running@> FOArtRunning;
uint FOART_TimeEvent = 0;
void unsafe_spawnFast( Critter& cr, int, int, int, string@ filename, array<int32>@ data )
{
if( !valid(filename) )
@filename = "<unknown>";
Map@ map = cr.GetMap();
if( !valid(map) )
{
FOART_SayLog( cr, filename+": Not on worldmap" );
return;
}
DebugLog( "FOArt: reading data" );
Buffer@ buff = NewBuffer( data );
if( !valid(buff) )
{
FOART_SayLog( cr, filename+": Buffer not valid" );
return;
}
DebugLog( "FOArt: loading data" );
FOArt@ foart = NewFOArt(0);
if( foart.Load( buff.AsUint8() ))
{
if( foart.Version() == 0 )
FOART_SayLog( cr, filename+": Load error" );
FOART_Spawn( foart, map, cr.HexX, cr.HexY, cr.Id );
}
else
FOART_SayLog( cr, filename+": FOArt not loaded" );
}
void unsafe_spawnSlow( Critter& cr, int, int, int, string@ filename, array<int32>@ data )
{
if( !valid(filename) )
@filename = "<unknown>";
Map@ map = cr.GetMap();
if( !valid(map) )
{
FOART_SayLog( cr, filename+": Not on worldmap" );
return;
}
DebugLog( "FOArt: reading data" );
Buffer@ buff = NewBuffer( data );
if( !valid(buff) )
{
FOART_SayLog( cr, filename+": Buffer not valid" );
return;
}
DebugLog( "FOArt: loading data" );
FOArt@ foart = NewFOArt(0);
if( foart.Load( buff.AsUint8() ))
{
if( foart.Version() == 0 )
FOART_SayLog( cr, filename+": Load error" );
FOART_Spawn( foart, map, cr.HexX, cr.HexY, cr.Id, true );
}
else
FOART_SayLog( cr, filename+": FOArt not loaded" );
}
void FOART_Spawn( FOArt@ foart, Map& map, uint16 hexX, uint16 hexY, uint ownerId, bool timeEvent = false )
{
if( timeEvent )
{
timeEvent = false;
// detect servers with small __TimeMultiplier
if( REAL_MS(FOART_PROCESS_DELAY) == 0 )
{
Log( "ERROR !! FOART_PROCESS_DELAY is too small" );
return;
}
FOArtRunning.insertLast( @FOArt_Running( foart, map.Id, hexX, hexY, ownerId ));
if( FOART_TimeEvent == 0 )
timeEvent = true;
else
{
uint duration = 0;
array<uint> values;
if( !GetTimeEvent( FOART_TimeEvent, duration, values ))
{
Log( "WARNING ! FOArt time event not found, but its id is still set" );
timeEvent = true;
}
else
SetTimeEvent( FOART_TimeEvent, duration, values ); // !!!
}
if( timeEvent )
{
FOART_TimeEvent = CreateTimeEvent( __FullSecond+REAL_MS(FOART_PROCESS_DELAY), FOART_MODULE+"@e_FOART_Process", false );
DebugLog( "FOArt: created time event<"+FOART_TimeEvent+">" );
}
}
else
{
int result = foart.Spawn( map, hexX, hexY );
if( result < 0 )
Log( "FOArt: Spawn error "+result );
else
Log( "FOArt: spawned "+result+" item"+(result==1?"":"s") );
}
}
uint e_FOART_Process( array<uint>@ )
{
if( FOArtRunning.length() == 0 )
{
DebugLog( "FOArt: removed time event<"+FOART_TimeEvent+">" );
FOART_TimeEvent = 0;
return( 0 );
}
for( uint current=0, max=FOArtRunning.length(); current<max; current++ )
{
FOArtRunning[current].Process();
if( FOArtRunning[current].finished )
{
FOArtRunning.removeAt( current );
break;
}
}
return( REAL_MS(FOART_PROCESS_DELAY) );
}
#endif // __FOART_SERVER__ //