Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 77e534f19d8bba0e7f3aec4526fd4ba1e7094feb (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
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
/*
   game/game.cc
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#include <vector>

#include "game/game.h"
#include "game/ship.h"
#include "game/star.h"
#include "core/gameserver.h"
#include "sys/sys.h"
#include "math/mathlib.h"
#include "filesystem/filesystem.h"

namespace game
{

/*----- engine game functions ------------------------------------- */

/// a player joins the game
void func_join(core::Player *player, std::string const &args)
{
	if (player->control())
		return;

	player->player_control = new Ship(player, "micron_vector");
	player->control()->entity_color = player->color();
	
	std::string message(player->name());
	message.append(" joins the game.");
	core::server()->broadcast(message);

	player->player_dirty = true;
}

/// a player joins the spectators
void func_spectate(core::Player *player, std::string const &args)
{
	if (!player->player_control)
		return;

	std::string message(player->name());
	message.append(" spectates.");
	core::server()->broadcast(message);

	if (player->control()) {
		// player has only ship for now
		player->player_control->die();
		player->player_control = 0;
	}

	player->player_dirty = true;
}

/// a player buys a ship
void func_buy(core::Player *player, std::string const &args)
{
	if (!player->control()) {
		return;
	}

	std::string shipname;
	std::istringstream is(args);
	is >> shipname;
	if ((shipname == "micron_vector") || (shipname == "canasta")) {
		// player has only ship for now
		player->player_control->die();
		player->player_control = 0;
		
		player->player_control = new Ship(player, shipname);
		player->control()->entity_color = player->color();

		core::server()->broadcast(player->name() + " purchased a " + shipname);
		player->player_dirty = true;
	} else {
		core::server()->send(player, "Usage: buy <canasta|micron_vector>");
	}
}
/*----- Game ------------------------------------------------------ */

Game::Game() : core::Module("Project::OSiRiON")
{
}

Game::~Game()
{
}

void Game::init()
{
	using math::Vector3f;
	using math::Color;

	module_running = false;

	// setup the game world
	
	// the star
	Star *star = new Star();
	star->entity_location = Vector3f(256.0f, -256.0f, 0.0f);
	star->entity_name = "star: Sabishi Hoshi";

	// the green cube
	core::Entity *cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
	cube->entity_shape = core::Entity::Cube;
	cube->entity_color = Color(0.0f, 0.8f, 0.0f);
	cube->entity_location = Vector3f(24.0f, 24.0f, 0.0f);
	cube->entity_name ="ccube: Borg cube green";
	cube->entity_modelname = "ccube";
	cube->entity_moduletypeid = cube_enttype;

	// the red cube
	cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
	cube->entity_shape = core::Entity::Cube;
	cube->entity_color = Color(1.0f, 0.0f, 0.0f);
	cube->entity_location = Vector3f(16.0f, 16.0f, 0.0f);
	cube->entity_name = "cube: Borg cube red";
	cube->entity_modelname = "cube";
	cube->entity_moduletypeid = cube_enttype;

	// Canasta
	cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
	cube->entity_shape = core::Entity::Diamond;
	cube->entity_color = Color(0.5f, 1.0f, 5.0f);
	cube->entity_location = Vector3f(16.0f, 20.0f, 0.0f);
	cube->entity_name = "wreck: Canasta";
	cube->entity_modelname = "ships/canasta";

	// Micron Vector
	cube = new core::Entity(core::Entity::Solid & core::Entity::Static);
	cube->entity_shape = core::Entity::Diamond;
	cube->entity_color = Color(0.5f, 1.0f, 5.0f);
	cube->entity_location = Vector3f(17.0f, 21.0f, 0.0f);
	cube->entity_name = "wreck: Micron Vector";
	cube->entity_modelname = "ships/micron_vector";

	// Alexandria
	core::Entity *alexandria = new core::Entity(core::Entity::Solid & core::Entity::Static);
	alexandria->entity_location = Vector3f(0.0f, -64.0f, 0.0f);
	alexandria->entity_name = "station: Alexandria";
	alexandria->entity_modelname = "stations/alexandria";

	// the yellow sphere
	core::Entity *sphere = new core::Entity(core::Entity::Solid & core::Entity::Static);
	sphere->entity_shape = core::Entity::Sphere;
	sphere->entity_color = Color(0.8f, 0.8f, 0.0f);
	sphere->entity_location = Vector3f(0.0f, 32.0f, 0.0f);
	sphere->entity_name ="sphere: The Sphere";

	// the galactic origin
	core::Entity *axis = new core::Entity(core::Entity::Static);
	axis->entity_shape = core::Entity::Diamond;
	axis->entity_color = Color(1.0f, 1.0f, 0.0f);
	axis->entity_location = Vector3f(0, 0, 0);
	axis->entity_name = "axis: Origin";

	// add engine game functions
	core::Func::add("buy", (core::GameFuncPtr) func_buy);
	core::Func::add("join", (core::GameFuncPtr) func_join);
	core::Func::add("spectate", (core::GameFuncPtr) func_spectate);
	
	// add engine game variables
	core::Cvar::set("g_borgcubes", "2", core::Cvar::Game);
	core::Cvar::set("g_name", name().c_str(), core::Cvar::Game | core::Cvar::ReadOnly);
	
	// indicate the module is ready to run frames
	module_running = true;
}

void Game::shutdown()
{
	module_running = false;
}

void Game::frame(float seconds)
{
	if (!running())
		return;
}

void Game::player_connect(core::Player *player)
{
	std::string args;
	func_spectate(player, args);
}

void Game::player_disconnect(core::Player *player)
{
	if (player->control()) {
		// player has only one ship for now
		player->control()->die();
		player->player_control = 0;
	}
}

} // namespace game