src/include/action_handler.cpp File Reference

#include "action_handler.h"
#include "action.h"
#include "../character/body.h"
#include "../character/move.h"
#include "../game/game_mode.h"
#include "../game/game_loop.h"
#include "../game/game.h"
#include "../game/time.h"
#include "../include/constant.h"
#include "../network/network.h"
#include "../map/camera.h"
#include "../map/map.h"
#include "../map/maps_list.h"
#include "../map/wind.h"
#include "../menu/network_menu.h"
#include "../network/randomsync.h"
#include "../team/macro.h"
#include "../tool/debug.h"
#include "../tool/i18n.h"
#include "../tool/vector2.h"
#include "../weapon/construct.h"
#include "../weapon/launcher.h"
#include "../weapon/supertux.h"
#include "../weapon/weapon.h"
#include "../weapon/weapons_list.h"
#include "../weapon/explosion.h"

Include dependency graph for action_handler.cpp:

Go to the source code of this file.

Defines

#define DELTA_CROSSHAIR   0.035

Functions

void SyncCharacters ()
void Action_MoveRight (Action *a)
void Action_MoveLeft (Action *a)
void Action_Jump (Action *a)
void Action_HighJump (Action *a)
void Action_BackJump (Action *a)
void Action_Up (Action *a)
void Action_Down (Action *a)
void Action_ChangeWeapon (Action *a)
void Action_NextCharacter (Action *a)
void Action_ChangeCharacter (Action *a)
void Action_Shoot (Action *a)
void Action_Wind (Action *a)
ActionBuildActionSendCharacterPhysics (int team_no, int char_no)
void Action_SetCharacterPhysics (Action *a)
void Action_SetCharacterEnergy (Action *a)
void Action_SetSkin (Action *a)
void Action_SetCharacterDirection (Action *a)
void Action_SetMap (Action *a)
void Action_ChangeState (Action *a)
void Action_SetGameMode (Action *a)
void SendGameMode ()
void Action_NewTeam (Action *a)
void Action_UpdateTeam (Action *a)
void Action_DelTeam (Action *a)
void Action_ChatMessage (Action *a)
void Action_ChangeTeam (Action *a)
void Action_AskVersion (Action *a)
void Action_SendVersion (Action *a)
void Action_SendRandom (Action *a)
void Action_SupertuxState (Action *a)
void Action_SyncBegin (Action *a)
void Action_SyncEnd (Action *a)
void Action_Ping (Action *a)
void Action_Explosion (Action *a)
void Action_SetTarget (Action *a)
void Action_SetTimeout (Action *a)
void Action_ConstructionUp (Action *a)
void Action_ConstructionDown (Action *a)
void Action_WeaponStopUse (Action *a)
void Action_Nickname (Action *a)
void Action_Pause (Action *a)


Define Documentation

#define DELTA_CROSSHAIR   0.035

Definition at line 51 of file action_handler.cpp.


Function Documentation

void Action_AskVersion ( Action a  ) 

Definition at line 363 of file action_handler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_BackJump ( Action a  ) 

Definition at line 122 of file action_handler.cpp.

00123 {
00124   GameLoop::GetInstance()->character_already_chosen = true;
00125   ActiveCharacter().BackJump();
00126 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_ChangeCharacter ( Action a  ) 

Definition at line 150 of file action_handler.cpp.

00151 {
00152   a->RetrieveCharacter();
00153   camera.FollowObject(&ActiveCharacter(), true, true);
00154 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_ChangeState ( Action a  ) 

Definition at line 214 of file action_handler.cpp.

00215 {
00216   MSG_DEBUG("action.handler", "ChangeState");
00217 
00218   if(network.IsServer())
00219   {
00220     switch(network.state)
00221     {
00222     case Network::NETWORK_OPTION_SCREEN:
00223       // State is changed when server clicks on the launch game button
00224       network.client_inited++;
00225       break;
00226     case Network::NETWORK_INIT_GAME:
00227       // One more client is ready to play
00228       network.client_inited++;
00229       if(network.client_inited == network.connected_player)
00230         network.state = Network::NETWORK_READY_TO_PLAY;
00231       break;
00232     default:
00233       assert(false);
00234       break;
00235     }
00236   }
00237 
00238   if(network.IsClient())
00239   {
00240     switch(network.state)
00241     {
00242     case Network::NETWORK_OPTION_SCREEN:
00243       network.state = Network::NETWORK_INIT_GAME;
00244       break;
00245     case Network::NETWORK_INIT_GAME:
00246       network.state = Network::NETWORK_READY_TO_PLAY;
00247       break;
00248     case Network::NETWORK_READY_TO_PLAY:
00249       network.state = Network::NETWORK_PLAYING;
00250       break;
00251     default:
00252        assert(false);
00253     }
00254   }
00255 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_ChangeTeam ( Action a  ) 

Definition at line 356 of file action_handler.cpp.

00357 {
00358   teams_list.SetActive (a->PopString());
00359   ActiveTeam().PrepareTurn();
00360   assert (!ActiveCharacter().IsDead());
00361 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_ChangeWeapon ( Action a  ) 

Definition at line 138 of file action_handler.cpp.

00139 {
00140   ActiveTeam().SetWeapon(static_cast<Weapon::Weapon_type>(a->PopInt()));
00141 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_ChatMessage ( Action a  ) 

Definition at line 345 of file action_handler.cpp.

00346 {
00347   if(Game::GetInstance()->IsGameLaunched())
00348     //Add message to chat session in Game
00349     //    GameLoop::GetInstance()->chatsession.chat->AddText(a->PopString());
00350     GameLoop::GetInstance()->chatsession.NewMessage(a->PopString());
00351   else
00352     //Network Menu
00353     network.network_menu->ReceiveMsgCallback(a->PopString());
00354 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_ConstructionDown ( Action a  ) 

Definition at line 462 of file action_handler.cpp.

00463 {
00464   Construct* launcher = dynamic_cast<Construct*>(&(ActiveTeam().AccessWeapon()));
00465   assert(launcher != NULL);
00466   launcher->Down();
00467 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_ConstructionUp ( Action a  ) 

Definition at line 455 of file action_handler.cpp.

00456 {
00457   Construct* launcher = dynamic_cast<Construct*>(&(ActiveTeam().AccessWeapon()));
00458   assert(launcher != NULL);
00459   launcher->Up();
00460 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_DelTeam ( Action a  ) 

Definition at line 337 of file action_handler.cpp.

00338 {
00339   std::string team = a->PopString();
00340   teams_list.DelTeam (team);
00341   network.network_menu->DelTeamCallback(team);
00342 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_Down ( Action a  ) 

Definition at line 133 of file action_handler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_Explosion ( Action a  ) 

Definition at line 418 of file action_handler.cpp.

00419 {
00420   Point2i pos;
00421   ExplosiveWeaponConfig config;
00422 
00423   pos.x = a->PopInt();
00424   pos.y = a->PopInt();
00425   config.explosion_range = a->PopInt();
00426   config.particle_range = a->PopInt();
00427   config.damage = a->PopInt();
00428   config.blast_range = a->PopDouble();
00429   config.blast_force = a->PopDouble();
00430   std::string son = a->PopString();
00431   bool fire_particle = a->PopInt();
00432   ParticleEngine::ESmokeStyle smoke = (ParticleEngine::ESmokeStyle)a->PopInt();
00433 
00434   ApplyExplosion_common(pos, config, son, fire_particle, smoke);
00435 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_HighJump ( Action a  ) 

Definition at line 116 of file action_handler.cpp.

00117 {
00118   GameLoop::GetInstance()->character_already_chosen = true;
00119   ActiveCharacter().HighJump();
00120 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_Jump ( Action a  ) 

Definition at line 110 of file action_handler.cpp.

00111 {
00112   GameLoop::GetInstance()->character_already_chosen = true;
00113   ActiveCharacter().Jump();
00114 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_MoveLeft ( Action a  ) 

Definition at line 104 of file action_handler.cpp.

00105 {
00106   assert(false);
00107   MoveCharacterLeft (ActiveCharacter());
00108 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_MoveRight ( Action a  ) 

Definition at line 98 of file action_handler.cpp.

00099 {
00100   assert(false);
00101   MoveCharacterRight (ActiveCharacter());
00102 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_NewTeam ( Action a  ) 

Definition at line 310 of file action_handler.cpp.

00311 {
00312   ConfigTeam the_team;
00313 
00314   the_team.id = a->PopString();
00315   the_team.player_name = a->PopString();
00316   the_team.nb_characters = uint(a->PopInt());
00317 
00318   teams_list.AddTeam (the_team);
00319 
00320   network.network_menu->AddTeamCallback(the_team.id);
00321 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_NextCharacter ( Action a  ) 

Definition at line 143 of file action_handler.cpp.

00144 {
00145   a->RetrieveCharacter();       // Retrieve current character's informations
00146   a->RetrieveCharacter();       // Retrieve next character information
00147   camera.FollowObject(&ActiveCharacter(), true, true);
00148 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_Nickname ( Action a  ) 

Definition at line 474 of file action_handler.cpp.

00475 {
00476 
00477 }

Here is the caller graph for this function:

void Action_Pause ( Action a  ) 

Definition at line 479 of file action_handler.cpp.

00480 {
00481   // Toggle pause
00482   Game::GetInstance()->Pause();
00483 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_Ping ( Action a  ) 

Definition at line 414 of file action_handler.cpp.

00415 {
00416 }

Here is the caller graph for this function:

void Action_SendRandom ( Action a  ) 

Definition at line 380 of file action_handler.cpp.

00381 {
00382   if (!network.IsClient()) return;
00383   randomSync.AddToTable(a->PopDouble());
00384 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_SendVersion ( Action a  ) 

Definition at line 369 of file action_handler.cpp.

00370 {
00371   if (!network.IsServer()) return;
00372   std::string version= a->PopString();
00373   if (version != Constants::VERSION)
00374   {
00375     Error(Format(_("Wormux versions are differents : client=%s, server=%s."),
00376     version.c_str(), Constants::VERSION.c_str()));
00377   }
00378 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_SetCharacterDirection ( Action a  ) 

Definition at line 202 of file action_handler.cpp.

00203 {
00204   ActiveCharacter().SetDirection (Body::Direction_t(a->PopInt()));
00205 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_SetCharacterEnergy ( Action a  ) 

Definition at line 182 of file action_handler.cpp.

00183 {
00184   int team_no, char_no;
00185   team_no = a->PopInt();
00186   char_no = a->PopInt();
00187   Character* c = teams_list.FindPlayingByIndex(team_no)->FindByIndex(char_no);
00188   c->SetEnergy( a->PopInt() );
00189 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_SetCharacterPhysics ( Action a  ) 

Definition at line 176 of file action_handler.cpp.

00177 {
00178   while(!a->IsEmpty())
00179     a->RetrieveCharacter();
00180 }

Here is the caller graph for this function:

void Action_SetGameMode ( Action a  ) 

Definition at line 257 of file action_handler.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_SetMap ( Action a  ) 

Definition at line 207 of file action_handler.cpp.

00208 {
00209   if (!network.IsClient()) return;
00210   MapsList::GetInstance()->SelectMapByName(a->PopString());
00211   network.network_menu->ChangeMapCallback();
00212 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_SetSkin ( Action a  ) 

Definition at line 191 of file action_handler.cpp.

00192 {
00193   //Set the frame of the walking skin, to get the position of the hand synced
00194   if (!ActiveTeam().IsLocal() || network.state != Network::NETWORK_PLAYING)
00195   {
00196     ActiveTeam().ActiveCharacter().SetClothe(a->PopString());
00197     ActiveTeam().ActiveCharacter().SetMovement(a->PopString());
00198     ActiveTeam().ActiveCharacter().body->SetFrame((uint)a->PopInt());
00199   }
00200 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_SetTarget ( Action a  ) 

Definition at line 437 of file action_handler.cpp.

00438 {
00439   MSG_DEBUG("action.handler", "Set target by clicking");
00440 
00441   Point2i target;
00442   target.x = a->PopInt();
00443   target.y = a->PopInt();
00444 
00445   ActiveTeam().AccessWeapon().ChooseTarget (target);
00446 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_SetTimeout ( Action a  ) 

Definition at line 448 of file action_handler.cpp.

00449 {
00450   WeaponLauncher* launcher = dynamic_cast<WeaponLauncher*>(&(ActiveTeam().AccessWeapon()));
00451   assert(launcher != NULL);
00452   launcher->GetProjectile()->m_timeout_modifier = a->PopInt();
00453 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_Shoot ( Action a  ) 

Definition at line 156 of file action_handler.cpp.

00157 {
00158   double strength = a->PopDouble();
00159   double angle = a->PopDouble();
00160   a->RetrieveCharacter();
00161   ActiveTeam().AccessWeapon().PrepareShoot(strength, angle);
00162 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_SupertuxState ( Action a  ) 

Definition at line 386 of file action_handler.cpp.

00387 {
00388   assert(ActiveTeam().GetWeaponType() == Weapon::WEAPON_SUPERTUX);
00389   WeaponLauncher* launcher = static_cast<WeaponLauncher*>(&(ActiveTeam().AccessWeapon()));
00390   SuperTux* tux = static_cast<SuperTux*>(launcher->GetProjectile());
00391 
00392   double x, y;
00393 
00394   tux->SetAngle(a->PopDouble());
00395   x = a->PopDouble();
00396   y = a->PopDouble();
00397   tux->SetPhysXY(x, y);
00398   tux->SetSpeedXY(Point2d(0,0));
00399 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_SyncBegin ( Action a  ) 

Definition at line 401 of file action_handler.cpp.

00402 {
00403   assert(!network.sync_lock);
00404   network.sync_lock = true;
00405 }

Here is the caller graph for this function:

void Action_SyncEnd ( Action a  ) 

Definition at line 407 of file action_handler.cpp.

00408 {
00409   assert(network.sync_lock);
00410   network.sync_lock = false;
00411 }

Here is the caller graph for this function:

void Action_Up ( Action a  ) 

Definition at line 128 of file action_handler.cpp.

00129 {
00130   ActiveCharacter().AddFiringAngle(-DELTA_CROSSHAIR);
00131 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_UpdateTeam ( Action a  ) 

Definition at line 323 of file action_handler.cpp.

00324 {
00325   ConfigTeam the_team;
00326 
00327   the_team.id = a->PopString();
00328   the_team.player_name = a->PopString();
00329   the_team.nb_characters = uint(a->PopInt());
00330 
00331   teams_list.UpdateTeam (the_team);
00332 
00333   network.network_menu->UpdateTeamCallback(the_team.id);
00334 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_WeaponStopUse ( Action a  ) 

Definition at line 469 of file action_handler.cpp.

00470 {
00471   ActiveTeam().AccessWeapon().ActionStopUse();
00472 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Action_Wind ( Action a  ) 

Definition at line 164 of file action_handler.cpp.

00165 {
00166   wind.SetVal (a->PopInt());
00167 }

Here is the call graph for this function:

Here is the caller graph for this function:

Action* BuildActionSendCharacterPhysics ( int  team_no,
int  char_no 
)

Definition at line 169 of file action_handler.cpp.

00170 {
00171   Action* a = new Action(Action::ACTION_SET_CHARACTER_PHYSICS);
00172   a->StoreCharacter(team_no, char_no);
00173   return a;
00174 }

Here is the caller graph for this function:

void SendGameMode (  ) 

Definition at line 282 of file action_handler.cpp.

00283 {
00284   assert(network.IsServer());
00285   Action a(Action::ACTION_SET_GAME_MODE);
00286   a.Push((int)GameMode::GetInstance()->max_characters);
00287   a.Push((int)GameMode::GetInstance()->max_teams);
00288   a.Push((int)GameMode::GetInstance()->duration_turn);
00289   a.Push((int)GameMode::GetInstance()->duration_exchange_player);
00290   a.Push((int)GameMode::GetInstance()->duration_before_death_mode);
00291   a.Push(GameMode::GetInstance()->gravity);
00292   a.Push(GameMode::GetInstance()->safe_fall);
00293   a.Push(GameMode::GetInstance()->damage_per_fall_unit);
00294   a.Push((int)GameMode::GetInstance()->duration_move_player);
00295   a.Push(GameMode::GetInstance()->allow_character_selection);
00296   a.Push((int)GameMode::GetInstance()->character.init_energy);
00297   a.Push((int)GameMode::GetInstance()->character.max_energy);
00298   a.Push((int)GameMode::GetInstance()->character.mass);
00299   a.Push(GameMode::GetInstance()->character.air_resist_factor);
00300   a.Push((int)GameMode::GetInstance()->character.jump_strength);
00301   a.Push(GameMode::GetInstance()->character.jump_angle);
00302   a.Push((int)GameMode::GetInstance()->character.super_jump_strength);
00303   a.Push(GameMode::GetInstance()->character.super_jump_angle);
00304   a.Push((int)GameMode::GetInstance()->character.back_jump_strength);
00305   a.Push(GameMode::GetInstance()->character.back_jump_angle);
00306   network.SendAction(&a);
00307 }

Here is the call graph for this function:

Here is the caller graph for this function:

void SyncCharacters (  ) 

Definition at line 63 of file action_handler.cpp.

00064 {
00065   assert(network.IsServer());
00066   ActionHandler* action_handler = ActionHandler::GetInstance();
00067 
00068   Action a_begin_sync(Action::ACTION_SYNC_BEGIN);
00069   network.SendAction(&a_begin_sync);
00070   TeamsList::iterator
00071     it=teams_list.playing_list.begin(),
00072     end=teams_list.playing_list.end();
00073 
00074   for (int team_no = 0; it != end; ++it, ++team_no)
00075   {
00076     Team& team = **it;
00077     Team::iterator
00078         tit = team.begin(),
00079         tend = team.end();
00080 
00081     for (int char_no = 0; tit != tend; ++tit, ++char_no)
00082     {
00083       // Sync the character's energy
00084       Action* a = new Action(Action::ACTION_SET_CHARACTER_ENERGY);
00085       a->Push(team_no);
00086       a->Push(char_no);
00087       a->Push((int)(*tit).GetEnergy());
00088       action_handler->NewAction(a);
00089       // Sync the character's position
00090       a = BuildActionSendCharacterPhysics(team_no, char_no);
00091       action_handler->NewAction(a);
00092     }
00093   }
00094   Action a_sync_end(Action::ACTION_SYNC_END);
00095   network.SendAction(&a_sync_end);
00096 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Mon Jan 1 13:18:24 2007 for Wormux by  doxygen 1.4.7