-
Notifications
You must be signed in to change notification settings - Fork 0
/
etheria-1pt2_0xb21.sol
579 lines (530 loc) · 22.9 KB
/
etheria-1pt2_0xb21.sol
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
/*
Etheria v1.2
Block 459708
Oct-29-2015 09:11:55 PM +UTC
0xb21f8684f23dbb1008508b4de91a0aaedebdb7e4
{
"54385526": "setStatus(uint8,uint8,string)", // unused (costs 1 ETH)
"2ef761d3": "buyTile(uint8,uint8)", // unused (sold out - attempting to buy already-owned tiles will lose your ETH)
"8cae1374": "editBlock(uint8,uint8,uint256,int8[5])", // unused under modern build mechanics
"f2a75fe4": "empty()",
"90fd53ec": "farmTile(uint8,uint8,int8)", // unused under modern build mechanics
"fa93019c": "getBlocks(uint8,uint8)", // unused under modern build mechanics
"8435be4b": "getLastFarm(uint8,uint8)", // unused under modern build mechanics
"2d49ffcd": "getLocked()",
"a55cab95": "getName(uint8,uint8)",
"e039e4a1": "getOwner(uint8,uint8)",
"d39eb301": "getStatus(uint8,uint8)", // unused (setStatus costs 1 ETH)
"182db370": "getWhatHappened()",
"41c0e1b5": "kill()", // unkillable due to lock
"10c1952f": "setLocked()", // locking tx: 0x3964eeb306681cdc4c9adc83f1f395ac55a8dd4d8000b4f29338f145cd87c2f1
"93eec1fb": "setName(uint8,uint8,string)",
"7d5fec5a": "setOwner(uint8,uint8,address)" // uses tx.origin - tiles can only be owned by end-user accounts ( DO NOT SEND TO A CONTRACT. YOUR TILE WILL BE LOST)
}
var etheriaAddress = "0xb21f8684f23dbb1008508b4de91a0aaedebdb7e4";
var abi = [
{"constant":false,"inputs":[],"name":"setLocked","outputs":[],"type":"functin"},
{"constant":true,"inputs":[],"name":"getWhatHappened","outputs":[{"name":"","type":"string"}],"type":"function"},
{"constant":true,"inputs":[],"name":"getLocked","outputs":[{"name":"","type":"bool"}],"type":"function"},
{"constant":false,"inputs":[{"name":"col","type":"uint8"},{"name":"row","type":"uint8"}],"name":"buyTile","outputs":[],"type":"function"},
{"constant":false,"inputs":[],"name":"kill","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"col","type":"uint8"},{"name":"row","type":"uint8"},{"name":"_s","type":"string"}],"name":"setStatus","outputs":[],"type":"function"},
{"constant":false,"inputs":[{"name":"col","type":"uint8"},{"name":"row","type":"uint8"},{"name":"newowner","type":"address"}],"name":"setOwner","outputs":[],"type":"function"},
{"constant":true,"inputs":[{"name":"col","type":"uint8"},{"name":"row","type":"uint8"}],"name":"getLastFarm","outputs":[{"name":"","type":"uint256"}],"type":"function"},
{"constant":false,"inputs":[{"name":"col","type":"uint8"},{"name":"row","type":"uint8"},{"name":"index","type":"uint256"},{"name":"_block","type":"int8[5]"}],"name":"editBlock","outputs":[],"type":"function"},
{"constant":false,"inputs":[{"name":"col","type":"uint8"},{"name":"row","type":"uint8"},{"name":"blocktype","type":"int8"}],"name":"farmTile","outputs":[],"type":"function"},
{"constant":false,"inputs":[{"name":"col","type":"uint8"},{"name":"row","type":"uint8"},{"name":"_n","type":"string"}],"name":"setName","outputs":[],"type":"function"},
{"constant":true,"inputs":[{"name":"col","type":"uint8"},{"name":"row","type":"uint8"}],"name":"getName","outputs":[{"name":"","type":"string"}],"type":"function"},
{"constant":true,"inputs":[{"name":"col","type":"uint8"},{"name":"row","type":"uint8"}],"name":"getStatus","outputs":[{"name":"","type":"string"}],"type":"function"},
{"constant":true,"inputs":[{"name":"col","type":"uint8"},{"name":"row","type":"uint8"}],"name":"getOwner","outputs":[{"name":"","type":"address"}],"type":"function"},
{"constant":false,"inputs":[],"name":"empty","outputs":[],"type":"function"},
{"constant":true,"inputs":[{"name":"col","type":"uint8"},{"name":"row","type":"uint8"}],"name":"getBlocks","outputs":[{"name":"","type":"int8[5][]"}],"type":"function"},
{"inputs":[],"type":"constructor"},
{"anonymous":false,"inputs":[{"indexed":false,"name":"col","type":"uint8"},{"indexed":false,"name":"row","type":"uint8"}],"name":"TileChanged","type":"event"}
];
var etheria = new web3.eth.Contract(abi, etheriaAddress);
Verified by Etherscan in Nov 2021 by triple-compiling with 0.1.6-d41f8b7c solc main release.
*/
contract BlockDefStorage
{
function getOccupies(uint8 blocktype) public returns (int8[24])
{}
function getAttachesto(uint8 blocktype) public returns (int8[48])
{}
}
contract MapElevationRetriever
{
function getElevation(uint8 col, uint8 row) public constant returns (uint8)
{}
}
contract Etheria
{
event TileChanged(uint8 col, uint8 row);//, address owner, string name, string status, uint lastfarm, address[] offerers, uint[] offers, int8[5][] blocks);
uint8 mapsize = 33;
Tile[33][33] tiles;
address creator;
struct Tile
{
address owner;
string name;
string status;
int8[5][] blocks; //0 = blocktype,1 = blockx,2 = blocky,3 = blockz, 4 = color
uint lastfarm;
int8[3][] occupado; // the only one not reported in the //TileChanged event
}
BlockDefStorage bds;
MapElevationRetriever mer;
function Etheria() {
creator = tx.origin;
bds = BlockDefStorage(0xd4e686a1fbf1bfe058510f07cd3936d3d5a70589);
mer = MapElevationRetriever(0x68549d7dbb7a956f955ec1263f55494f05972a6b);
}
function getOwner(uint8 col, uint8 row) public constant returns(address)
{
return tiles[col][row].owner; // no harm if col,row are invalid
}
function setOwner(uint8 col, uint8 row, address newowner)
{
// if(isOOB(col,row)) // row and/or col was not between 0-mapsize
// {
// whathappened = "setOwner:ERR:c,r OOB";
// return;
// }
Tile tile = tiles[col][row];
if(tile.owner != tx.origin && !(tx.origin == creator && !getLocked()))
{
whathappened = "setOwner:ERR:not owner";
return;
}
tile.owner = newowner;
TileChanged(col,row);
whathappened = "setOwner:OK";
return;
}
/***
* _ _ ___ ___ ___ _____ _____ _____ ___ _____ _ _ _____
* | \ | | / _ \ | \/ || ___| ___ / ___|_ _/ _ \_ _| | | / ___|
* | \| |/ /_\ \| . . || |__ ( _ ) \ `--. | |/ /_\ \| | | | | \ `--.
* | . ` || _ || |\/| || __| / _ \/\ `--. \ | || _ || | | | | |`--. \
* | |\ || | | || | | || |___ | (_> < /\__/ / | || | | || | | |_| /\__/ /
* \_| \_/\_| |_/\_| |_/\____/ \___/\/ \____/ \_/\_| |_/\_/ \___/\____/
*
*
*/
function getName(uint8 col, uint8 row) public constant returns(string)
{
return tiles[col][row].name; // no harm if col,row are invalid
}
function setName(uint8 col, uint8 row, string _n) public
{
// if(isOOB(col,row)) // row and/or col was not between 0-mapsize
// {
// whathappened = "setName:ERR:c,r OOB";
// return;
// }
Tile tile = tiles[col][row];
if(tile.owner != tx.origin && !(tx.origin == creator && !getLocked()))
{
whathappened = "setName:ERR:not owner";
return;
}
tile.name = _n;
TileChanged(col,row);
whathappened = "setName:OK";
return;
}
function getStatus(uint8 col, uint8 row) public constant returns(string)
{
return tiles[col][row].status; // no harm if col,row are invalid
}
function setStatus(uint8 col, uint8 row, string _s) public // setting status costs 1 eth to prevent spam
{
// if(isOOB(col,row)) // row and/or col was not between 0-mapsize
// {
// tx.origin.send(msg.value); // return their money, if any
// whathappened = "setStatus:ERR:c,r OOB";
// return;
// }
if(msg.value != 1000000000000000000)
{
tx.origin.send(msg.value); // return their money, if any
whathappened = "setStatus:ERR:val!=1eth";
return;
}
Tile tile = tiles[col][row];
if(tile.owner != tx.origin && !(tx.origin == creator && !getLocked()))
{
tx.origin.send(msg.value); // return their money, if any
whathappened = "setStatus:ERR:not owner";
return;
}
tile.status = _s;
creator.send(msg.value);
TileChanged(col,row);
whathappened = "setStatus:OK";
return;
}
/***
* ______ ___ _________ ________ _ _ _____ ___________ _____ _____ _____ _ _ _____
* | ___/ _ \ | ___ \ \/ |_ _| \ | | __ \ ___ | ___| _ \_ _|_ _|_ _| \ | | __ \
* | |_ / /_\ \| |_/ / . . | | | | \| | | \/ ( _ ) | |__ | | | | | | | | | | | \| | | \/
* | _|| _ || /| |\/| | | | | . ` | | __ / _ \/\ | __|| | | | | | | | | | | . ` | | __
* | | | | | || |\ \| | | |_| |_| |\ | |_\ \ | (_> < | |___| |/ / _| |_ | | _| |_| |\ | |_\ \
* \_| \_| |_/\_| \_\_| |_/\___/\_| \_/\____/ \___/\/ \____/|___/ \___/ \_/ \___/\_| \_/\____/
*
*/
function getLastFarm(uint8 col, uint8 row) public constant returns (uint)
{
return tiles[col][row].lastfarm;
}
function farmTile(uint8 col, uint8 row, int8 blocktype) public
{
// if(isOOB(col,row)) // row and/or col was not between 0-mapsize
// {
// tx.origin.send(msg.value); // return their money, if any
// whathappened = "farmTile:ERR:c,r OOB";
// return;
// }
if(blocktype < 0 || blocktype > 17) // invalid blocktype
{
tx.origin.send(msg.value); // return their money, if any
whathappened = "farmTile:ERR:invalid blocktype";
return;
}
Tile tile = tiles[col][row];
if(tile.owner != tx.origin)
{
tx.origin.send(msg.value); // return their money, if any
whathappened = "farmTile:ERR:not owner";
return;
}
if((block.number - tile.lastfarm) < 2500) // ~12 hours of blocks
{
if(msg.value != 1000000000000000000)
{
tx.origin.send(msg.value); // return their money
whathappened = "farmTile:ERR:val!=1eth";
return;
}
else // they paid 1 ETH
{
creator.send(msg.value); // If they haven't waited long enough, but they've paid 1 eth, let them farm again.
}
}
else
{
if(msg.value > 0) // they've waited long enough but also sent money. Return it and continue normally.
{
tx.origin.send(msg.value); // return their money
}
}
// by this point, they've either waited 2500 blocks or paid 1 ETH
for(uint8 i = 0; i < 10; i++)
{
tile.blocks.length+=1;
tile.blocks[tile.blocks.length - 1][0] = int8(blocktype); // blocktype 0-17
tile.blocks[tile.blocks.length - 1][1] = 0; // x
tile.blocks[tile.blocks.length - 1][2] = 0; // y
tile.blocks[tile.blocks.length - 1][3] = -1; // z
tile.blocks[tile.blocks.length - 1][4] = 0; // color
}
tile.lastfarm = block.number;
TileChanged(col,row);
whathappened = "farmTile:OK";
return;
}
function editBlock(uint8 col, uint8 row, uint index, int8[5] _block) // NOTE: won't return accidental money.
{
// if(isOOB(col,row)) // row and/or col was not between 0-mapsize
// {
// whathappened = "editBlock:ERR:c,r OOB";
// return;
// }
Tile tile = tiles[col][row];
if(tile.owner != tx.origin) // 1. DID THE OWNER SEND THIS MESSAGE?
{
whathappened = "editBlock:ERR:not owner";
return;
}
if(_block[3] < 0) // 2. IS THE Z LOCATION OF THE BLOCK BELOW ZERO? BLOCKS CANNOT BE HIDDEN
{
whathappened = "editBlock:ERR:can't hide blocks";
return;
}
if(index > (tile.blocks.length-1))
{
whathappened = "editBlock:ERR:index OOR";
return;
}
if(_block[0] == -1) // user has signified they want to only change the color of this block
{
tile.blocks[index][4] = _block[4];
whathappened = "editBlock:OK:color changed";
return;
}
_block[0] = tile.blocks[index][0]; // can't change the blocktype, so set it to whatever it already was
int8[24] memory didoccupy = bds.getOccupies(uint8(_block[0]));
int8[24] memory wouldoccupy = bds.getOccupies(uint8(_block[0]));
for(uint8 b = 0; b < 24; b+=3) // always 8 hexes, calculate the didoccupy
{
wouldoccupy[b] = wouldoccupy[b]+_block[1];
wouldoccupy[b+1] = wouldoccupy[b+1]+_block[2];
if(wouldoccupy[1] % 2 != 0 && wouldoccupy[b+1] % 2 == 0) // if anchor y is odd and this hex y is even, (SW NE beam goes 11,`2`2,23,`3`4,35,`4`6,47,`5`8 ` = x value incremented by 1. Same applies to SW NE beam from 01,12,13,24,25,36,37,48)
wouldoccupy[b] = wouldoccupy[b]+1; // then offset x by +1
wouldoccupy[b+2] = wouldoccupy[b+2]+_block[3];
didoccupy[b] = didoccupy[b]+tile.blocks[index][1];
didoccupy[b+1] = didoccupy[b+1]+tile.blocks[index][2];
if(didoccupy[1] % 2 != 0 && didoccupy[b+1] % 2 == 0) // if anchor y and this hex y are both odd,
didoccupy[b] = didoccupy[b]+1; // then offset x by +1
didoccupy[b+2] = didoccupy[b+2]+tile.blocks[index][3];
}
if(!isValidLocation(col,row,_block, wouldoccupy))
{
return; // whathappened is already set
}
// EVERYTHING CHECKED OUT, WRITE OR OVERWRITE THE HEXES IN OCCUPADO
if(tile.blocks[index][3] >= 0) // If the previous z was greater than 0 (i.e. not hidden) ...
{
for(uint8 l = 0; l < 24; l+=3) // loop 8 times,find the previous occupado entries and overwrite them
{
for(uint o = 0; o < tile.occupado.length; o++)
{
if(didoccupy[l] == tile.occupado[o][0] && didoccupy[l+1] == tile.occupado[o][1] && didoccupy[l+2] == tile.occupado[o][2]) // x,y,z equal?
{
tile.occupado[o][0] = wouldoccupy[l]; // found it. Overwrite it
tile.occupado[o][1] = wouldoccupy[l+1];
tile.occupado[o][2] = wouldoccupy[l+2];
}
}
}
}
else // previous block was hidden
{
for(uint8 ll = 0; ll < 24; ll+=3) // add the 8 new hexes to occupado
{
tile.occupado.length++;
tile.occupado[tile.occupado.length-1][0] = wouldoccupy[ll];
tile.occupado[tile.occupado.length-1][1] = wouldoccupy[ll+1];
tile.occupado[tile.occupado.length-1][2] = wouldoccupy[ll+2];
}
}
tile.blocks[index] = _block;
TileChanged(col,row);
return;
}
function getBlocks(uint8 col, uint8 row) public constant returns (int8[5][])
{
return tiles[col][row].blocks; // no harm if col,row are invalid
}
// three OK conditions:
// 1. Valid offer on unowned tile. (whathap = 4)
// 2. Valid offer on owned tile where offerer did not previously have an offer on file (whathap = 7)
// 3. Valid offer on owned tile where offerer DID have a previous offer on file (whathap = 6)
function buyTile(uint8 col, uint8 row)
{
// if(isOOB(col,row)) // row and/or col was not between 0-mapsize
// {
// tx.origin.send(msg.value); // return their money, if any
// whathappened = "buyTile:ERR:c,r OOB";
// return;
// }
//
if(msg.value != 1000000000000000000) // 1 ETH is the starting value. If not return; // Also, if below sea level, return.
{
tx.origin.send(msg.value); // return their money, if any
whathappened = "buyTile:ERR:val!=1eth";
return;
}
Tile tile = tiles[col][row];
if(tile.owner == address(0x0000000000000000000000000000000000000000)) // if UNOWNED
{
if(mer.getElevation(col,row) < 125) // 1 ETH is the starting value. If not return; // Also, if below sea level, return.
{
tx.origin.send(msg.value); // return their money
whathappened = "buyTile:ERR:water";
return;
}
else
{
creator.send(msg.value); // this was a valid offer, send money to contract creator
tile.owner = tx.origin; // set tile owner to the buyer
TileChanged(col,row);
whathappened = "buyTile:OK";
return;
}
}
else
{
tx.origin.send(msg.value); // return their money, if any
whathappened = "buyTile:ERR:alr owned";
return;
}
}
/***
* _ _ _____ _____ _ _____ _______ __
* | | | |_ _|_ _| | |_ _|_ _\ \ / /
* | | | | | | | | | | | | | | \ V /
* | | | | | | | | | | | | | | \ /
* | |_| | | | _| |_| |_____| |_ | | | |
* \___/ \_/ \___/\_____/\___/ \_/ \_/
*
*/
// this logic COULD be reduced a little, but the gain is minimal and readability suffers
function blockHexCoordsValid(int8 x, int8 y) private constant returns (bool)
{
uint absx;
uint absy;
if(x < 0)
absx = uint(x*-1);
else
absx = uint(x);
if(y < 0)
absy = uint(y*-1);
else
absy = uint(y);
if(absy <= 33) // middle rectangle
{
if(y % 2 != 0 ) // odd
{
if(-50 <= x && x <= 49)
return true;
}
else // even
{
if(absx <= 49)
return true;
}
}
else
{
if((y >= 0 && x >= 0) || (y < 0 && x > 0)) // first or 4th quadrants
{
if(y % 2 != 0 ) // odd
{
if (((absx*2) + (absy*3)) <= 198)
return true;
}
else // even
{
if ((((absx+1)*2) + ((absy-1)*3)) <= 198)
return true;
}
}
else
{
if(y % 2 == 0 ) // even
{
if (((absx*2) + (absy*3)) <= 198)
return true;
}
else // odd
{
if ((((absx+1)*2) + ((absy-1)*3)) <= 198)
return true;
}
}
}
return false;
}
// SEVERAL CHECKS TO BE PERFORMED
// 1. DID THE OWNER SEND THIS MESSAGE? (SEE editBlock)
// 2. IS THE Z LOCATION OF THE BLOCK BELOW ZERO? BLOCKS CANNOT BE HIDDEN AFTER SHOWING (SEE editBlock)
// 3. DO ANY OF THE PROPOSED HEXES FALL OUTSIDE OF THE TILE?
// 4. DO ANY OF THE PROPOSED HEXES CONFLICT WITH ENTRIES IN OCCUPADO?
// 5. DO ANY OF THE BLOCKS TOUCH ANOTHER?
// 6. NONE OF THE OCCUPY BLOCKS TOUCHED THE GROUND. BUT MAYBE THEY TOUCH ANOTHER BLOCK?
function isValidLocation(uint8 col, uint8 row, int8[5] _block, int8[24] wouldoccupy) private constant returns (bool)
{
bool touches;
Tile tile = tiles[col][row]; // since this is a private method, we don't need to check col,row validity
for(uint8 b = 0; b < 24; b+=3) // always 8 hexes, calculate the wouldoccupy and the didoccupy
{
if(!blockHexCoordsValid(wouldoccupy[b], wouldoccupy[b+1])) // 3. DO ANY OF THE PROPOSED HEXES FALL OUTSIDE OF THE TILE?
{
whathappened = "editBlock:ERR:OOB";
return false;
}
for(uint o = 0; o < tile.occupado.length; o++) // 4. DO ANY OF THE PROPOSED HEXES CONFLICT WITH ENTRIES IN OCCUPADO?
{
if(wouldoccupy[b] == tile.occupado[o][0] && wouldoccupy[b+1] == tile.occupado[o][1] && wouldoccupy[b+2] == tile.occupado[o][2]) // do the x,y,z entries of each match?
{
whathappened = "editBlock:ERR:conflict";
return false; // this hex conflicts. The proposed block does not avoid overlap. Return false immediately.
}
}
if(touches == false && wouldoccupy[b+2] == 0) // 5. DO ANY OF THE BLOCKS TOUCH ANOTHER? (GROUND ONLY FOR NOW)
{
touches = true; // once true, always true til the end of this method. We must keep looping to check all the hexes for conflicts and tile boundaries, though, so we can't return true here.
}
}
// now if we're out of the loop and here, there were no conflicts and the block was found to be in the tile boundary.
// touches may be true or false, so we need to check
if(touches == false) // 6. NONE OF THE OCCUPY BLOCKS TOUCHED THE GROUND. BUT MAYBE THEY TOUCH ANOTHER BLOCK?
{
int8[48] memory attachesto = bds.getAttachesto(uint8(_block[0]));
for(uint8 a = 0; a < 48 && !touches; a+=3) // always 8 hexes, calculate the wouldoccupy and the didoccupy
{
if(attachesto[a] == 0 && attachesto[a+1] == 0 && attachesto[a+2] == 0) // there are no more attachestos available, break (0,0,0 signifies end)
break;
//attachesto[a] = attachesto[a]+_block[1];
attachesto[a+1] = attachesto[a+1]+_block[2];
if(attachesto[1] % 2 != 0 && attachesto[a+1] % 2 == 0) // (for attachesto, anchory is the same as for occupies, but the z is different. Nothing to worry about)
attachesto[a] = attachesto[a]+1; // then offset x by +1
//attachesto[a+2] = attachesto[a+2]+_block[3];
for(o = 0; o < tile.occupado.length && !touches; o++)
{
if((attachesto[a]+_block[1]) == tile.occupado[o][0] && attachesto[a+1] == tile.occupado[o][1] && (attachesto[a+2]+_block[3]) == tile.occupado[o][2]) // a valid attachesto found in occupado?
{
whathappened = "editBlock:OK:attached";
return true; // in bounds, didn't conflict and now touches is true. All good. Return.
}
}
}
whathappened = "editBlock:ERR:floating";
return false;
}
else // touches was true by virtue of a z = 0 above (touching the ground). Return true;
{
whathappened = "editBlock:OK:ground";
return true;
}
}
// function isOOB(uint8 col, uint8 row) private constant returns (bool)
// {
// if(col < 0 || col > (mapsize-1) || row < 0 || row > (mapsize-1))
// return true; // is out of bounds
// }
string whathappened;
function getWhatHappened() public constant returns (string)
{
return whathappened;
}
/***
Return money fallback and empty random funds, if any
*/
function()
{
tx.origin.send(msg.value);
}
function empty()
{
creator.send(address(this).balance); // etheria should never hold a balance. But in case it does, at least provide a way to retrieve them.
}
/**********
Standard lock-kill methods
**********/
bool locked; // until locked, creator can kill, set names, statuses and tile ownership.
function setLocked()
{
if (msg.sender == creator)
locked = true;
}
function getLocked() public constant returns (bool)
{
return locked;
}
function kill()
{
if (!getLocked() && msg.sender == creator)
suicide(creator); // kills this contract and sends remaining funds back to creator
}
}