-
Notifications
You must be signed in to change notification settings - Fork 2
/
PlayerData.cpp
120 lines (106 loc) · 3.01 KB
/
PlayerData.cpp
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
// @Begin License@
// This file is part of Coldest.
//
// Coldest is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Coldest 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Coldest. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright 2008-2012 Ben Nemec
// @End License@
#include "PlayerData.h"
#include "globals.h"
PlayerData::PlayerData(Meshlist& ml) : speed(0.f), turnspeed(0.f), needsync(true), mesh(numbodyparts, ml.end()),
indicator(NULL),
item(Item::NoItem, ml), spawntimer(0), hp(intvec(numbodyparts, 100)),
destroyed(numbodyparts, false), team(0), name("Nooblet"), salvage(100), powerdowntime(0),
healaccum(0.f), weight(1.f), spectate(false), admin(false)
{
Uint32 ticks = 0;
if (SDL_WasInit(SDL_INIT_TIMER))
{
ticks = SDL_GetTicks();
}
recpacketnum = 0;
addr.host = INADDR_NONE;
addr.port = 0; // Theoretically this should be 0 regardless of byte-order...but I could be wrong
connected = false;
spawned = false;
lastupdate = ticks;
unit = numunits;
kills = 0;
deaths = 0;
lastmovetick = lastcoolingtick = ticks;
pos = Vector3();
pitch = roll = rotation = facing = 0.f;
moveleft = moveright = moveforward = moveback = false;
size = 0;
leftclick = rightclick = run = false;
meshes = &ml;
currweapon = 0;
ping = 0;
temperature = 0.f;
fallvelocity = 0.f;
Weapon none(Weapon::NoWeapon);
for (int i = 0; i < numbodyparts; ++i)
{
mesh.push_back(ml.end());
weapons.push_back(none);
lastfiretick.push_back(0);
}
}
void PlayerData::Disconnect()
{
connected = false;
Kill();
}
void PlayerData::Kill()
{
spawned = false;
leftclick = false;
ClearMeshes();
if (indicator)
{
indicator->ttl = 1;
indicator = NULL;
}
}
void PlayerData::ClearMeshes(bool erase)
{
for (int part = 0; part < numbodyparts; ++part)
{
if (mesh[part] != meshes->end())
{
if (erase)
meshes->erase(mesh[part]);
mesh[part] = meshes->end();
}
}
}
void PlayerData::Reset()
{
pitch = roll = rotation = facing = 0.f;
moveleft = moveright = moveforward = moveback = false;
leftclick = rightclick = run = false;
temperature = 0.f;
fallvelocity = 0.f;
currweapon = 0;
speed = turnspeed = 0.f;
destroyed = vector<bool>(numbodyparts, false);
healaccum = 0.f;
firerequests.clear();
weight = 1.f;
}
Weapon& PlayerData::CurrentWeapon()
{
int weaponslot = weaponslots[currweapon];
return weapons[weaponslot];
}