Add infos into target window
[ryzomcore.git] / ryzom / server / src / gpm_service / client_messages.cpp
blobee02f613950c792ebd3794c82ffd6216ef0d4c10
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "stdpch.h"
20 // include files
21 #include "nel/misc/types_nl.h"
23 #include "client_messages.h"
25 //#include "game_share/tick_event_handler.h"
26 //#include "game_share/msg_client_server.h"
27 //#include "game_share/mode_and_behaviour.h" //TEMP!!!
28 //#include "game_share/news_types.h"
29 //#include "game_share/bot_chat_types.h"
30 //#include "game_share/brick_types.h"
31 //#include "game_share/loot_harvest_state.h"
32 //#include "game_share/ryzom_mirror_properties.h"
34 #include "server_share/r2_variables.h"
36 #include "world_position_manager.h"
37 #include "gpm_service.h"
39 using namespace std;
40 using namespace NLMISC;
41 using namespace NLNET;
44 /****************************************************************\
45 cbUpdateEntityPosition()
46 \****************************************************************/
47 void cbClientPosition( CMessage& msgin, const string &serviceName, NLNET::TServiceId serviceId )
49 H_AUTO(cbClientPosition);
51 CEntityId id;
52 NLMISC::TGameCycle tick;
53 msgin.serial(id, tick);
55 TDataSetRow entityIndex = TheDataset.getDataSetRow( id );
56 if ( !entityIndex.isValid() )
58 // client may send position even before it is added in system
59 //nldebug( "%u: Receiving a position from client %s which is not in mirror yet", CTickEventHandler::getGameCycle(), id.toString().c_str() );
60 return;
63 // entity pos (x, y, z, theta)
64 sint32 x, y, z;
65 float heading;
66 msgin.serial(x, y, z, heading);
68 if (IsRingShard)
70 // make sure the move that the player is trying to make is legal
71 // if the move wasn't legal then the values of 'x' and 'y' will be changed to make them legal
72 bool moveWasLegal= pCGPMS->MoveChecker->checkMove(entityIndex, x, y, tick);
74 // if the move wasn't legal then dispatch a message to the player
75 if (!moveWasLegal)
77 // ***TODO ***
78 // // Teleport the player back to a previous valid location
79 // CMessage msgout( "IMPULSION_ID" );
80 // msgout.serial( master->Id );
81 // CBitMemStream bms;
82 // GenericXmlMsgManager.pushNameToStream( "TP:CORRECT", bms );
83 // bms.serial( x );
84 // bms.serial( y );
85 // bms.serial( z );
86 // msgout.serialMemStream( bms );
87 // CUnifiedNetwork::getInstance()->send( master->Id.getDynamicId(), msgout );
88 // ***TODO ***
91 // set the player coordinates in the ring vision universe
92 pCGPMS->RingVisionUniverse->setEntityPosition(entityIndex,x,y);
94 // todo: determine whether player is in water etc for real;
95 bool local= false;
96 bool interior= false;
97 bool water= false;
99 // update the player coordinates in the mirror
100 CMirrorPropValue1DS<sint32>( TheDataset, entityIndex, DSPropertyPOSX )= x;
101 CMirrorPropValue1DS<sint32>( TheDataset, entityIndex, DSPropertyPOSY )= y;
102 CMirrorPropValue1DS<sint32>( TheDataset, entityIndex, DSPropertyPOSZ )= (z&~7) + (local ? 1 : 0) + (interior ? 2 : 0) + (water ? 4 : 0);
103 CMirrorPropValue1DS<float>( TheDataset, entityIndex, DSPropertyORIENTATION )= heading;
104 CMirrorPropValue1DS<NLMISC::TGameCycle>( TheDataset, entityIndex, DSPropertyTICK_POS )= tick;
106 CMirrorPropValue1DS<TYPE_CELL> cell ( TheDataset, entityIndex, DSPropertyCELL );
107 uint32 cx = (uint16) ( + x/CWorldPositionManager::getCellSize() );
108 uint32 cy = (uint16) ( - y/CWorldPositionManager::getCellSize() );
109 cell = (cx<<16) + cy;
111 // update the player position in the ring vision grid
112 pCGPMS->RingVisionUniverse->setEntityPosition(entityIndex,x,y);
114 else
117 // check player mode and behaviour
118 CMirrorPropValueRO<MBEHAV::TMode> propMode( TheDataset, entityIndex, DSPropertyMODE );
119 MBEHAV::EMode mode = (MBEHAV::EMode)(propMode().Mode);
120 CMirrorPropValueRO<MBEHAV::CBehaviour> propBehaviour( TheDataset, entityIndex, DSPropertyBEHAVIOUR );
121 MBEHAV::EBehaviour behaviour = (MBEHAV::EBehaviour)(propBehaviour().Behaviour);
122 if ( (mode == MBEHAV::COMBAT)
123 || (mode == MBEHAV::COMBAT_FLOAT)
124 || (mode == MBEHAV::DEATH) )
126 H_AFTER(cbClientPosition);
127 return;
130 CWorldEntity *player = CWorldPositionManager::getEntityPtr(entityIndex);
132 if (player == NULL)
134 return;
137 if (player->X() == 0 && player->Y() == 0 && player->Z() == 0)
139 return;
142 //CWorldPositionManager::setEntityPosition(id, x, y, z, heading, tick);
143 if (player->getType() == CWorldEntity::Player && player->CheckMotion && player->PosInitialised)
145 CWorldPositionManager::movePlayer(player, x, y, z, heading, tick);
148 } // cbClientPosition //
150 //----------------------------
151 // CbClientArray
152 //----------------------------
153 TUnifiedCallbackItem CbClientArray[]=
155 { "CLIENT:POSITION", cbClientPosition },
161 //-------------------------------------------------------------------------
162 // singleton initialisation and release
164 void CClientMessages::init()
166 // setup the callback array
167 CUnifiedNetwork::getInstance()->addCallbackArray( CbClientArray, sizeof(CbClientArray)/sizeof(CbClientArray[0]) );
170 void CClientMessages::release()