Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2014-12-22 16:57:20 +0000
committerStijn Buys <ingar@osirion.org>2014-12-22 16:57:20 +0000
commite7061d6fed8bdfc1828315eb8745cd919cb96bbc (patch)
treede614d556c748542ef169f1e4c295a832efdaae9 /src/core
parent871552eab28d07c3aaf0cabb5fb167c0eb365bdf (diff)
Prevent wingmen from getting destroyed when you buy a new ship or use the 'give ship' engine command.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/gameinterface.cc77
-rw-r--r--src/core/gameinterface.h3
2 files changed, 60 insertions, 20 deletions
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index aa4ef4c..8ecd697 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -26,9 +26,11 @@ namespace core
void func_list_players(std::string const &args)
{
- if (args.size()) {
+ if (args.size())
+ {
Player *player = game()->find_player(args);
- if (!player) {
+ if (!player)
+ {
con_print << "^BPlayer '" + args + "^B' not found";
return;
} else {
@@ -44,9 +46,11 @@ Player GameInterface::game_localplayer(0);
EntityControlable *localcontrol()
{
if (game()->localplayer())
+ {
return game()->localplayer()->control();
- else
+ } else {
return 0;
+ }
}
Player *localplayer()
@@ -59,7 +63,8 @@ GameInterface::GameInterface()
clear();
game_localplayer.clear();
- if (Cvar::sv_dedicated->value()) {
+ if (Cvar::sv_dedicated->value())
+ {
game_localplayer.player_name.assign("Console");
} else {
game_localplayer.player_name.assign("Player");
@@ -94,7 +99,8 @@ GameInterface::~GameInterface()
clear();
// delete vertex array
- if (game_vertexarray) {
+ if (game_vertexarray)
+ {
delete game_vertexarray;
game_vertexarray = 0;
}
@@ -119,9 +125,11 @@ void GameInterface::clear()
model::Material::clear();
// clear player list
- for (Players::iterator it = game_players.begin(); it != game_players.end(); it++) {
+ for (Players::iterator it = game_players.begin(); it != game_players.end(); it++)
+ {
Player *player = (*it);
- if (player != localplayer()) {
+ if (player != localplayer())
+ {
delete player;
}
}
@@ -129,8 +137,10 @@ void GameInterface::clear()
game_playerlist_timestamp = 0;
// remove all game functions
- for (Func::Registry::iterator it = Func::registry().begin(); it != Func::registry().end();) {
- if (((*it).second->flags() & Func::Game) == Func::Game) {
+ for (Func::Registry::iterator it = Func::registry().begin(); it != Func::registry().end();)
+ {
+ if (((*it).second->flags() & Func::Game) == Func::Game)
+ {
delete(*it).second;
Func::registry().erase(it++);
} else {
@@ -139,8 +149,10 @@ void GameInterface::clear()
}
// remove all game cvars
- for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end();) {
- if (((*it).second->flags() & Cvar::Game) == Cvar::Game) {
+ for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end();)
+ {
+ if (((*it).second->flags() & Cvar::Game) == Cvar::Game)
+ {
delete(*it).second;
Cvar::registry().erase(it++);
} else {
@@ -172,40 +184,64 @@ void GameInterface::set_playerlist_timestamp(const unsigned long timestamp)
game_playerlist_timestamp = ( timestamp > 0 ? timestamp : 1);
}
-void GameInterface::abort() {
+void GameInterface::abort()
+{
game_running = false;
}
Player *GameInterface::find_player(const int playerid)
{
- if (playerid == 0) {
+ if (playerid == 0)
+ {
return 0;
}
- for (std::list<Player *>:: iterator it = game_players.begin(); it != game_players.end(); it++) {
- if ((*it)->id() == playerid) {
+ for (Players::iterator it = game_players.begin(); it != game_players.end(); it++)
+ {
+ if ((*it)->id() == playerid)
+ {
return (*it);
}
}
return 0;
}
+Player *GameInterface::find_player(const Player *player)
+{
+ if (player)
+ {
+ for (Players::iterator it = game_players.begin(); it != game_players.end(); it++)
+ {
+ if ((*it) == player)
+ {
+ return (*it);
+ }
+ }
+ }
+ return 0;
+}
+
Player *GameInterface::find_player(const std::string &search)
{
std::istringstream searchstr(search);
int id = 0;
if (searchstr >> id) {
- for (std::list<Player *>:: iterator it = game_players.begin(); it != game_players.end(); it++) {
- if ((*it)->id() == id) {
+ for (Players:: iterator it = game_players.begin(); it != game_players.end(); it++)
+ {
+ if ((*it)->id() == id)
+ {
return (*it);
}
}
}
if (search.size() < 3)
+ {
return 0;
+ }
- for (std::list<Player *>:: iterator it = game_players.begin(); it != game_players.end(); it++) {
+ for (Players:: iterator it = game_players.begin(); it != game_players.end(); it++)
+ {
if (aux::text_strip_lowercase((*it)->name()).find(aux::lowercase(search)) != std::string::npos)
return (*it);
}
@@ -217,7 +253,8 @@ void GameInterface::list_players()
{
int count = 0;
- for (Players::iterator it = game_players.begin(); it != game_players.end(); it++) {
+ for (Players::const_iterator it = game_players.begin(); it != game_players.end(); it++)
+ {
const Player *player = (*it);
con_print << " " << std::setfill(' ')
<< aux::pad_left(player->name(), 24) << "^N "
@@ -235,4 +272,4 @@ void GameInterface::list_players()
con_print << count << " connected " << aux::plural("player", count) << std::endl;
}
-}
+} // namespace core
diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h
index f118ad3..f204c04 100644
--- a/src/core/gameinterface.h
+++ b/src/core/gameinterface.h
@@ -52,6 +52,9 @@ public:
/// find a player id
Player *find_player(const int playerid);
+
+ /// find a player
+ Player *find_player(const Player *player);
/// show a list of connected players
void list_players();