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

#include "intro/convoy.h"

namespace intro {


/* ---- class Member ----------------------------------------------- */

Member::Member(std::string const &model) : core::EntityControlable(0, 1)
{
	set_name("Convoy member");
	set_label(model);

	set_modelname("ships/" + model);

	entity_thrust = 1.0f;
/*
	entity_speed = 1.0f;

	entity_location.x = -16.0f;
	entity_location.y = -math::randomf(8.0f);
	entity_location.z = math::randomf(8.0f) - 6.0f;

	entity_axis.change_direction(15.0f);
*/
}

Member::~Member()
{
}

void Member::frame(float seconds)
{
	entity_location += entity_axis.forward() * speed() * thrust() * seconds;
}

/* ---- class convoy ----------------------------------------------- */

Convoy::Convoy(core::Zone *zone)
{
	convoy_zone = zone;
	convoy_speed = 1;
}

Convoy::~Convoy()
{
	convoy_members.clear();
}

void Convoy::set_color(const math::Color &color)
{
	convoy_color.assign(color);
}
void Convoy::set_color_second(const math::Color &color)
{
	convoy_color_second.assign(color);
}

void Convoy::set_location(const math::Vector3f &location)
{
	convoy_location.assign(location);
}

void Convoy::change_direction(float angle)
{
	convoy_axis.change_direction(angle);
}

void Convoy::set_speed(const float speed)
{
	convoy_speed = speed;
}

void Convoy::add(const char *model)
{
	add(std::string(model));
}

void Convoy::add(const std::string &model)
{
	float d = 0;

	Member *member = new Member(model);
	convoy_members.push_back(member);
	member->set_zone(convoy_zone);
	member->entity_color.assign(convoy_color);
	member->entity_color_second.assign(convoy_color_second);

	member->entity_thrust = 1.0f;
	member->entity_speed = convoy_speed;

	member->entity_location.assign(convoy_location);
	d = ((float) convoy_members.size()) * 0.5f;

	member->entity_location.x += math::randomf((float) convoy_members.size()) -d;
	member->entity_location.y += math::randomf((float) convoy_members.size()) -d;
	member->entity_location.z += (math::randomf((float) convoy_members.size()) -d) * 0.5f;

	member->entity_axis.change_direction(15.0f);
}

void Convoy::frame(float seconds)
{
	for (Members::iterator it = convoy_members.begin(); it != convoy_members.end(); ) {
		Member *member = (*it);
		if (member->location().length() > 64.0f) {
			std::string model(member->label());
 			member->die();
			convoy_members.erase(it++);
			add(model);
		} else {
			++it;
		}
	}
}

}