blob: b037b0bfdd64e6cfa6c5e9c3fc3ffef7ae83f1a9 (
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
|
/*
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()
{
entity_moduletypeid = 1;
set_name("Convoy ship");
set_label("ship");
set_modelname(model);
entity_thrust = 1.0f;
}
Member::~Member()
{
}
void Member::frame(float seconds)
{
get_location() += axis().forward() * speed() * thrust() * seconds;
}
/* ---- class Convoy ----------------------------------------------- */
Convoy::Convoy(core::Zone *zone) : core::EntityDynamic()
{
entity_moduletypeid = 2;
set_zone(zone);
set_label("convoy");
set_name("Convoy");
entity_speed = 1.0f;
set_serverside();
}
Convoy::~Convoy()
{
convoy_members.clear();
}
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(zone());
member->get_color().assign(color());
member->get_color_second().assign(color_second());
member->entity_thrust = 1.0f;
member->entity_speed = speed();
member->get_location().assign(location());
d = ((float) convoy_members.size()) * 0.5f;
member->get_location().get_x() += math::randomf((float) convoy_members.size()) - d;
member->get_location().get_y() += math::randomf((float) convoy_members.size()) - d;
member->get_location().get_z() += (math::randomf((float) convoy_members.size()) - d) * 0.5f;
member->get_axis().assign(axis());
}
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->model()->name());
member->die();
convoy_members.erase(it++);
add(model);
} else {
++it;
}
}
}
}
|