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


C++ CUnit::GetMapPixelPosTopLeft方法代码示例

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


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

示例1: CclCreateMissile

/**
**  Create a missile on the map
**
**  @param l  Lua state.
**
*/
static int CclCreateMissile(lua_State *l)
{
	LuaCheckArgs(l, 6);

	const std::string name = LuaToString(l, 1);
	const MissileType *mtype = MissileTypeByIdent(name);
	if (!mtype) {
		LuaError(l, "Bad missile");
	}
	PixelPos startpos, endpos;
	if (!lua_istable(l, 2) || lua_rawlen(l, 2) != 2) {
		LuaError(l, "incorrect argument !!");
	}
	lua_rawgeti(l, 2, 1);
	startpos.x = LuaToNumber(l, -1);
	lua_pop(l, 1);
	lua_rawgeti(l, 2, 2);
	startpos.y = LuaToNumber(l, -1);
	lua_pop(l, 1);
	if (!lua_istable(l, 3) || lua_rawlen(l, 3) != 2) {
		LuaError(l, "incorrect argument !!");
	}
	lua_rawgeti(l, 3, 1);
	endpos.x = LuaToNumber(l, -1);
	lua_pop(l, 1);
	lua_rawgeti(l, 3, 2);
	endpos.y = LuaToNumber(l, -1);
	lua_pop(l, 1);

	const int sourceUnitId = LuaToNumber(l, 4);
	const int destUnitId = LuaToNumber(l, 5);
	const bool dealDamage = LuaToBoolean(l, 6);
	CUnit *sourceUnit = sourceUnitId != -1 ? &UnitManager.GetSlotUnit(sourceUnitId) : NULL;
	CUnit *destUnit = destUnitId != -1 ? &UnitManager.GetSlotUnit(destUnitId) : NULL;

	if (sourceUnit != NULL) {
		startpos += sourceUnit->GetMapPixelPosTopLeft();
	}
	if (destUnit != NULL) {
		endpos += destUnit->GetMapPixelPosTopLeft();
	}

	Missile *missile = MakeMissile(*mtype, startpos, endpos);
	if (!missile) {
		return 0;
	}
	if (dealDamage) {
		missile->SourceUnit = sourceUnit;
	}
	missile->TargetUnit = destUnit;
	return 0;
}
开发者ID:ajaykon,项目名称:Stratagus,代码行数:58,代码来源:script_missile.cpp

示例2: CclCreateMissile

/**
**  Create a missile on the map
**
**  @param l  Lua state.
**
*/
static int CclCreateMissile(lua_State *l)
{
	const int arg = lua_gettop(l);
	if (arg < 6 || arg > 7) {
		LuaError(l, "incorrect argument");
	}

	const std::string name = LuaToString(l, 1);
	const MissileType *mtype = MissileTypeByIdent(name);
	if (!mtype) {
		LuaError(l, "Bad missile");
	}
	PixelPos startpos, endpos;
	CclGetPos(l, &startpos.x, &startpos.y, 2);
	CclGetPos(l, &endpos.x, &endpos.y, 3);

	const int sourceUnitId = LuaToNumber(l, 4);
	const int destUnitId = LuaToNumber(l, 5);
	const bool dealDamage = LuaToBoolean(l, 6);
	const bool mapRelative = arg == 7 ? LuaToBoolean(l, 7) : false;
	CUnit *sourceUnit = sourceUnitId != -1 ? &UnitManager.GetSlotUnit(sourceUnitId) : nullptr;
	CUnit *destUnit = destUnitId != -1 ? &UnitManager.GetSlotUnit(destUnitId) : nullptr;

	if (mapRelative == false) {
		if (sourceUnit != nullptr) {
			startpos += sourceUnit->GetMapPixelPosTopLeft();
		}
		if (destUnit != nullptr) {
			endpos += destUnit->GetMapPixelPosTopLeft();
		}
	}

	//Wyrmgus start
//	Missile *missile = MakeMissile(*mtype, startpos, endpos);
	Missile *missile = MakeMissile(*mtype, startpos, endpos, 0);
	//Wyrmgus end
	if (!missile) {
		return 0;
	}
	if (dealDamage) {
		missile->SourceUnit = sourceUnit;
	}
	missile->TargetUnit = destUnit;
	return 0;
}
开发者ID:Andrettin,项目名称:Wyrmgus,代码行数:51,代码来源:script_missile.cpp


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