当前位置: 首页>>代码示例>>C++>>正文


C++ UnitBase::doAttackObject方法代码示例

本文整理汇总了C++中UnitBase::doAttackObject方法的典型用法代码示例。如果您正苦于以下问题:C++ UnitBase::doAttackObject方法的具体用法?C++ UnitBase::doAttackObject怎么用?C++ UnitBase::doAttackObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnitBase的用法示例。


在下文中一共展示了UnitBase::doAttackObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: executeCommand

void Command::executeCommand() const {
	switch(commandID) {

		case CMD_PLACE_STRUCTURE: {
			if(parameter.size() != 3) {
				throw std::invalid_argument("Command::executeCommand(): CMD_PLACE_STRUCTURE needs 3 Parameters!");
			}
			ConstructionYard* pConstYard = dynamic_cast<ConstructionYard*>(currentGame->getObjectManager().getObject(parameter[0]));
			if(pConstYard == NULL) {
				return;
			}
			pConstYard->doPlaceStructure((int) parameter[1], (int) parameter[2]);
		} break;


		case CMD_UNIT_MOVE2POS: {
			if(parameter.size() != 4) {
				throw std::invalid_argument("Command::executeCommand(): CMD_UNIT_MOVE2POS needs 4 Parameters!");
			}
			UnitBase* unit = dynamic_cast<UnitBase*>(currentGame->getObjectManager().getObject(parameter[0]));
			if(unit == NULL) {
                return;
			}
            unit->doMove2Pos((int) parameter[1], (int) parameter[2], (bool) parameter[3]);
		} break;

		case CMD_UNIT_MOVE2OBJECT: {
			if(parameter.size() != 2) {
				throw std::invalid_argument("Command::executeCommand(): CMD_UNIT_MOVE2OBJECT needs 2 Parameters!");
			}
			UnitBase* unit = dynamic_cast<UnitBase*>(currentGame->getObjectManager().getObject(parameter[0]));
			if(unit == NULL) {
                return;
			}
            unit->doMove2Object((int) parameter[1]);
		} break;

		case CMD_UNIT_ATTACKPOS: {
			if(parameter.size() != 4) {
				throw std::invalid_argument("Command::executeCommand(): CMD_UNIT_ATTACKPOS needs 4 Parameters!");
			}
			UnitBase* unit = dynamic_cast<UnitBase*>(currentGame->getObjectManager().getObject(parameter[0]));
			if(unit == NULL) {
                return;
			}
			unit->doAttackPos((int) parameter[1], (int) parameter[2], (bool) parameter[3]);
		} break;

		case CMD_UNIT_ATTACKOBJECT: {
			if(parameter.size() != 2) {
				throw std::invalid_argument("Command::executeCommand(): CMD_UNIT_ATTACKOBJECT needs 2 Parameters!");
			}
			UnitBase* pUnit = dynamic_cast<UnitBase*>(currentGame->getObjectManager().getObject(parameter[0]));
			if(pUnit == NULL) {
                return;
			}
			pUnit->doAttackObject((int) parameter[1], true);
		} break;

        case CMD_INFANTRY_CAPTURE: {
			if(parameter.size() != 2) {
				throw std::invalid_argument("Command::executeCommand(): CMD_INFANTRY_CAPTURE needs 2 Parameters!");
			}
			InfantryBase* pInfantry = dynamic_cast<InfantryBase*>(currentGame->getObjectManager().getObject(parameter[0]));
			if(pInfantry == NULL) {
                return;
			}
			pInfantry->doCaptureStructure((int) parameter[1]);
		} break;

		case CMD_UNIT_SETMODE: {
			if(parameter.size() != 2) {
				throw std::invalid_argument("Command::executeCommand(): CMD_UNIT_SETMODE needs 2 Parameter!");
			}
			UnitBase* pUnit = dynamic_cast<UnitBase*>(currentGame->getObjectManager().getObject(parameter[0]));
			if(pUnit == NULL) {
                return;
			}
			pUnit->doSetAttackMode((ATTACKMODE) parameter[1]);
		} break;

		case CMD_DEVASTATOR_STARTDEVASTATE: {
			if(parameter.size() != 1) {
				throw std::invalid_argument("Command::executeCommand(): CMD_DEVASTATOR_STARTDEVASTATE needs 1 Parameter!");
			}
			Devastator* pDevastator = dynamic_cast<Devastator*>(currentGame->getObjectManager().getObject(parameter[0]));
			if(pDevastator == NULL) {
                return;
			}
			pDevastator->doStartDevastate();
		} break;

		case CMD_MCV_DEPLOY: {
			if(parameter.size() != 1) {
				throw std::invalid_argument("Command::executeCommand(): CMD_MCV_DEPLOY needs 1 Parameter!");
			}
			MCV* pMCV = dynamic_cast<MCV*>(currentGame->getObjectManager().getObject(parameter[0]));
			if(pMCV == NULL) {
                return;
			}
//.........这里部分代码省略.........
开发者ID:binarycrusader,项目名称:dunelegacy,代码行数:101,代码来源:Command.cpp


注:本文中的UnitBase::doAttackObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。