aboutsummaryrefslogtreecommitdiff
path: root/src/unittest/test_modchannels.cpp
blob: 069f439a1efa463fb5e82cfa152934203e0f83df (plain)
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
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "test.h"

#include "gamedef.h"
#include "modchannels.h"

class TestModChannels : public TestBase
{
public:
	TestModChannels() { TestManager::registerTestModule(this); }
	const char *getName() { return "TestModChannels"; }

	void runTests(IGameDef *gamedef);

	void testJoinChannel(IGameDef *gamedef);
	void testLeaveChannel(IGameDef *gamedef);
	void testSendMessageToChannel(IGameDef *gamedef);
};

static TestModChannels g_test_instance;

void TestModChannels::runTests(IGameDef *gamedef)
{
	TEST(testJoinChannel, gamedef);
	TEST(testLeaveChannel, gamedef);
	TEST(testSendMessageToChannel, gamedef);
}

void TestModChannels::testJoinChannel(IGameDef *gamedef)
{
	// Test join
	UASSERT(gamedef->joinModChannel("test_join_channel"));
	// Test join (fail, already join)
	UASSERT(!gamedef->joinModChannel("test_join_channel"));
}

void TestModChannels::testLeaveChannel(IGameDef *gamedef)
{
	// Test leave (not joined)
	UASSERT(!gamedef->leaveModChannel("test_leave_channel"));

	UASSERT(gamedef->joinModChannel("test_leave_channel"));

	// Test leave (joined)
	UASSERT(gamedef->leaveModChannel("test_leave_channel"));
}

void TestModChannels::testSendMessageToChannel(IGameDef *gamedef)
{
	// Test sendmsg (not joined)
	UASSERT(!gamedef->sendModChannelMessage(
			"test_sendmsg_channel", "testmsgchannel"));

	UASSERT(gamedef->joinModChannel("test_sendmsg_channel"));

	// Test sendmsg (joined)
	UASSERT(gamedef->sendModChannelMessage("test_sendmsg_channel", "testmsgchannel"));
}
pan class="hl kwa">local y_max = math.min(maxp.y, height_max) local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1) local pr = PseudoRandom(seed) local num_chunks = math.floor(chunks_per_volume * volume) local chunk_size = 3 if ore_per_chunk <= 4 then chunk_size = 2 end local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk) --print("generate_ore num_chunks: "..dump(num_chunks)) for i=1,num_chunks do local y0 = pr:next(y_min, y_max-chunk_size+1) if y0 >= height_min and y0 <= height_max then local x0 = pr:next(minp.x, maxp.x-chunk_size+1) local z0 = pr:next(minp.z, maxp.z-chunk_size+1) local p0 = {x=x0, y=y0, z=z0} for x1=0,chunk_size-1 do for y1=0,chunk_size-1 do for z1=0,chunk_size-1 do if pr:next(1,inverse_chance) == 1 then local x2 = x0+x1 local y2 = y0+y1 local z2 = z0+z1 local p2 = {x=x2, y=y2, z=z2} if minetest.env:get_node(p2).name == wherein then minetest.env:set_node(p2, {name=name}) end end end end end end end --print("generate_ore done") end minetest.register_on_generated(function(minp, maxp, seed) generate_ore("default:stone_with_coal", "default:stone", minp, maxp, seed, 1/8/8/8, 5, -31000, 64) generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+1, 1/16/16/16, 5, -5, 7) generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+2, 1/12/12/12, 5, -16, -5) generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+3, 1/9/9/9, 5, -31000, -17) -- Generate clay if maxp.y >= 2 and minp.y <= 0 then -- Assume X and Z lengths are equal local divlen = 4 local divs = (maxp.x-minp.x)/divlen+1; for divx=0+1,divs-1-1 do for divz=0+1,divs-1-1 do local cx = minp.x + math.floor((divx+0.5)*divlen) local cz = minp.z + math.floor((divz+0.5)*divlen) if minetest.env:get_node({x=cx,y=1,z=cz}).name == "default:water_source" and minetest.env:get_node({x=cx,y=0,z=cz}).name == "default:sand" then local is_shallow = true local num_water_around = 0 if minetest.env:get_node({x=cx-divlen*2,y=1,z=cz+0}).name == "default:water_source" then num_water_around = num_water_around + 1 end if minetest.env:get_node({x=cx+divlen*2,y=1,z=cz+0}).name == "default:water_source" then num_water_around = num_water_around + 1 end if minetest.env:get_node({x=cx+0,y=1,z=cz-divlen*2}).name == "default:water_source" then num_water_around = num_water_around + 1 end if minetest.env:get_node({x=cx+0,y=1,z=cz+divlen*2}).name == "default:water_source" then num_water_around = num_water_around + 1 end if num_water_around >= 2 then is_shallow = false end if is_shallow then for x1=-divlen,divlen do for z1=-divlen,divlen do if minetest.env:get_node({x=cx+x1,y=0,z=cz+z1}).name == "default:sand" then minetest.env:set_node({x=cx+x1,y=0,z=cz+z1}, {name="default:clay"}) end end end end end end end end end)