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

#include "base/game.h"
#include "base/jumppoint.h"

namespace game
{

/* ---- class JumpPoint -------------------------------------------- */

JumpPoint::JumpPoint() : core::EntityDynamic(core::Entity::Static | core::Entity::Bright)
{
	entity_shape = core::Entity::Diamond;
	entity_color.assign(0.0f, 0.8f, 0.8f, 1.0f);
	entity_color_second.assign(0.6f, 1.0f);
	entity_radius = 0.25f;

	entity_moduletypeid = jumppoint_enttype;
	jumppoint_target = 0;
	entity_serverside = false;
}

JumpPoint::~JumpPoint()
{
}

void JumpPoint::set_targetlabel(const std::string &label) 
{
	jumppoint_targetlabel.assign(label);
}

void JumpPoint::validate()
{
	jumppoint_target = 0;

	if (targetlabel().size() < 3) {
		con_warn << "  Jumppoint with invalid target label '" << targetlabel() << "'\n";
		return;
	}
	size_t pos = targetlabel().find(':');
	if ((pos < 1 ) || (pos >= (targetlabel().size()-1))) {
		con_warn << "  Jumppoint with invalid target label '" << targetlabel() << "'\n";
		return;
	}

	std::string zonelabel(targetlabel().substr(0, pos));
	std::string entitylabel(targetlabel().substr(pos+1, targetlabel().size()-pos));

	core::Zone *targetzone = core::Zone::find(zonelabel);
	if (!targetzone) {
		con_warn << "  Jumppoint with invalid target zone '" << zonelabel << "'\n";
		return;
	}

	core::Entity *targetentity = targetzone->find_entity(entitylabel);
	if (!targetentity) {
		con_warn << "  Could not find target jumppoint '" << entitylabel << "'\n";
		return;
	}

	if ((targetentity->moduletype() != jumppoint_enttype) && (targetentity->moduletype() != jumpgate_enttype)) {
		con_warn << "  Jumppoint with invalid target jumppoint '" << entitylabel << "'\n";
		return;
	}

	jumppoint_target = static_cast<JumpPoint *>(targetentity);

	//con_debug << "  Jumppoint " << zone->label() << ":" << label() << " with target " << targetlabel() << std::endl;
}

/* ---- class JumpGate --------------------------------------------- */

JumpGate::JumpGate() : JumpPoint()
{
	unset_flag(core::Entity::Bright);
	entity_radius = 1.0f;
	entity_moduletypeid = jumpgate_enttype;
	set_flag(core::Entity::Dockable);

	entity_eventstate = core::Entity::NoPower;
}

JumpGate::~JumpGate()
{
}

void JumpGate::activate()
{
	jumpgate_timer = 10.0f;
	entity_eventstate = core::Entity::Normal;
}

void JumpGate::frame(float elapsed)
{
	if (jumpgate_timer > 0)
		jumpgate_timer -= elapsed;

	if (jumpgate_timer < 0) {
		entity_eventstate = core::Entity::NoPower;
	}
}

}