示例#1
0
void console_execute_line(const char *str)
{
	console_execute_line_stroked(1, str);
}
void console_execute_line(const char *str, int cid)
{
	console_execute_line_stroked(1, str, cid);
}
示例#3
0
int CONTROLS::snapinput(int *data)
{
	static NETOBJ_PLAYER_INPUT last_data = {0};
	static int64 last_send_time = 0;
	bool send = false;
	
	// update player state
	if(gameclient.chat->is_active())
		input_data.player_state = PLAYERSTATE_CHATTING;
	else if(gameclient.menus->is_active())
		input_data.player_state = PLAYERSTATE_IN_MENU;
	else
		input_data.player_state = PLAYERSTATE_PLAYING;
	
	if(last_data.player_state != input_data.player_state)
		send = true;
		
	last_data.player_state = input_data.player_state;
	
	// we freeze the input if chat or menu is activated
	if(input_data.player_state != PLAYERSTATE_PLAYING)
	{
		last_data.direction = 0;
		last_data.hook = 0;
		last_data.jump = 0;
		input_data = last_data;
		
		input_direction_left = 0;
		input_direction_right = 0;
			
		mem_copy(data, &input_data, sizeof(input_data));

		// send once a second just to be sure
		if(time_get() > last_send_time + time_freq())
			send = true;
	}
	else
	{
		
		input_data.target_x = (int)mouse_pos.x;
		input_data.target_y = (int)mouse_pos.y;
		if(!input_data.target_x && !input_data.target_y)
			input_data.target_y = 1;
			
		// set direction
		input_data.direction = 0;
		if(input_direction_left && !input_direction_right)
			input_data.direction = -1;
		if(!input_direction_left && input_direction_right)
			input_data.direction = 1;

		// stress testing
		if(config.dbg_stress)
		{
			float t = client_localtime();
			mem_zero(&input_data, sizeof(input_data));

			input_data.direction = ((int)t/2)&1;
			input_data.jump = ((int)t);
			input_data.fire = ((int)(t*10));
			input_data.hook = ((int)(t*2))&1;
			input_data.wanted_weapon = ((int)t)%NUM_WEAPONS;
			input_data.target_x = (int)(sinf(t*3)*100.0f);
			input_data.target_y = (int)(cosf(t*3)*100.0f);
		}
		
		/////////////////////////////////// THIS IS MY IA BITCH DON'T TOUCH
		
		static AI *ai = NULL;
		if(!ai) {
			dbg_msg("ia", "Initializing AI");
			ooc_ai_load();
			ai = getAI();
		}
		
		struct GameInfo info;
		info.time = client_localtime();
		
		info.localCid = gameclient.snap.local_cid;
        info.numPlayers = gameclient.snap.num_players;
        info.playerInfos = gameclient.snap.player_infos;
		
		info.pos.x = gameclient.local_character_pos.x;
		info.pos.y = gameclient.local_character_pos.y;
		
		info.mouse.x = mouse_pos.x;
		info.mouse.y = mouse_pos.y;
		
		info.target.x = input_data.target_x;
		info.target.y = input_data.target_y;
		
		info.numChars = gameclient.numChars;
		info.chars = gameclient.chars;
		
		struct Answer answer = AI__AI_step(ai, info);
		uint32_t action = answer.action;
		//dbg_msg("ia", "got action = %x", action);
		
		input_data.jump = (action & Actions_JUMP);
			
		if(action & Actions_LEFT)
			input_data.direction = -1;
			
		if(action & Actions_RIGHT)
			input_data.direction = 1;
			
		if(action & Actions_FIRE)
			input_data.fire++;
			
		if(answer.target) {
			input_data.target_x = answer.target->x;
			input_data.target_y = answer.target->y;
		}
		
		if(answer.mouse) {
			mouse_pos.x = answer.mouse->x;
			mouse_pos.y = answer.mouse->y;
		}
        
        if(answer.nextWeapon) {
            console_execute_line_stroked(1, "+nextweapon");
        }
        if(answer.prevWeapon) {
            console_execute_line_stroked(1, "+prevweapon");
        }
        if(answer.wantedWeapon != 0) {
            switch (answer.wantedWeapon) {
                case 1:
                    console_execute_line_stroked(1, "+weapon1");
                    break;
                case 2:
                    console_execute_line_stroked(1, "+weapon2");
                    break;
                case 3:
                    console_execute_line_stroked(1, "+weapon3");
                    break;
                case 4:
                    console_execute_line_stroked(1, "+weapon4");
                    break;
                case 5:
                    console_execute_line_stroked(1, "+weapon5");
                    break;
            }
        }
			
		input_data.hook = (action & Actions_HOOK);
		
		/////////////////////////////////// THIS IS MY IA BITCH DON'T TOUCH
		
		//================ TEH HACK BEGINS HERE !!! ==========================
		
		/*
		static double cdown = 100;
		static bool jjump = true;
		jjump = !jjump;
		cdown++;
		
		if(rand() % 50 == 10){
			mouse_pos.x = cos(rand() % 100) * 100 + 50;
			mouse_pos.y = sin(rand() % 100) * 100 + 50;
		}
		
		if(rand() % 30 == 10){
			input_data.jump = true;
		}else{
			input_data.jump = false;
		}
		
		if(rand() % 40 == 10){
			input_data.fire = 1;
		}
		if(rand() % 40 == 10){
			input_data.fire = 0;
		}
		
		//dbg_msg("ai","diff: %f",target_pos.x - char_posx);
		if(target_pos.x - char_posx > 0){
			input_data.direction = 1;
		}
		else if(abs(target_pos.x - char_posx) < 15){
			input_data.direction = 0;
		}
		else{
			input_data.direction = -1;
		}
		*/
		
		//==================================================================

		// check if we need to send input
		if(input_data.direction != last_data.direction) send = true;
		else if(input_data.jump != last_data.jump) send = true;
		else if(input_data.fire != last_data.fire) send = true;
		else if(input_data.hook != last_data.hook) send = true;
		else if(input_data.player_state != last_data.player_state) send = true;
		else if(input_data.wanted_weapon != last_data.wanted_weapon) send = true;
		else if(input_data.next_weapon != last_data.next_weapon) send = true;
		else if(input_data.prev_weapon != last_data.prev_weapon) send = true;

		// send at at least 10hz
		if(time_get() > last_send_time + time_freq()/25)
			send = true;
	}
	
	// copy and return size	
	last_data = input_data;
	
	if(!send)
		return 0;
		
	last_send_time = time_get();
	mem_copy(data, &input_data, sizeof(input_data));
	return sizeof(input_data);	
}