mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
changed namespace
This commit is contained in:
+98
-100
@@ -12,119 +12,117 @@
|
||||
#include "demoJet.h"
|
||||
#include "missileJet.h"
|
||||
|
||||
using namespace game::core;
|
||||
using namespace game::content;
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
|
||||
namespace game{
|
||||
namespace gui{
|
||||
ConsoleCommand::ConsoleCommand(Listbox *l, vector<Player*> players, string name, vector<string> args) {
|
||||
listbox = l;
|
||||
this->players = players;
|
||||
this->name = name;
|
||||
arguments = args;
|
||||
execute();
|
||||
namespace battleship{
|
||||
using namespace unitData;
|
||||
|
||||
ConsoleCommand::ConsoleCommand(Listbox *l, vector<Player*> players, string name, vector<string> args) {
|
||||
listbox = l;
|
||||
this->players = players;
|
||||
this->name = name;
|
||||
arguments = args;
|
||||
execute();
|
||||
}
|
||||
|
||||
ConsoleCommand::~ConsoleCommand() {
|
||||
}
|
||||
|
||||
void ConsoleCommand::execute() {
|
||||
if (name == commandList[0])
|
||||
addUnit();
|
||||
else if (name == commandList[1])
|
||||
debugUnits();
|
||||
else
|
||||
printConsoleMessage("No such command");
|
||||
}
|
||||
|
||||
void ConsoleCommand::addUnit() {
|
||||
int unitId = 0, playerId = 0;
|
||||
Vector3 pos(0, 0, 0);
|
||||
float angle = 0;
|
||||
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
arguments[i].erase(0);
|
||||
for (int i2 = 0; i2 < arguments[i].size(); i2++) {
|
||||
if (i == 0)
|
||||
playerId += (arguments[i][i2] - 48) * pow(10, arguments[i].size() - (i2 + 1));
|
||||
else
|
||||
unitId += (arguments[i][i2] - 48) * pow(10, arguments[i].size() - (i2 + 1));
|
||||
}
|
||||
}
|
||||
|
||||
ConsoleCommand::~ConsoleCommand() {
|
||||
}
|
||||
if ((playerId == 0 || playerId == 1) && (unitId >= 0 && unitId <= numberOfUnits)) {
|
||||
Unit *u = nullptr;
|
||||
|
||||
void ConsoleCommand::execute() {
|
||||
if (name == commandList[0])
|
||||
addUnit();
|
||||
else if (name == commandList[1])
|
||||
debugUnits();
|
||||
else
|
||||
printConsoleMessage("No such command");
|
||||
}
|
||||
|
||||
void ConsoleCommand::addUnit() {
|
||||
int unitId = 0, playerId = 0;
|
||||
Vector3 pos(0, 0, 0);
|
||||
float angle = 0;
|
||||
|
||||
for (int i = 0; i < arguments.size(); i++) {
|
||||
arguments[i].erase(0);
|
||||
for (int i2 = 0; i2 < arguments[i].size(); i2++) {
|
||||
if (i == 0)
|
||||
playerId += (arguments[i][i2] - 48) * pow(10, arguments[i].size() - (i2 + 1));
|
||||
else
|
||||
unitId += (arguments[i][i2] - 48) * pow(10, arguments[i].size() - (i2 + 1));
|
||||
switch (unitType[unitId]) {
|
||||
case UNIT_TYPE::VESSEL:
|
||||
u = new Vessel(players[playerId],pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::DESTROYER:
|
||||
u = new Destroyer(players[playerId], pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::CRUISER:
|
||||
u = new Cruiser(players[playerId],pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::SUBMARINE:
|
||||
u = new Submarine(players[playerId], pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::AIRCRAFT_CARRIER:
|
||||
{
|
||||
u = new AircraftCarrier(players[playerId],pos, unitId);
|
||||
break;
|
||||
}
|
||||
case UNIT_TYPE::MISSILE_JET:
|
||||
u = new MissileJet(players[playerId],pos, unitId, false);
|
||||
break;
|
||||
case UNIT_TYPE::DEMO_JET:
|
||||
u = new DemoJet(players[playerId],pos, unitId, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ((playerId == 0 || playerId == 1) && (unitId >= 0 && unitId <= numberOfUnits)) {
|
||||
Unit *u = nullptr;
|
||||
players[playerId]->addUnit(u);
|
||||
} else if (playerId != 0 && playerId != 1)
|
||||
printConsoleMessage("Invalid player id");
|
||||
else if (unitId < 0 || unitId > numberOfUnits)
|
||||
printConsoleMessage("Invalid unit id");
|
||||
}
|
||||
|
||||
switch (unitType[unitId]) {
|
||||
case UNIT_TYPE::VESSEL:
|
||||
u = new Vessel(players[playerId],pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::DESTROYER:
|
||||
u = new Destroyer(players[playerId], pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::CRUISER:
|
||||
u = new Cruiser(players[playerId],pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::SUBMARINE:
|
||||
u = new Submarine(players[playerId], pos, unitId);
|
||||
break;
|
||||
case UNIT_TYPE::AIRCRAFT_CARRIER:
|
||||
{
|
||||
u = new AircraftCarrier(players[playerId],pos, unitId);
|
||||
break;
|
||||
}
|
||||
case UNIT_TYPE::MISSILE_JET:
|
||||
u = new MissileJet(players[playerId],pos, unitId, false);
|
||||
break;
|
||||
case UNIT_TYPE::DEMO_JET:
|
||||
u = new DemoJet(players[playerId],pos, unitId, false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
void ConsoleCommand::debugUnits() {
|
||||
if (arguments.size() == 0)
|
||||
for (Player *pl : players){
|
||||
vector<Unit*> &units=pl->getUnits();
|
||||
|
||||
for (Unit *u : units){
|
||||
u->toggleDebugging(true);
|
||||
vector<Projectile*> projectiles=u->getProjectiles();
|
||||
|
||||
for(Projectile *pr : projectiles)
|
||||
pr->debug();
|
||||
}
|
||||
}
|
||||
else
|
||||
printConsoleMessage("Too many arguments");
|
||||
}
|
||||
|
||||
players[playerId]->addUnit(u);
|
||||
} else if (playerId != 0 && playerId != 1)
|
||||
printConsoleMessage("Invalid player id");
|
||||
else if (unitId < 0 || unitId > numberOfUnits)
|
||||
printConsoleMessage("Invalid unit id");
|
||||
}
|
||||
void ConsoleCommand::printConsoleMessage(string message) {
|
||||
int messageId = 0;
|
||||
bool foundEmptySlot = false;
|
||||
|
||||
void ConsoleCommand::debugUnits() {
|
||||
if (arguments.size() == 0)
|
||||
for (Player *pl : players){
|
||||
vector<Unit*> &units=pl->getUnits();
|
||||
|
||||
for (Unit *u : units){
|
||||
u->toggleDebugging(true);
|
||||
vector<Projectile*> projectiles=u->getProjectiles();
|
||||
|
||||
for(Projectile *pr : projectiles)
|
||||
pr->debug();
|
||||
}
|
||||
}
|
||||
else
|
||||
printConsoleMessage("Too many arguments");
|
||||
}
|
||||
|
||||
void ConsoleCommand::printConsoleMessage(string message) {
|
||||
int messageId = 0;
|
||||
bool foundEmptySlot = false;
|
||||
|
||||
for (int i = 0; i < listbox->getContents().size() && !foundEmptySlot; i++)
|
||||
if (listbox->getContents()[i] == L"") {
|
||||
messageId = i;
|
||||
foundEmptySlot = true;
|
||||
}
|
||||
/*
|
||||
if (foundEmptySlot)
|
||||
listbox->changeLine(messageId, message);
|
||||
else
|
||||
listbox->addLine(message);
|
||||
*/
|
||||
}
|
||||
for (int i = 0; i < listbox->getContents().size() && !foundEmptySlot; i++)
|
||||
if (listbox->getContents()[i] == L"") {
|
||||
messageId = i;
|
||||
foundEmptySlot = true;
|
||||
}
|
||||
/*
|
||||
if (foundEmptySlot)
|
||||
listbox->changeLine(messageId, message);
|
||||
else
|
||||
listbox->addLine(message);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user