2010-03-18 22:26:40 +01:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2010-04-27 05:36:36 +02:00
|
|
|
// Copyright (C) 2001-2008 Martio Figueroa
|
2010-03-18 22:26:40 +01:00
|
|
|
//
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#include "network_types.h"
|
2010-03-22 05:47:16 +01:00
|
|
|
#include "util.h"
|
|
|
|
#include "unit.h"
|
|
|
|
#include "world.h"
|
|
|
|
#include "unit_type.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include "gui.h"
|
2010-03-18 22:26:40 +01:00
|
|
|
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
2010-03-22 05:47:16 +01:00
|
|
|
using namespace Shared::Util;
|
|
|
|
|
2010-03-18 22:26:40 +01:00
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class NetworkCommand
|
|
|
|
// =====================================================
|
|
|
|
|
2010-04-18 09:35:48 +02:00
|
|
|
NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId, int commandTypeId, const Vec2i &pos, int unitTypeId, int targetId, int facing, bool wantQueue)
|
2010-03-25 13:15:10 +01:00
|
|
|
: networkCommandType(networkCommandType)
|
|
|
|
, unitId(unitId)
|
|
|
|
, commandTypeId(commandTypeId)
|
|
|
|
, positionX(pos.x)
|
|
|
|
, positionY(pos.y)
|
2010-04-18 09:35:48 +02:00
|
|
|
, unitTypeId(unitTypeId)
|
|
|
|
, wantQueue(wantQueue) {
|
2010-03-25 13:15:10 +01:00
|
|
|
assert(targetId == -1 || facing == -1);
|
|
|
|
this->targetId = targetId >= 0 ? targetId : facing;
|
2010-03-22 05:47:16 +01:00
|
|
|
|
|
|
|
if(this->networkCommandType == nctGiveCommand) {
|
|
|
|
const Unit *unit= world->findUnitById(this->unitId);
|
|
|
|
|
|
|
|
//validate unit
|
|
|
|
if(unit != NULL) {
|
|
|
|
const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), this->unitTypeId);
|
|
|
|
const CommandType *ct = unit->getType()->findCommandTypeById(this->commandTypeId);
|
|
|
|
if(ct != NULL && ct->getClass() == ccBuild) {
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
|
2010-04-27 05:36:36 +02:00
|
|
|
CardinalDir::assertDirValid(facing);
|
|
|
|
assert(targetId == -1);
|
2010-03-22 05:47:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkCommand::preprocessNetworkCommand(World *world) {
|
|
|
|
if(networkCommandType == nctGiveCommand) {
|
|
|
|
const Unit *unit= world->findUnitById(unitId);
|
|
|
|
|
|
|
|
//validate unit
|
|
|
|
if(unit != NULL) {
|
|
|
|
const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId);
|
|
|
|
const CommandType *ct = unit->getType()->findCommandTypeById(commandTypeId);
|
|
|
|
if(ct != NULL && ct->getClass() == ccBuild && targetId >= 0) {
|
2010-04-27 05:36:36 +02:00
|
|
|
CardinalDir::assertDirValid(targetId);
|
2010-03-22 05:47:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] (unit == NULL) %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string NetworkCommand::toString() const {
|
|
|
|
char szBuf[1024]="";
|
2010-04-18 09:35:48 +02:00
|
|
|
sprintf(szBuf,"networkCommandType = %d\nunitId = %d\ncommandTypeId = %d\npositionX = %d\nthis->positionY = %d\nunitTypeId = %d\ntargetId = %d\nwantQueue= %d",
|
|
|
|
networkCommandType,unitId,commandTypeId,positionX,this->positionY,unitTypeId,targetId,wantQueue);
|
2010-03-22 05:47:16 +01:00
|
|
|
|
|
|
|
string result = szBuf;
|
|
|
|
return result;
|
2010-03-18 22:26:40 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 05:47:16 +01:00
|
|
|
/*
|
2010-03-18 22:26:40 +01:00
|
|
|
NetworkCommand::NetworkCommand(int networkCommandType, NetworkCommandSubType ncstType, int unitId, int value1, int value2) {
|
|
|
|
this->networkCommandType= networkCommandType;
|
|
|
|
this->unitId= unitId;
|
|
|
|
this->commandTypeId= ncstType;
|
|
|
|
this->positionX= -1;
|
|
|
|
this->positionY= -1;
|
|
|
|
this->unitTypeId= value1;
|
|
|
|
this->targetId= value2;
|
|
|
|
}
|
2010-03-22 05:47:16 +01:00
|
|
|
*/
|
2010-03-18 22:26:40 +01:00
|
|
|
|
|
|
|
}}//end namespace
|