Beispiel #1
0
void CUnitDefHandler::CleanBuildOptions()
{
	// remove invalid build options
	for (int i = 1; i <= numUnitDefs; i++) {
		UnitDef& ud = unitDefs[i];
		map<int, string>& bo = ud.buildOptions;
		map<int, string>::iterator it = bo.begin();
		while (it != bo.end()) {
			bool erase = false;

			const UnitDef* bd = GetUnitByName(it->second);
			if (bd == NULL) {
				logOutput.Print("WARNING: removed the \"" + it->second +
				                "\" entry from the \"" + ud.name + "\" build menu");
				erase = true;
			}
			/*
			else if (bd->maxThisUnit <= 0) {
				// don't remove, just grey out the icon
				erase = true; // silent removal
			}
			*/

			if (erase) {
				map<int, string>::iterator tmp = it;
				it++;
				bo.erase(tmp);
			} else {
				it++;
			}
		}
	}
}
Beispiel #2
0
//Lua扩展函数,取得对象位置x,y,z = GetUnitPosition("player")
int lua_GetUnitPosition( void* l ){
	float v[6];

	if( Lua_isstring(l,1) ){
		size_t len;
		const char * name = Lua_tolstring(l,1,&len);
		void* punit = GetUnitByName( name );
		if( punit ){
			GetUnitPosition( punit,v );
			Lua_pushnumber(l,v[0]);
			Lua_pushnumber(l,v[1]);
			Lua_pushnumber(l,v[2]);
			return 3;
		}else if(g_pFocusID&&strcmp(name,"focus")==0){
			punit = GetUnit(*g_pFocusID,1);
			if( punit ){
				GetUnitPosition( punit,v );
				Lua_pushnumber(l,v[0]);
				Lua_pushnumber(l,v[1]);
				Lua_pushnumber(l,v[2]);
				return 3;
			}
		}
	}
	Lua_pushnil(l);
	return 1;
}
Beispiel #3
0
//计算x,y,z和你的角度a=GetAngle(x,y,z)
int lua_GetAngle( void* l ){
	float uv[3],pv[3],av[3],sv[3];

	bool isok = true;
	if( Lua_isnumber(l,1) ){
		uv[0] = (float)Lua_tonumber(l,1);
	}else isok = false;
	if( Lua_isnumber(l,2) ){
		uv[1] = (float)Lua_tonumber(l,2);
	}else isok = false;
	if( Lua_isnumber(l,3) ){
		uv[2] = (float)Lua_tonumber(l,3);
	}else isok = false;

	if( isok ){
		size_t len;
		const char * name = Lua_tolstring(l,1,&len);
		void* pplayer = GetUnitByName(sPlayer);
		if( pplayer ){
			GetUnitPosition( pplayer,pv );
			GetUnitDirection( pplayer,av );
			vector_sub( sv,uv,pv );
			sv[2] = 0;
			double a = vector_angle(av,sv);

			a *= 180/M_PI;
			Lua_pushnumber( l,a );
			return 1;
		}
	}
	Lua_pushnil(l);
	return 1;
}
Beispiel #4
0
//计算x,y,z和你的距离d=GetDistance(x,y,z)
int lua_GetDistance( void* l ){
	float uv[3],pv[3],v[3];
	bool isok = true;
	if( Lua_isnumber(l,1) ){
		uv[0] = (float)Lua_tonumber(l,1);
	}else isok = false;
	if( Lua_isnumber(l,2) ){
		uv[1] = (float)Lua_tonumber(l,2);
	}else isok = false;
	if( Lua_isnumber(l,3) ){
		uv[2] = (float)Lua_tonumber(l,3);
	}else isok = false;

	if( isok ){
		size_t len;
		const char * name = Lua_tolstring(l,1,&len);
		void* pplayer = GetUnitByName(sPlayer);
		if( pplayer ){
			GetUnitPosition( pplayer,pv );
	//		pv[2] = 0;
	//		uv[2] = 0;
			vector_sub(v,pv,uv);

			Lua_pushnumber( l,vector_mod( v ) );
			return 1;
		}
	}
	Lua_pushnil(l);
	return 1;
}
Beispiel #5
0
//取得玩家的控制状态,依赖
//参考函数:AnyTest(00673490) 魔兽版本3.09
//参考位置:00673E88
//wow3.11 参考位置005B1E8C
unsigned long GetMovementState(){
	void* s = GetUnitByName(sPlayer);
	if( s ){
		char* ebx = *((char**)s+0x0d8/4);
		if( ebx ){
			unsigned long state = *((unsigned long*)(ebx+0x44));
			return state;
		}
	}
	return 0;
}
Beispiel #6
0
//Lua扩展函数,取得对象的面向x,y,z = GetUnitDirection("player")
int lua_GetUnitDirection( void* l ){
	float v[6];

	if( Lua_isstring(l,1) ){
		size_t len;
		const char * name = Lua_tolstring(l,1,&len);
		void* punit = GetUnitByName( name );
		if( punit ){
			GetUnitDirection( punit,v );
			Lua_pushnumber(l,v[0]);
			Lua_pushnumber(l,v[1]);
			Lua_pushnumber(l,v[2]);
			return 3;
		}
	}
	Lua_pushnil(l);
	return 1;
}