Exemplo n.º 1
0
void GameEvents::on_event_game_over(const CL_NetGameEvent &e)
{
	CL_String title = e.get_argument(0);
	CL_String message = e.get_argument(1);

	client->get_game_view()->game_over(title, message);
}
Exemplo n.º 2
0
void Cliente::on_evento_juego_otorga_powerup(const CL_NetGameEvent &e)
{
	int id_tanque = e.get_argument(0);
	int id_power = e.get_argument(1);

	mundo->otorgaPowerup(id_tanque, id_power);
}
void ServerGameEvents::on_event_attack_area(const CL_NetGameEvent &e, ServerGame *game, ServerGamePlayer *game_player)
{
	int map_area_from_id = e.get_argument(0);
	int map_area_to_id = e.get_argument(1);

	game->attack_area(game_player, map_area_from_id, map_area_to_id);
}
Exemplo n.º 4
0
// "Game-LoadMap" event was received
void Client::on_event_game_loadmap(const CL_NetGameEvent &e) 
{
	CL_String map_name = e.get_argument(0);
	int max_players = e.get_argument(1);
	CustomType position = e.get_argument(2);

	cl_log_event("events", "Loading map: %1 with %2 players, Position %3,%4,%5", map_name, max_players, position.get_x(), position.get_y(), position.get_z());
}
Exemplo n.º 5
0
void Cliente::on_evento_juego_actualizar_SubID(const CL_NetGameEvent &e)
{
	cl_log_event("eventos", "Actualiza SubID");
	int contSubID = e.get_argument(0);
	int tanqueid = e.get_argument(1);
	mundo->setSubID(contSubID);
	mundo->getTanqueID(tanqueid)->disparar();
}
Exemplo n.º 6
0
//Evento Login: Recibido
void Servidor::on_evento_login(const CL_NetGameEvent &e, UsuarioServidor *usuario)
{
	cl_log_event("eventos", "Cliente solicita login");

	int numusuarios = Usuarios.size();
/*
	if(numusuarios < (numjugadores -1) )
	{
		CL_String idlogin = e.get_argument(0);
		CL_String password = e.get_argument(1);
		CL_String nombre_usuario = e.get_argument(2);

		CL_SqliteConnection bd_conexion("bdjuego.sql3");
		CL_DBCommand consulta_login = bd_conexion.create_command("SELECT password FROM Usuarios WHERE id=?1");
		consulta_login.set_input_parameter_string(1,idlogin);
		CL_DBReader reader = bd_conexion.execute_reader(consulta_login);
		CL_String pas_bd;

		if(reader.retrieve_row())
		{
			pas_bd = reader.get_column_string(0);

			if(password.compare(pas_bd)==0) //Password Correcto
			{
				usuario->nombre_usuario= nombre_usuario;
				usuario->id = siguiente_usuario_id++;
				Usuarios.push_back(usuario);
				usuario->enviar_evento(CL_NetGameEvent("Login-Completado"));
			}
			else //Clave Incorrecta
			{
				usuario->enviar_evento(CL_NetGameEvent("Login-Fallado", "Clave Incorrecta"));
			}
		}
		else
		{
			usuario->enviar_evento(CL_NetGameEvent("Login-Fallado", "ID No encontrado")); //ID Incorrecto
		}


		reader.close(); 
	}
	else
	{
		usuario->enviar_evento(CL_NetGameEvent("Login-ServidorLleno"));
	}
	*/
	
		CL_String idlogin = e.get_argument(0);
		CL_String password = e.get_argument(1);
		CL_String nombre_usuario = e.get_argument(2);
		usuario->nombre_usuario= nombre_usuario;
		usuario->id = siguiente_usuario_id++;
		Usuarios.push_back(usuario);
		usuario->enviar_evento(CL_NetGameEvent("Login-Completado"));

}
Exemplo n.º 7
0
void Cliente::on_evento_juego_agrega_powerup(const CL_NetGameEvent &e)
{
	int i = e.get_argument(0);
	float x = e.get_argument(1);
	float y = e.get_argument(2);

	PowerupTipo tipos[4] = {MEDIKIT,ESCUDO,RAPIDEZ_TANQUE,DISPARO_360};

	mundo->agregarPowerup(tipos[i], CL_Vec2f(x, y));
}
Exemplo n.º 8
0
void Cliente::on_evento_juego_matar_tanque(const CL_NetGameEvent &e)
{
	cl_log_event("eventos", "Matar Tanque");

	int idtanque = e.get_argument(0);
	int tiempofin = e.get_argument(1);


	mundo->getTanqueID(idtanque)->Matar(CL_System::get_time(), tiempofin);
}
Exemplo n.º 9
0
void LobbyEvents::on_event_player_logged_in(const CL_NetGameEvent &e)
{
	int player_id = e.get_argument(0);
	CL_String player_name = e.get_argument(1);

	LobbyPlayer *player = player_collection->create_player(player_id, player_name);

	if (client->get_lobby_view())
		client->get_lobby_view()->player_logged_in(player);
}
Exemplo n.º 10
0
void LobbyEvents::on_event_player_message(const CL_NetGameEvent &e)
{
	int player_id = e.get_argument(0);
	CL_String message = e.get_argument(1);

	LobbyPlayer *player = player_collection->get_player(player_id);

	if(client->get_lobby_view() && player)
		client->get_lobby_view()->add_chat_message(player, message);
}
Exemplo n.º 11
0
void RaceStart::parseEvent(const CL_NetGameEvent &p_event)
{
	assert(p_event.get_name() == EVENT_RACE_START);

	int i = 0;

	m_carPosition.x = static_cast<float> (p_event.get_argument(i++));
	m_carPosition.y = static_cast<float> (p_event.get_argument(i++));

	m_carRotation.set_radians(static_cast<float> (p_event.get_argument(i++)));
}
Exemplo n.º 12
0
void GameEvents::on_event_game_player_message(const CL_NetGameEvent &e)
{
	int player_id = e.get_argument(0);
	CL_String message = e.get_argument(1);

	GamePlayer *player = client->get_game_model()->get_players()->get_player(player_id);
	if(player)
	{
		client->get_game_view()->add_player_message(player, message);
	}
}
Exemplo n.º 13
0
void GameEvents::on_event_set_maparea_army_strength(const CL_NetGameEvent &e)
{
	int map_area_id = e.get_argument(0);
	int army_strength = e.get_argument(1);

	MapArea *map_area = client->get_game_model()->get_map()->get_area_by_id(map_area_id);

	if(map_area != 0 && army_strength >= 1 && army_strength <= 8)
		map_area->army_strength = army_strength;
	else
		cl_log_event("error", "Invalid event: %1", e.to_string());
}
Exemplo n.º 14
0
void GameEvents::on_event_player_joined_game(const CL_NetGameEvent &e)
{
	int player_id = e.get_argument(0);
	CL_String player_name = e.get_argument(1);
	int visual_id = e.get_argument(2);

	GamePlayer *player = client->get_game_model()->get_players()->create_player(player_name, player_id, visual_id);
	if(player)
		client->get_game_view()->player_joined_game(player);
	else
		cl_log_event("error", "Invalid event: %1", e.to_string());
}
Exemplo n.º 15
0
void CarState::parseEvent(const CL_NetGameEvent &p_event)
{
	assert(p_event.get_name() == EVENT_CAR_STATE);

	m_name = p_event.get_argument(0);
	m_serialData = CL_NetGameEvent("");

	const int argCount = static_cast<signed>(p_event.get_argument_count());

	for (int i = 1; i < argCount; ++i) {
		m_serialData.add_argument(p_event.get_argument(i));
	}
}
Exemplo n.º 16
0
void Cliente::on_evento_juego_agrega_tanque(const CL_NetGameEvent &e) 
{
	cl_log_event("eventos", "Agrega Tanque");
	float x = e.get_argument(0);  //Obtiene posicion 
	float y = e.get_argument(1);
	int mi_id = e.get_argument(2);
	CL_String nombre = e.get_argument(3);
	int contSubID = e.get_argument(4);
	CL_Vec2f postanque = CL_Vec2f(x,y);
	mundo->quitarTanque(0); //Se quita y se agrega el jugador
	mundo->agregarTanque(mi_id,DEFAULT,nombre,true,false,postanque,0.0f,0.0f);
	mundo->setSubID(contSubID);
}
Exemplo n.º 17
0
//Evento Juego: Solicitud de comenzar
void Servidor::on_evento_juego_solicitudcomenzar(const CL_NetGameEvent &e, UsuarioServidor *usuario)
{
	CL_String nombre = e.get_argument(0);
	cl_log_event("eventos", "Cliente solicito comenzar juego");

	CL_String mensaje= "Se conecto " + usuario->nombre_usuario;

	mundo->AgregarCadenaChat(mensaje);

	int id_nuevo = mundo->tanques.size();

	enviaratodosEx(CL_NetGameEvent("Juego-Msj",mensaje),id_nuevo); //Enviar a todos que se conecto alquien

	CL_Vec2f pospawn = mundo->agregarTanque(id_nuevo,DEFAULT,nombre,false,false); //agrega el usuario
																									//Devuelve el id_actual
	usuario->enviar_evento(CL_NetGameEvent("Juego-Comenzar",pospawn.x,pospawn.y,id_nuevo, nombre, mundo->getActualSubID())); //envia el SpawnPoint al usuario
	//enviaratodosEx(CL_NetGameEvent("Juego-AgregarTanque",pospawn.x,pospawn.y,id_nuevo, nombre), id_nuevo); //envia el SpawnPoint al usuario
	
	//Envia los tanques creados
	std::list<Tanque *>::iterator it;

	for(it=mundo->tanques.begin(); it != mundo->tanques.end(); ++it)
	{
		CL_NetGameEvent evento("Juego-JugadorConectado",(*it)->getID(),(*it)->getPos().x,(*it)->getPos().y								 //Envia al usuario todos los tanques 
											    ,(*it)->getanguloCuerpo(),(*it)->getAnguloTorreta());
		evento.add_argument((*it)->getNombre());
		//usuario->enviar_evento(evento); //actuales
		enviaratodos(evento);
	}

	mundo->quitarTodosPowerup();

	//enviaratodosEx(CL_NetGameEvent("Juego-JugadorConectado",usuario->id,pospawn.x,pospawn.y,(*final)->getanguloCuerpo() //Envia a todos el nuevo tanque
	//													   ,(*final)->getAnguloTorreta()),usuario->id);
}
Exemplo n.º 18
0
void Cliente::on_evento_juego_actualizar_tiempo(const CL_NetGameEvent &e)
{
	int min = e.get_argument(0);
	int seg = e.get_argument(1);

	mundo->setReloj(min, seg, false);
}
Exemplo n.º 19
0
void GameEvents::on_event_set_maparea_ownership(const CL_NetGameEvent &e)
{
	int map_area_id = e.get_argument(0);
	int player_id = e.get_argument(1);

	MapArea *map_area = client->get_game_model()->get_map()->get_area_by_id(map_area_id);
	GamePlayer *player = client->get_game_model()->get_players()->get_player(player_id);

	if(map_area != 0 && player != 0)
	{
		map_area->player_id = player->id;
		client->get_game_view()->update_map();
	}
	else
		cl_log_event("error", "Invalid event: %1", e.to_string());
}
Exemplo n.º 20
0
void Cliente::on_evento_juego_mensajechat(const CL_NetGameEvent &e)
{
	cl_log_event("eventos", "Mensaje recibido");
	CL_String mensaje = e.get_argument(0);

	mundo->AgregarCadenaChat(mensaje);	 //Agrega mensaje recibido
}
Exemplo n.º 21
0
void LobbyEvents::on_event_error_message(const CL_NetGameEvent &e)
{
	CL_String message = e.get_argument(0);

	if(client->get_lobby_view())
		client->get_lobby_view()->add_info_message(message);
}
Exemplo n.º 22
0
void LobbyEvents::on_event_player_left_game(const CL_NetGameEvent &e)
{
	int player_id = e.get_argument(0);
	int game_id = e.get_argument(1);

	LobbyPlayer *player = player_collection->get_player(player_id);
	LobbyGame *game = game_collection->get_game(game_id);

	if(game && player)
	{
		game->remove_player(player);

		if (client->get_lobby_view())
			client->get_lobby_view()->player_left_game(game, player);
	}
}
Exemplo n.º 23
0
void LoginEvents::on_event_login_failed(const CL_NetGameEvent &e)
{
	CL_String fail_reason = e.get_argument(0);

	// TODO: Handle failed login more gracefully
	throw CL_Exception("Login failed: " + fail_reason);
}
Exemplo n.º 24
0
void LobbyEvents::on_event_game_created(const CL_NetGameEvent &e)
{
	int game_id = e.get_argument(0);
	CL_String game_name = e.get_argument(1);
	CL_String map_name = e.get_argument(2);
	int max_players = e.get_argument(3);

	LobbyGame *game = game_collection->create_game(game_id, game_name, map_name, max_players, LobbyGame::lobby);
	if(game)
	{
		if (client->get_lobby_view())
		{
			client->get_lobby_view()->add_game(game);
			client->get_lobby_view()->create_game(game);
		}
	}
}
Exemplo n.º 25
0
void Cliente::on_evento_juego_jugador_conectado(const CL_NetGameEvent &e)
{	
	//Datos del tanque conectado
	int idtanque = e.get_argument(0);

	if(mundo->getTanqueID(idtanque) == NULL)
	{
		float x = e.get_argument(1);
		float y = e.get_argument(2);
		float angulo = e.get_argument(3);
		float angulotorreta = e.get_argument(4);
		CL_String nombre = e.get_argument(5);

		CL_Vec2f postanque = CL_Vec2f(x,y);
		mundo->agregarTanque(idtanque,DEFAULT,nombre,false,false,postanque,angulo,angulotorreta); //Agrega el tanque nuevo	
	}
}
Exemplo n.º 26
0
void Cliente::on_evento_juego_saludyscore(const CL_NetGameEvent &e)
{
	int idtanque = e.get_argument(0);
	int vida = e.get_argument(1);
	int armadura = e.get_argument(2);
	int score = e.get_argument(3);

	Tanque *tank = mundo->getTanqueID(idtanque);

	if(tank != NULL)
	{
		tank->setVida(vida);
		tank->setArmadura(armadura);
		tank->setScore(score);
	}
	
}
Exemplo n.º 27
0
void GameEvents::on_event_player_turn_started(const CL_NetGameEvent &e)
{
	int player_id = e.get_argument(0);

	if(player_id == client->get_player_id())
		client->get_game_view()->set_active_turn();
	else
		client->get_game_view()->set_waiting_turn();
}
Exemplo n.º 28
0
void Servidor::on_evento_juego_mensajechat(const CL_NetGameEvent &e, UsuarioServidor *usuario)
{
	cl_log_event("eventos", "Mensaje recibido");
	CL_String mensaje = e.get_argument(0);

	enviaratodosEx(CL_NetGameEvent("Juego-Msj",mensaje),usuario->id); //Envia a todos -1 el mensaje recibido

	mundo->AgregarCadenaChat(mensaje);
}
Exemplo n.º 29
0
void Servidor::on_evento_juego_actualizar_teclado(const CL_NetGameEvent &e, UsuarioServidor *usuario)
{
		cl_log_event("eventos", "Actualizar Teclado");

		int tipo = e.get_argument(0);
		int tecla = e.get_argument(1);

		if(tipo==0) // Tecla Down
		{
			mundo->teclatanquedown(usuario->id,tecla);
		}
		else if(tipo==1) //Tecla Up
		{
			mundo->teclatanqueup(usuario->id,tecla);
		}

		enviaratodosEx(CL_NetGameEvent("Juego-ActualizarTeclado",usuario->id,tipo,tecla),usuario->id); //Envia a todos -1 el actualizar teclado
}
Exemplo n.º 30
0
void LobbyEvents::on_event_game_started(const CL_NetGameEvent &e)
{
	int game_id = e.get_argument(0);
	LobbyGame *game = game_collection->get_game(game_id);
	if(game)
	{
		game->set_state(LobbyGame::playing);
		client->get_lobby_view()->update_game(game);
	}
}