Mercurial > sumwars
changeset 1:5a125ff6877f branch_net
=spiel lokal wieder lauffaehig
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/items.xml Fri Sep 19 11:03:22 2008 +0000 @@ -0,0 +1,63 @@ +<?xml version="1.0" ?> + +<!-- Bei Gegenstaenden, die keine Waffen sind kann "WeaponAttribute" weggelassen werden. --> + +<!-- general +<Item type="weapon" subtype="short_sw" size="medium"> + <Mesh file="sword.mesh" /> + <Attribute + level_requirement="char" + character_requirement="char" + price="int" + min_enchant="30" + max_enchant="120" + /> + <UseupEffect /> + <EquipEffect /> + <WeaponAttribute + damage_min_physical="5" + damage_max_physical="10" + damage_min_air="0" + damage_max_air="0" + damage_min_ice="0" + damage_max_ice="0" + damage_min_fire="0" + damage_max_fire="0" + damage_attack="20" + damage_power="30" + attack_range="1.0" + two_handed="no" + dattack_speed="500" + /> + <DropChance + level="int" + probability="float" + /> +</Item> +--> + + +<!-- Short Sword --> +<Item type="weapon" subtype="short_sw" size="medium"> + <Mesh file="sword.mesh" /> + <Attribute + price="150" + min_enchant="30" + max_enchant="120" + /> + <EquipEffect /> + <WeaponAttribute + damage_min_physical="5" + damage_max_physical="10" + damage_attack="20" + damage_power="30" + attack_range="1.0" + two_handed="no" + dattack_speed="500" + /> + <DropChance + level="0" + probability="1.0" + /> +</Item> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/monsters.xml Fri Sep 19 11:03:22 2008 +0000 @@ -0,0 +1,49 @@ +<?xml version="1.0" ?> + + +<!-- Goblin --> +<!-- 3871 = 0xf1f --> +<Monster type="MONSTER" subtype="GOBLIN" fraction="MONSTER" category="GOBLIN"> + <Dropslots p0="0.1" p1="0.2" p2="0.2" p3="0.2" /> + <Dropslot0 min_level="0" max_level="20" magic_prob="0.3" magic_power="500" /> + <Dropslot1 min_level="0" max_level="10" magic_prob="0.3" magic_power="1000" /> + + <BasicAttributes + max_experience="100000" + level="1" + max_health="15" + armor="10" + block="0" + attack="10" + strength="15" + dexterity="10" + magic_power="5" + willpower="10" + resistances_physical="0" + resistances_air="0" + resistances_ice="0" + resistances_fire="0" + resistances_cap_physical="50" + resistances_cap_air="50" + resistances_cap_ice="50" + resistances_cap_fire="50" + walk_speed="2000" + attack_speed="1500" + step_length="0.5" + abilities0="3871" + abilities1="0" + abilities2="0" + abilities3="0" + abilities4="0" + abilities5="0" + attack_range="1" + special_flags="0" + immunity="0" + /> + + <Geometry radius="0.5" /> + + <AI ai_sight_range="8" /> +</Monster> + +
--- a/items.xml Wed Sep 17 11:01:52 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -<?xml version="1.0" ?> - -<!-- Bei Gegenstaenden, die keine Waffen sind kann "WeaponAttribute" weggelassen werden. --> - -<!-- general -<Item type="weapon" subtype="short_sw" size="medium"> - <Mesh file="sword.mesh" /> - <Attribute - level_requirement="char" - character_requirement="char" - price="int" - min_enchant="30" - max_enchant="120" - /> - <UseupEffect /> - <EquipEffect /> - <WeaponAttribute - damage_min_physical="5" - damage_max_physical="10" - damage_min_air="0" - damage_max_air="0" - damage_min_ice="0" - damage_max_ice="0" - damage_min_fire="0" - damage_max_fire="0" - damage_attack="20" - damage_power="30" - attack_range="1.0" - two_handed="no" - dattack_speed="500" - /> - <DropChance - level="int" - probability="float" - /> -</Item> ---> - - -<!-- Short Sword --> -<Item type="weapon" subtype="short_sw" size="medium"> - <Mesh file="sword.mesh" /> - <Attribute - price="150" - min_enchant="30" - max_enchant="120" - /> - <EquipEffect /> - <WeaponAttribute - damage_min_physical="5" - damage_max_physical="10" - damage_attack="20" - damage_power="30" - attack_range="1.0" - two_handed="no" - dattack_speed="500" - /> - <DropChance - level="0" - probability="1.0" - /> -</Item> -
--- a/monsters.xml Wed Sep 17 11:01:52 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -<?xml version="1.0" ?> - - -<!-- Goblin --> -<!-- 3871 = 0xf1f --> -<Monster type="MONSTER" subtype="GOBLIN" fraction="MONSTER" category="GOBLIN"> - <Dropslots p0="0.1" p1="0.2" p2="0.2" p3="0.2" /> - <Dropslot0 min_level="0" max_level="20" magic_prob="0.3" magic_power="500" /> - <Dropslot1 min_level="0" max_level="10" magic_prob="0.3" magic_power="1000" /> - - <BasicAttributes - max_experience="100000" - level="1" - max_health="15" - armor="10" - block="0" - attack="10" - strength="15" - dexterity="10" - magic_power="5" - willpower="10" - resistances_physical="0" - resistances_air="0" - resistances_ice="0" - resistances_fire="0" - resistances_cap_physical="50" - resistances_cap_air="50" - resistances_cap_ice="50" - resistances_cap_fire="50" - walk_speed="2000" - attack_speed="1500" - step_length="0.5" - abilities0="3871" - abilities1="0" - abilities2="0" - abilities3="0" - abilities4="0" - abilities5="0" - attack_range="1" - special_flags="0" - immunity="0" - /> - - <Geometry radius="0.5" /> - - <AI ai_sight_range="8" /> -</Monster> - -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/resources Fri Sep 19 11:03:22 2008 +0000 @@ -0,0 +1,1 @@ +../trunk/client/resources \ No newline at end of file
--- a/src/core/Makefile Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/Makefile Fri Sep 19 11:03:22 2008 +0000 @@ -15,7 +15,7 @@ LDFLAGS = $(shell pkg-config --libs $(LIBS)) LOADLIBES = LDLIBS = $(LDFLAGS) -lm -lrt -CFLAGS = -g +CFLAGS = -O3 CXXFLAGS = $(shell pkg-config --cflags $(LIBS)) $(CFLAGS) OBJS = $(shell cat ./Makefile.objs ) DIRS = $(shell find . -mindepth 1 -maxdepth 1 -type d -not -iname .svn )
--- a/src/core/Makefile.objs Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/Makefile.objs Fri Sep 19 11:03:22 2008 +0000 @@ -1,40 +1,39 @@ -trade.o -world.o -main.o -objectfactory.o -objectloader.o -itemlist.o -gridunit.o -servernetwork.o -action.o -worldobject.o -networkstruct.o -projectile.o -party.o -debug.o -item.o -dropitem.o -dmgprojectile.o -creature.o -pathfind.o -fixedobject.o -serverwobject.o -player.o -warrior.o -monster.o -mage.o -archer.o -priest.o -itemfactory.o -itemloader.o -serveritem.o -damage.o -random.o -region.o -server.o -spawnpoint.o -document.o -network.o +../core/trade.o +../core/world.o +../core/objectfactory.o +../core/objectloader.o +../core/itemlist.o +../core/gridunit.o +../core/servernetwork.o +../core/clientnetwork.o +../core/worldobject.o +../core/networkstruct.o +../core/projectile.o +../core/party.o +../core/debug.o +../core/item.o +../core/dropitem.o +../core/dmgprojectile.o +../core/creature.o +../core/pathfind.o +../core/fixedobject.o +../core/serverwobject.o +../core/player.o +../core/warrior.o +../core/monster.o +../core/mage.o +../core/archer.o +../core/priest.o +../core/itemfactory.o +../core/itemloader.o +../core/serveritem.o +../core/damage.o +../core/random.o +../core/region.o +../core/spawnpoint.o +../core/document.o +../core/network.o +../core/action.o ../tinyxml/tinyxml.o ../tinyxml/tinyxmlparser.o
--- a/src/core/action.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/action.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -24,10 +24,12 @@ a->m_req_ability[1] = Action::NOACTION; a->m_req_ability[2] = Action::NOACTION; a->m_description = "descr_noaction"; - a->m_enum_name = "noaction"; - a->m_animation[NO_WEAPON].push_back("idle"); - a->m_animation[ONE_HANDED].push_back("attack"); + a->m_enum_name = "noaction"; + a->m_animation[NO_WEAPON].push_back("idle"); + a->m_animation[ONE_HANDED].push_back("attack"); a->m_animation[TWO_HANDED].push_back("idle"); + + a = &(Action::m_base_info[Action::WALK]); a->m_timer_nr=0;
--- a/src/core/action.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/action.h Fri Sep 19 11:03:22 2008 +0000 @@ -215,6 +215,13 @@ */ struct ActionInfo { + ActionInfo() + { + m_animation[NO_WEAPON].clear(); + m_animation[ONE_HANDED].clear(); + m_animation[TWO_HANDED].clear(); + + } /** * \var m_timer_nr * \brief Nummer des Timers, der bei benutzen der Aktion gestartet wird. Moegliche Werte sind 0,1,2
--- a/src/core/clientnetwork.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/clientnetwork.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -4,7 +4,7 @@ ClientNetwork::ClientNetwork() : Network() { - + m_server_address = UNASSIGNED_SYSTEM_ADDRESS; m_status = NET_CLOSE; } @@ -96,33 +96,27 @@ } -int ClientNetwork::numberSlotMessages() +int ClientNetwork::numberSlotMessages(int slot) { return m_received_packets.size(); } -void ClientNetwork::popSlotMessage( Packet* &data) +void ClientNetwork::popSlotMessage( Packet* &data,int slot) { data = m_received_packets.front(); m_received_packets.pop(); } -void ClientNetwork::pushSlotMessage( RakNet::BitStream * data,PacketPriority prio,PacketReliability reliability) +void ClientNetwork::pushSlotMessage( RakNet::BitStream * data,int slot,PacketPriority prio,PacketReliability reliability) { m_peer->Send(data,prio,reliability , 0,m_server_address, false); } -NetStatus ClientNetwork::getSlotStatus() +NetStatus ClientNetwork::getSlotStatus(int slot) { return m_status; } -void ClientNetwork::deallocatePacket(Packet* packet) -{ - static int nr =0; - nr++; - DEBUG5("packets deallocated: %i",nr); - m_peer->DeallocatePacket(packet); -} +
--- a/src/core/creature.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/creature.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -509,9 +509,9 @@ // Aktion ist beendet m_action.m_type = Action::NOACTION; m_action.m_elapsed_time =0; - } - - + } + + } @@ -2265,7 +2265,7 @@ if (i->m_time <=0) { // Zeit abgelaufen, Modifikation deaktivieren - DEBUG("removing base attr mod"); + DEBUG5("removing base attr mod"); recalc |= removeBaseAttrMod((CreatureBaseAttrMod*) &(*i)); i=m_dyn_attr.m_temp_mods.erase(i); } @@ -2428,7 +2428,9 @@ setDestroyed(true); } - default: time=0 ; + default: + DEBUG5("unknown state: %i",getState()); + time=0 ; } } @@ -3837,3 +3839,24 @@ return true; } +float Creature::getTimerPercent(int timer) +{ + if (timer ==1) + { + if (m_timer1_max ==0) + return 0; + + return m_timer1 / m_timer1_max; + } + + if (timer ==2) + { + if (m_timer2_max ==0) + return 0; + + return m_timer2 / m_timer2_max; + } + + return 0; +} +
--- a/src/core/creature.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/creature.h Fri Sep 19 11:03:22 2008 +0000 @@ -176,6 +176,12 @@ m_trade_id = trade_id; } + /** + * \fn float getTimerPercent(int timer) + * \brief Gibt den Prozentsatz des gewaehlten Timers aus + */ + float getTimerPercent(int timer); + //Operations /** @@ -286,7 +292,37 @@ */ virtual void toString(CharConv* cv); + /** + * \fn bool checkAbility(Action::ActionType at) + * \brief Prueft ob die Kreatur ueber die angegebene Faehigkeit verfuegt + * \param at Faehigkeit + * \return true, wenn die Faehigkeit verfuegbar ist + */ + bool checkAbility(Action::ActionType at); + + /** + * \fn bool checkAbilityLearnable(Action::ActionType at) + * \brief Testet ob eine Faehigkeit erlernbar ist + * \param at Faehigkeit + * \return true, wenn die Faehigkeit erlernbar ist + */ + bool checkAbilityLearnable(Action::ActionType at); + + /** + * \fn virtual void calcDamage(ActionType type,Damage& dmg) + * \brief Berechnet den Schaden fuer die aktuell ausgefuehrte Aktion + */ + virtual void calcDamage(Action::ActionType act,Damage& dmg); + + /** + * \fn virtual Action::ActionEquip getActionEquip() + * \brief Gibt aus, ob die Aktion einhaendig oder zweihaendig ausgefuehrt wird + */ + virtual Action::ActionEquip getActionEquip() + { + return Action::ONE_HANDED; + } protected: @@ -302,11 +338,7 @@ */ virtual void calcBaseAttrMod(); - /** - * \fn virtual void calcDamage(ActionType type,Damage& dmg) - * \brief Berechnet den Schaden fuer die aktuell ausgefuehrte Aktion - */ - virtual void calcDamage(Action::ActionType act,Damage& dmg); + /** * \fn virtual void recalcDamage(); @@ -389,28 +421,9 @@ */ void collisionDetection(float time); - /** - * \fn bool checkAbility(Action::ActionType at) - * \brief Prueft ob die Kreatur ueber die angegebene Faehigkeit verfuegt - * \param at Faehigkeit - * \return true, wenn die Faehigkeit verfuegbar ist - */ - bool checkAbility(Action::ActionType at); - + - /** - * \fn bool checkAbilityLearnable(Action::ActionType at) - * \brief Testet ob eine Faehigkeit erlernbar ist - * \param at Faehigkeit - * \return true, wenn die Faehigkeit erlernbar ist - */ - bool checkAbilityLearnable(Action::ActionType at); - /** - * \fn virtual Action::ActionEquip getActionEquip() - * \brief Gibt aus, ob die Aktion einhaendig oder zweihaendig ausgefuehrt wird - */ - virtual Action::ActionEquip getActionEquip() =0; //Private stuff
--- a/src/core/document.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/document.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -26,39 +26,29 @@ : m_special_keys() , m_shortkey_map() { - DEBUG("reading ip"); + DEBUG5("reading ip"); // IP aus Konfigurationsdatei einlesen { ifstream file("config"); - DEBUG("file opened"); + DEBUG5("file opened"); if ( file.is_open() ) { - file >> getNetworkInfo()->m_server_ip; - ERRORMSG("Server-IP: %s", getNetworkInfo()->m_server_ip); + file >> m_server_ip; + DEBUG5("Server-IP: %s", m_server_ip); } else { ERRORMSG("config nicht gefunden"); } } + + m_world =0; bool network_error = false; // Informationen zu Aktionen initialisieren Action::init(); - // Datenstrukturen fuer Objekte und Projektile anlegen - m_objects_bintree= new map<int, ClientWObject*>; - m_projectiles = new map<int,Projectile*>; - m_drop_items = new map<int,DropItem>; - - m_region_data.m_static_objects = new map<int,WorldObject*>; - m_region_data.m_static_objects->clear(); - m_region_data.m_tiles =0; - - // Netzwerk initialisieren - getNetworkInfo()->m_network = new ClientNetwork(); - // Status der GUI setzen getGUIState()->m_left_mouse_hold= false; @@ -66,7 +56,8 @@ getGUIState()->m_shift_hold = false; getGUIState()->m_sheet= MAIN_MENU; getGUIState()->m_shown_windows = SAVEGAME_LIST; - getGUIState()->m_pressed_key = OIS::KC_UNASSIGNED; + //getGUIState()->m_pressed_key = OIS::KC_UNASSIGNED; + getGUIState()->m_pressed_key =0; getGUIState()->m_cursor_object =""; getGUIState()->m_cursor_object_id =0; getGUIState()->m_cursor_item_id =0; @@ -76,11 +67,7 @@ // Pointer/Inhalte mit 0 initialisieren m_gui_state.m_chat_window_content = ""; m_data_locks=0; - m_main_player =0; - m_party =0; m_savegame =0; - m_detailed_item=0; - m_ability_pos=Action::NOACTION; // aktuell eingestellte Aktionen setzen @@ -92,6 +79,7 @@ // Shortkeys einstellen m_shortkey_map.clear(); + /* installShortkey(OIS::KC_I,SHOW_INVENTORY); installShortkey(OIS::KC_C,SHOW_CHARINFO); installShortkey(OIS::KC_T,SHOW_SKILLTREE); @@ -114,34 +102,48 @@ m_special_keys.insert(OIS::KC_ESCAPE); m_special_keys.insert(OIS::KC_LSHIFT); m_special_keys.insert(OIS::KC_LCONTROL); + */ } -void Document::serverConnect() +void Document::startGame(bool server) { - // Verbindung aufbauen - NetStatus ret; - getNetworkInfo()->m_network->serverConnect( getNetworkInfo()->m_server_ip,REQ_PORT); - m_state = CONNECTING; + m_server = server; + + + + m_world = new World(server); + m_world->init(); + + if (server) + { + + } + else + { + ClientNetwork* net = static_cast<ClientNetwork*>(m_world->getNetwork()); + net->serverConnect(m_server_ip,REQ_PORT); + + } + m_state = LOAD_SAVEGAME; +} - - -} - -void Document::sendSavegame() +void Document::loadSavegame() { // Savegame einlesen DEBUG5("lese savegame"); char head[8]; int i; char* bp = head; - string fname = "../client/"; + string fname = "../../save/"; fname += m_save_file; + /* if (m_gui_type == GL_GUI) { fname = m_save_file; } + */ DEBUG5("savegame is %s",fname.c_str()); ifstream file(fname.c_str(),ios::in| ios::binary); @@ -151,7 +153,7 @@ { file.get(head[i]); } - CharConv cv((unsigned char*) head,8); + CharConv cv((unsigned char*) head,18); char binsave; cv.fromBuffer<char>(binsave); short version; @@ -167,16 +169,8 @@ { file.get(data[i]); } - //hexwrite(data+45,len-45); - - // Savegame an den Server senden - ClientHeader header; - header.m_content = PTYPE_C2S_SAVEGAME; // Savegame von Client zu Server - header.m_chatmessage = false; // keine Chatnachricht - CharConv save; - header.toString(&save); - save.toBuffer(data,len); - getNetworkInfo()->m_network->pushSlotMessage(save.getBitStream()); + + m_world->handleSavegame(data); // aktuelle Aktion setzen @@ -204,16 +198,18 @@ setRightAction((Action::ActionType) n); m_right_action=(Action::ActionType) n; */ + /* setRightAction(Action::ATTACK) ; m_left_action = Action::ATTACK; setLeftAction(Action::ATTACK); m_right_action = Action::ATTACK; - +*/ - m_state = CONNECTED; + m_state =RUNNING; m_gui_state.m_shown_windows = NO_WINDOWS; m_gui_state.m_sheet = GAME_SCREEN; m_modified = WINDOWS_MODIFIED | GUISHEET_MODIFIED; + m_timer.start(); delete data; @@ -227,11 +223,6 @@ Document::~Document() { - delete m_region_data.m_static_objects; - delete m_projectiles; - delete m_objects_bintree; - delete getNetworkInfo()->m_network; - delete m_drop_items; } // Methods @@ -260,24 +251,7 @@ void Document::sendCommand(ClientCommand* comm) { - CharConv cv; - - // Header anlegen - ClientHeader header; - header.m_content = PTYPE_C2S_DATA; // Daten von Client zu Server - header.m_chatmessage = false; // keine Chatnachricht - - - // Header in den Puffer schreiben - header.toString(&cv); - // Kommando in den Puffer schreiben - comm->toString(&cv); - DEBUG4("Kommando (%f %f) button: %i id: %i action: %i",comm->m_coordinate_x,comm->m_coordinate_y,comm->m_button, comm->m_id,comm->m_action); - - - - // Datenpaket zum Server senden - m_network_info.m_network->pushSlotMessage(cv.getBitStream()); + m_world->handleCommand(comm); } @@ -298,9 +272,9 @@ ERRORMSG("kritischer Abschnitt verletzt"); } -OIS::KeyCode Document::getMappedKey(ShortkeyDestination sd) +KeyCode Document::getMappedKey(ShortkeyDestination sd) { - map<OIS::KeyCode, ShortkeyDestination>::iterator it; + map<KeyCode, ShortkeyDestination>::iterator it; for (it=m_shortkey_map.begin(); it!= m_shortkey_map.end();++it) { if (it->second == sd) @@ -309,15 +283,15 @@ } } - return OIS::KC_UNASSIGNED; + return 0; } -void Document::installShortkey(OIS::KeyCode key,ShortkeyDestination dest) +void Document::installShortkey(KeyCode key,ShortkeyDestination dest) { // Taste auf die das Ereignis bisher gemappt war - OIS::KeyCode oldkey = getMappedKey(dest); + KeyCode oldkey = getMappedKey(dest); // entfernen - if (oldkey != OIS::KC_UNASSIGNED) + if (oldkey != 0) { m_shortkey_map.erase(oldkey); } @@ -374,8 +348,6 @@ void Document::onButtonSaveExitClicked ( ) { - m_save_timer=0; - if (m_state!=SHUTDOWN_REQUEST) { setState(SHUTDOWN_REQUEST); @@ -407,21 +379,21 @@ { ClientCommand command; - - ClientWObject* cwo; - map<int,ClientWObject*>::iterator iter; + // der lokale Spieler + Player* pl = static_cast<Player*> (m_world->getLocalPlayer()); + if (pl==0) + return; + // herstellen der Koordinaten im Koordinatensystem des Spiels - x += m_main_player->getGeometry()->m_shape.m_coordinate_x; - y += m_main_player->getGeometry()->m_shape.m_coordinate_y; - m_gui_state. m_clicked_x =x; - m_gui_state. m_clicked_y =y; + m_gui_state.m_clicked_x =x; + m_gui_state.m_clicked_y =y; // Paket mit Daten fuellen command.m_button=RIGHT_MOUSE_BUTTON; command.m_coordinate_x=x; command.m_coordinate_y=y; - command.m_action = m_right_action; + command.m_action = pl->getRightAction(); m_gui_state.m_left_mouse_hold=false; m_gui_state.m_right_mouse_hold_time=0; @@ -430,11 +402,12 @@ m_gui_state.m_clicked_object_id=0; command.m_id=0; - lock(); + int id = getObjectAt(x,y); + m_gui_state.m_clicked_object_id = id; command.m_id =id; - unlock(); + command.m_number=0; if (command.m_id!=0) @@ -442,10 +415,7 @@ // Paket an den Server senden - sendCommand(&command); - - - + sendCommand(&command); } @@ -454,13 +424,13 @@ ClientCommand command; - - ClientWObject* cwo; - map<int,ClientWObject*>::iterator iter; + // der lokale Spieler + Player* pl = static_cast<Player*> (m_world->getLocalPlayer()); + if (pl==0) + return; // herstellen der Koordinaten im Koordinatensystem des Spiels - x += m_main_player->getGeometry()->m_shape.m_coordinate_x; - y += m_main_player->getGeometry()->m_shape.m_coordinate_y; + m_gui_state. m_clicked_x =x; m_gui_state. m_clicked_y =y; @@ -472,7 +442,7 @@ } command.m_coordinate_x=x; command.m_coordinate_y=y; - command.m_action = m_left_action; + command.m_action = pl->getLeftAction(); m_gui_state.m_right_mouse_hold=false; m_gui_state.m_left_mouse_hold_time=0; @@ -481,17 +451,15 @@ DEBUG4("angeklickte Koordinaten: %f %f",x,y); //TODO: suchen welches objekt angeklickt wurde - map<int,ClientWObject*>::iterator i; - ClientWObject* wo =0; + m_gui_state.m_clicked_object_id=0; command.m_id=0; - Shape* s=0; - float sx,sy; - lock(); + + int id = getObjectAt(x,y); + m_gui_state.m_clicked_object_id = id; command.m_id =id; - unlock(); command.m_number=0; if (command.m_id!=0) @@ -514,45 +482,21 @@ int Document::getObjectAt(float x,float y) { - if (m_gui_type == GL_GUI) - { - map<int,ClientWObject*>::iterator i; - ClientWObject* wo =0; - Shape* s=0; - float sx,sy; - - for (i=m_objects_bintree->begin();i!=m_objects_bintree->end();++i) - { - wo = i->second; - s = &(wo->getGeometry()->m_shape); - sx = s->m_coordinate_x; - sy = s->m_coordinate_y; - - if (s->m_type == Shape::CIRCLE) - { - if ((sx-x)*(sx-x) + (sy-y)*(sy-y) < s->m_radius*s->m_radius) - { - return wo->getId(); - } - } - else - { - float ex = s->m_extent_x; - float ey = s->m_extent_y; - - if (x>=sx -ex && x<=sx +ex && y>=sy -ey && y<=sy +ey) - { - return wo->getId(); - } - } - - } + // der lokale Spieler + ServerWObject* pl = m_world->getLocalPlayer(); + if (pl==0) return 0; - } - else - { - return m_gui_state.m_cursor_object_id; - } + + // Region in der sich der lokale Spieler befindet + Region* reg = pl->getRegion(); + if (reg ==0) + return 0; + + ServerWObject* obj = reg->getSWObjectAt(x,y); + if (obj != 0) + return obj->getId(); + + return 0; } @@ -569,9 +513,15 @@ { ClientCommand command; command.m_button = BUTTON_PARTY_ACCEPT; - if (m_party->getNrCandidates() > cnr) + + // Party in der der Spieler Mitglied ist + Party* party = getParty(); + if (party ==0) + return; + + if (party->getNrCandidates() > cnr) { - command.m_id = m_party->getCandidates()[cnr]; + command.m_id = party->getCandidates()[cnr]; sendCommand(&command); } } @@ -594,6 +544,7 @@ } +/* void Document::requestItemDetailedInfo( short pos) { ClientCommand command; @@ -609,6 +560,7 @@ command.m_id = abl; sendCommand(&command); } +*/ void Document::increaseAttribute(CreatureBaseAttr::Attribute attr) { @@ -649,9 +601,14 @@ { getGUIState()->m_shown_windows &= ~INVENTORY; + + // der lokale Spieler + Player* pl = static_cast<Player*>( m_world->getLocalPlayer()); + if (pl==0) + return; // Item das aktuell in der Hand ist fallen lassen - if (getMainPlayer()->m_equipement->getItem(Equipement::CURSOR_ITEM)!=0) + if (pl->getEquipement()->getItem(Equipement::CURSOR_ITEM)!=0) { dropCursorItem(); } @@ -660,7 +617,7 @@ { // wenn Inventar geoeffnet wird, dann Skilltree schliessen getGUIState()->m_shown_windows &= ~SKILLTREE; - m_gui_state.m_pressed_key = OIS::KC_UNASSIGNED; + m_gui_state.m_pressed_key = 0; getGUIState()->m_shown_windows |= INVENTORY; @@ -704,7 +661,7 @@ getGUIState()->m_shown_windows |= SKILLTREE; } - m_gui_state.m_pressed_key = OIS::KC_UNASSIGNED; + m_gui_state.m_pressed_key = 0; // Geoeffnete Fenster haben sich geaendert m_modified |= WINDOWS_MODIFIED; @@ -735,21 +692,26 @@ void Document::setLeftAction(Action::ActionType act) { - if (m_gui_state.m_pressed_key != OIS::KC_UNASSIGNED) + if (m_gui_state.m_pressed_key != 0) { // Im Skilltree wird Kurztaste ausgewaehlt installShortkey(m_gui_state.m_pressed_key,(ShortkeyDestination) (USE_SKILL_LEFT+act)); return; } + + // wenn kein Spieler gesetzt ist, dann keine Faehigkeit setzen - if (m_main_player ==0) + // der lokale Spieler + Player* player = static_cast<Player*>(m_world->getLocalPlayer()); + if (player==0) return; + int acti = (int) act; Action::ActionInfo* aci = Action::getActionInfo(act); // Testen ob die Faehigkeit zur Verfuegung steht - if (!m_main_player->checkAbility(act)) + if (!player->checkAbility(act)) { // Faehigkeit steht nicht zur Verfuegung, abbrechen return; @@ -765,8 +727,6 @@ DEBUG("Setting Action %i",act); m_gui_state.m_left_mouse_hold = false; - m_left_action = act; - ClientCommand command; @@ -777,7 +737,7 @@ void Document::setRightAction(Action::ActionType act) { - if (m_gui_state.m_pressed_key != OIS::KC_UNASSIGNED) + if (m_gui_state.m_pressed_key != 0) { // Im Skilltree wird Kurztaste ausgewaehlt installShortkey(m_gui_state.m_pressed_key,(ShortkeyDestination) (USE_SKILL_RIGHT+act)); @@ -786,14 +746,16 @@ } // wenn kein Spieler gesetzt ist, dann keine Faehigkeit setzen - if (m_main_player ==0) + // der lokale Spieler + Player* player = static_cast<Player*>(m_world->getLocalPlayer()); + if (player==0) return; - + int acti = (int) act; Action::ActionInfo* aci = Action::getActionInfo(act); // Testen ob die Faehigkeit zur Verfuegung steht - if (!m_main_player->checkAbility(act)) + if (!player->checkAbility(act)) { // Faehigkeit steht nicht zur Verfuegung, abbrechen return; @@ -806,7 +768,6 @@ DEBUG("Setting Action %i",act); m_gui_state.m_right_mouse_hold = false; - m_right_action = act; ClientCommand command; command.m_button = BUTTON_SET_RIGHT_ACTION; @@ -814,28 +775,31 @@ sendCommand(&command); } -std::string Document::getAbilityDescription() +std::string Document::getAbilityDescription(Action::ActionType ability) { ostringstream out_stream; out_stream.str(""); - if (m_main_player !=0 && m_ability_pos != Action::NOACTION) + // der lokale Spieler + Player* player = static_cast<Player*>(m_world->getLocalPlayer()); + + if (player !=0 ) { // Struktur mit Informationen zur Aktion - Action::ActionInfo* aci = Action::getActionInfo(m_ability_pos); + Action::ActionInfo* aci = Action::getActionInfo(ability); // Name der Faehigkeit - out_stream << Action::getName(m_ability_pos); + out_stream << Action::getName(ability); // out_stream << Action::getName(m_ability_pos); // Beschreibung //out_stream << "\n" << "Beschreibung: bla blubb"; - out_stream << "\n" << gettext("doc_description") << Action::getDescription(m_ability_pos); + out_stream << "\n" << gettext("doc_description") << Action::getDescription(ability); // Gibt an, ob der Spieler die Faehigkeit besitzt bool avlb = true; - short ac = m_ability_pos; - if ((m_main_player->m_abilities[ac/32] & (1 << (ac %32))) ==0) + short ac = ability; + if (!player->checkAbility(ability)) { // Spieler besitzt Faehigkeit nicht avlb = false; @@ -852,7 +816,9 @@ } // Schaden - std::string dmgstring = m_ability_damage.getDamageString(Damage::ABILITY); + Damage dmg; + player->calcDamage(ability,dmg); + std::string dmgstring = dmg.getDamageString(Damage::ABILITY); if (dmgstring !="") { out_stream << "\n" << dmgstring; @@ -863,23 +829,9 @@ return out_stream.str(); } -bool Document::onKeyPress(OIS::KeyCode key) +bool Document::onKeyPress(KeyCode key) { - if (key == OIS::KC_ESCAPE) - { - if (m_gui_state.m_shown_windows == NO_WINDOWS) - { - onButtonSaveExitClicked(); - } - else - { - m_gui_state.m_shown_windows = NO_WINDOWS; - // Geoeffnete Fenster haben sich geaendert - m_modified |= WINDOWS_MODIFIED; - } - } - if (m_gui_state.m_shown_windows & SKILLTREE) { // Skilltree wird angezeigt @@ -900,7 +852,7 @@ } - map<OIS::KeyCode, ShortkeyDestination>::iterator it = m_shortkey_map.find(key); + map<KeyCode, ShortkeyDestination>::iterator it = m_shortkey_map.find(key); if (it == m_shortkey_map.end()) { @@ -947,6 +899,19 @@ { emitDebugSignal(3); } + else if (dest == CLOSE_ALL) + { + if (m_gui_state.m_shown_windows == NO_WINDOWS) + { + onButtonSaveExitClicked(); + } + else + { + m_gui_state.m_shown_windows = NO_WINDOWS; + // Geoeffnete Fenster haben sich geaendert + m_modified |= WINDOWS_MODIFIED; + } + } else { return false; @@ -957,11 +922,11 @@ } } -bool Document::onKeyRelease(OIS::KeyCode key) +bool Document::onKeyRelease(KeyCode key) { - if (m_gui_state.m_pressed_key != OIS::KC_UNASSIGNED) + if (m_gui_state.m_pressed_key != 0) { - m_gui_state.m_pressed_key = OIS::KC_UNASSIGNED; + m_gui_state.m_pressed_key = 0; } } @@ -974,28 +939,22 @@ case INACTIVE: break; - case CONNECT_REQUEST: - serverConnect(); + case START_GAME: + startGame(m_server); break; - case CONNECTING: - if (m_network_info.m_network->getSlotStatus() == NET_CONNECTED) + case LOAD_SAVEGAME: + if (m_server || m_world->getNetwork()->getSlotStatus() == NET_CONNECTED) { - sendSavegame(); + loadSavegame(); } - case CONNECTED: + case RUNNING: updateContent(time); break; case SHUTDOWN_REQUEST: updateContent(time); - m_save_timer += time; - if (m_save_timer >3000) - { - ERRORMSG("no savegame received, shutdown"); - m_state = SHUTDOWN; - } break; case SHUTDOWN_WRITE_SAVEGAME: @@ -1005,9 +964,11 @@ pthread_create(&thread,0,&Document::writeSaveFile,this); pthread_join(thread, &ret); - // Verbindung zum Server schliessen - m_network_info.m_network->serverDisconnect(); - m_network_info.m_network->kill(); + // Spielwelt abschalten + delete m_world; + m_world =0; + + m_state = SHUTDOWN; break; @@ -1021,6 +982,13 @@ { DEBUG5("update content"); + Player* player = static_cast<Player*>(m_world->getLocalPlayer()); + if (player==0) + { + DEBUG5("no local player"); + return; + } + if (m_gui_state.m_left_mouse_hold) { DEBUG5("linke Maustaste festgehalten"); @@ -1037,7 +1005,7 @@ command.m_coordinate_x=m_gui_state.m_clicked_x; command.m_coordinate_y=m_gui_state.m_clicked_y; command.m_id = m_gui_state.m_clicked_object_id; - command.m_action = m_left_action; + command.m_action = player->getLeftAction(); command.m_number=0; m_gui_state.m_left_mouse_hold_time=0; @@ -1059,7 +1027,7 @@ command.m_coordinate_x=m_gui_state.m_clicked_x; command.m_coordinate_y=m_gui_state.m_clicked_y; command.m_id = m_gui_state.m_clicked_object_id; - command.m_action = m_right_action; + command.m_action = player->getRightAction(); command.m_number=0; m_gui_state.m_right_mouse_hold_time=0; @@ -1068,7 +1036,11 @@ } } - + + // Welt eine Zeitscheibe weiter laufen lassen + m_world->update(time); + + /* ServerHeader headerp; Packet* data=0; @@ -1149,12 +1121,15 @@ } DEBUG5("update finished"); + */ } + +/* void Document::handleDataPkg(CharConv* cv, ServerHeader* headerp) { //DEBUG("read bits: %i bytes",cv->getBitStream()->GetReadOffset()); - + /* map<int, ClientWObject*>::iterator iter; ClientWObject* cwo=0; map<int,Projectile*>::iterator it; @@ -1277,28 +1252,7 @@ unlock(); } - else - { - /* - int i; - short len =cv->fromBuffer<short>(datap); - int count = 0; - string::size_type position = 0; - while (count < 3 && m_gui_state.m_chat_window_content.find('\n', position) != string::npos) - { - position = m_gui_state.m_chat_window_content.find('\n', position+1); - count++; - DEBUG5("Count: %i", count); - DEBUG5("Pos: %i", position); - } - if (count >= 3) - { - position = m_gui_state.m_chat_window_content.find('\n', 0); - m_gui_state.m_chat_window_content.erase(0, position+1); - } - m_gui_state.m_chat_window_content = m_gui_state.m_chat_window_content + '\n' + datap; - */ - } + DEBUG5("objects modified"); m_modified |= OBJECTS_MODIFIED; @@ -1425,6 +1379,7 @@ m_modified |= REGION_MODIFIED; } +*/ void* Document::writeSaveFile(void* doc_ptr) { @@ -1458,3 +1413,6 @@ return 0; } + + +
--- a/src/core/document.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/document.h Fri Sep 19 11:03:22 2008 +0000 @@ -54,12 +54,8 @@ */ #include "networkstruct.h" -#include "constants.h" #include "projectile.h" #include "party.h" -#include "clientwobject.h" -#include "clientmplayer.h" -#include "clientnetwork.h" #include "debug.h" #include "damage.h" #include "itemlist.h" @@ -68,6 +64,9 @@ #include "matrix2d.h" #include "tiles.h" #include "dropitem.h" +#include "world.h" +#include "player.h" +#include "timer.h" #include <pthread.h> #include "gettext.h" @@ -79,7 +78,7 @@ * */ -#typedef int KeyCode +typedef int KeyCode; class Document { @@ -98,11 +97,11 @@ { INACTIVE =0, - CONNECT_REQUEST =1, + START_GAME =1, - CONNECTING =2, + LOAD_SAVEGAME =2, - CONNECTED =3, + RUNNING =3, SHUTDOWN_REQUEST =4, @@ -170,54 +169,13 @@ SHOW_SKILLTREE =3, SHOW_PARTYMENU=4, SHOW_CHATBOX =5, + CLOSE_ALL=9, SWAP_EQUIP=10, USE_POTION = 30, USE_SKILL_LEFT=100, USE_SKILL_RIGHT=300, }; - /** - * \struct NetworkInfo - * \brief Struktur fuer die Daten zum Netzwerk auf Clientseite - */ - struct NetworkInfo - { - /** - * \var m_network_error - * \brief false, wenn ein Netzwerkfehler aufgetreten ist - */ - bool m_network_error; - - /** - * \var m_server_ip[16] - * \brief Speichert die IP des Servers - */ - char m_server_ip[16]; - - /** - * \var m_network_slot - * \brief Speichert den verwendeten Netzwerk-Slot - */ - int m_network_slot; - - /** - * \var ClientNetwork* m_network - * \brief Objekt für die Netzwerkanbindung des Clients - */ - ClientNetwork* m_network; - - /** - * \var int m_timeout_counter - * \brief Zaehler fuer Timeouts - */ - int m_timeout_counter; - - /** - * \var bool m_host - * \brief Gibt an, ob der eigene Rechner der Host ist - */ - bool m_host; - }; /** @@ -374,16 +332,7 @@ */ static void* writeSaveFile(void* doc_ptr); - /** - * \fn NetworkInfo* getNetworkInfo() - * \brief Gibt Zeiger auf die Netzwerkinformationen zurueck - * return Netzwerkinformation - */ - NetworkInfo* getNetworkInfo() - { - return &m_network_info; - } - + /** * \fn GUISTate* getGUIState() * \brief Gibt Zustand der GUI Datenfelder zurueck @@ -433,25 +382,8 @@ m_modified = mod; } - /** - * \fn map<int, ServerWObject*>* getModifiedObjects() - * \brief Gibt Datenstruktur mit allen modifizierten Objekten aus - * \return Objekte - */ - map<int, ServerWObject*>* getModifiedObjects() - { - return m_modified_objects; - } - - /** - * \fn list<Projectile>* getProjectiles() - * \brief Gibt die Liste mit den Geschossen aus - * \return Liste der Geschosse - */ - map<int,Projectile*>* getProjectiles() - { - return m_projectiles; - } + + @@ -460,40 +392,30 @@ * \fn ServerItem* getDetailedItem() * \brief Gibt Zeiger auf das Item, das aktuell per Tooltip genauer angezeigt wird zurueck */ - ServerItem* getDetailedItem() - { - return m_detailed_item; - } + //ServerItem* getDetailedItem(); /** * \fn ServerItem* getDetailedItem() * \brief Gibt Position des Items, das aktuell per Tooltip genauer angezeigt wird zurueck */ - short getDetailedItemPos() + /*short getDetailedItemPos() { - return m_detailed_item_pos; + return 0; } - +*/ /** * \fn Action::ActionType getAbilityPos() * \brief Gibt die Position der Aktion die gerade als Tooltip angezeigt zurueck */ + /* Action::ActionType getAbilityPos() { - return m_ability_pos; + return Action::NOACTION; } + */ - /** - * \fn ClientMPlayer* getMainPlayer() - * \brief Gibt Zeiger auf die Spielerfigur zurueck - * \return Spielerobjekt - */ - ClientMPlayer* getMainPlayer() - { - return m_main_player; - } /** * \fn Party* getParty() @@ -502,7 +424,7 @@ */ Party* getParty() { - return m_party; + return 0; } /** @@ -516,10 +438,12 @@ * \fn Action::ActionType getLeftAction() * \brief Gibt die Aktion, die durch die linke Maustaste ausgeloest wird, zurueck */ + /* Action::ActionType getLeftAction() { return m_left_action; } + */ /** * \fn void setRightAction(Action::ActionType a) @@ -532,26 +456,38 @@ * \fn Action::ActionType getRightAction() * \brief Gibt die Aktion, die durch die rechte Maustaste ausgeloest wird, zurueck */ + /* Action::ActionType getRightAction() { return m_right_action; } + */ /** * \fn map<int,DropItem>* getDropItems() * \brief Gibt die Liste aller fuer den Spieler sichtbaren Gegenstaende am Boden zurueck */ + /* map<int,DropItem>* getDropItems() { return m_drop_items; } - +*/ + + /** + /* \fn void setServer(bool server) + * \brief Stellt ein ob das Spiel der Server ist + */ + void setServer(bool server) + { + m_server = server; + } /** - * \fn std:.string getAbilityDescription() + * \fn std:.string getAbilityDescription(Action::ActionType ability) * \brief Gibt die Beschreibung der Faehigkeit, ueber der Mauszeiger ist, aus */ - std::string getAbilityDescription(); + std::string getAbilityDescription(Action::ActionType ability); /** * \fn KeyCode getMappedKey(ShortkeyDestination sd) @@ -662,13 +598,13 @@ * \fn void requestItemDetailedInfo( short pos) * \brief Fordert vom Server weitere Informationen zu einem Item an */ - void requestItemDetailedInfo( short pos); + //void requestItemDetailedInfo( short pos); /** * \fn void requestAbilityDamage(Action::ActionType abl) * \brief Fordert vom Server den Schaden einer Faehigkeit an */ - void requestAbilityDamage(Action::ActionType abl); + //void requestAbilityDamage(Action::ActionType abl); /** * \fn void increaseAttribute(CreatureBaseAttr::Attribute attr) @@ -708,16 +644,37 @@ void emitDebugSignal(int i=0); /** - * \fn void update( ) + * \fn void update( float time=0) * \brief Aktualisiert den Inhalt der GUI, holt alle Daten neu vom Netzwerk */ void update(float time=0); /** - * \fn void serverConnect() + * \fn void startGame(bool server) * \brief Baut Verbindung zum Server auf */ - void serverConnect(); + void startGame(bool server); + + /** + * \fn Player* getLocalPlayer() + * \brief Gibt den Spieler aus, der lokal an dem Rechner ist + */ + Player* getLocalPlayer() + { + if (m_world ==0) + return 0; + + return static_cast<Player*>(m_world->getLocalPlayer()); + } + + /** + * \fn World* getWorld() + * \brief gibt Zeiger auf die Spielwelt aus + */ + World* getWorld() + { + return m_world; + } // Private stuff @@ -732,10 +689,10 @@ void sendCommand(ClientCommand* comm); /** - * \fn void sendSavegame() - * \brief Sendet ein Savegame zum Server + * \fn void loadSavegame() + * \brief laedt ein Savegame */ - void sendSavegame(); + void loadSavegame(); /** * \fn void updateContent(float time) @@ -749,7 +706,7 @@ * \param headerp Zeiger auf den Header des Datenpaketes * \brief Behandlung von Datenpaketen */ - void handleDataPkg(CharConv* cv,ServerHeader* headerp); + //void handleDataPkg(CharConv* cv,ServerHeader* headerp); /** @@ -757,28 +714,28 @@ * \brief Behandlung von Savegamepaketen * \param datap Zeiger auf die Daten */ - void handleSavegame(CharConv* cv); + //void handleSavegame(CharConv* cv); /** * \fn void handleDetailedItem(CharConv* cv) * \brief Behandlung von Informationen zu einem Item * \param datap Zeiger auf die Daten */ - void handleDetailedItem(CharConv* cv); + //void handleDetailedItem(CharConv* cv); /** * \fn void handleRegionData(CharConv* cv) * \brief Behandlung der Daten einer Region */ - void handleRegionData(CharConv* cv); + //void handleRegionData(CharConv* cv); - /** + /** * \fn void handleDatapkg(CharConv* cv) - * \param datap Zeiger auf das Datenpaket - * \param headerp Zeiger auf den Header des Datenpaketes - * \brief Behandlung von informationen zum Schaden einer Aktion - */ - void handleAbilityDamage(CharConv* cv, ServerHeader* headerp); + * \param datap Zeiger auf das Datenpaket + * \param headerp Zeiger auf den Header des Datenpaketes + * \brief Behandlung von informationen zum Schaden einer Aktion + */ + //void handleAbilityDamage(CharConv* cv, ServerHeader* headerp); /** * \fn int getObjectAt(float x,float y) @@ -787,10 +744,8 @@ */ int getObjectAt(float x,float y); - /** \var NetworkInfo m_network_info - * \brief Enthaelt Daten zum Netzwerk - */ - NetworkInfo m_network_info; + + /** * \var GUIState m_gui_state @@ -800,90 +755,6 @@ /** - * \var m_modified_objects - * \brief Speichert die an den Client übertragenen Objekte in einem Binärbaum - */ - map<int, ServerWObject*>* m_modified_objects; - - /** - * \var list<int> m_removed_objects - * \brief Liste mit den IDs geloeschter Objekte - */ - list<int> m_removed_objects; - - /** - * \var list<int> m_removed_projectiles - * \brief Liste mit den IDs geloeschter Objekte Projektile - */ - list<int> m_removed_projectiles; - - /** - * \var RegionData m_region_data - * \brief Statische Daten zur aktuellen Region - */ - RegionData m_region_data; - - /** - * \var m_main_player - * \brief Zeiger auf das Spielerobjekt das der Nutzer kontrolliert - */ - ClientMPlayer* m_main_player; - - /** - * \var Party* m_party - * \brief Zeiger auf die Party der der Spieler angehoert - */ - Party* m_party; - - /** - * \var Action::ActionType m_left_action - * \brief Aktion die auf linke Maustaste ausgefuehrt wird - */ - Action::ActionType m_left_action; - - /** - * \var Action::ActionType m_right_action - * \brief Aktion die auf rechte Maustaste ausgefuehrt wird - */ - Action::ActionType m_right_action; - - /** - * \var map<int,Projectile*> m_projectiles - * \brief Liste der Projektil - */ - map<int,Projectile*>* m_projectiles; - - /** - * \var map<int,DropItem>* m_drop_items; - * \brief Liste der Items am Boden - */ - map<int,DropItem>* m_drop_items; - - /** - * \var ServerItem* m_detailed_item - * \brief Item mit detaillierten Informationen - */ - ServerItem* m_detailed_item; - - /** - * \var short m_detailed_item_pos - * \brief Position des Items mit detaillierten Informationen - */ - short m_detailed_item_pos; - - /** - * \var Damage m_ability_damage - * \brief Schaden der Faehigkeit auf die der Mauszeiger zeigt - */ - Damage m_ability_damage; - - /** - * \var short m_ability_pos - * \brief Faehigkeit auf die der Mauszeiger zeigt - */ - Action::ActionType m_ability_pos; - - /** * \var m_data_locks * \brief Gibt die Anzahl der Locks auf den Daten des Dokuments an. Die Daten koennen nur veraendert und von aussen gelesen werden, wenn die Anzahl gleich 0 ist */ @@ -927,12 +798,26 @@ set<KeyCode> m_special_keys; + + char m_server_ip[16]; + /** - * \var float m_save_timer - * \brief Timer, der der die Zeit zaehlt, die auf ein Savegame gewartet wird + * \var World* m_world + * \brief Welt die von dem Spiel simuliert wird */ - float m_save_timer; - + World* m_world; + + /** + * \var bool m_server + * \brief true, wenn der aktuelle Rechner der Server ist + */ + bool m_server; + + /** + * \var Timer m_timer + * \brief Timer fuer die Updatezyklen der Spielwelt + */ + Timer m_timer; };
--- a/src/core/dropslot.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/dropslot.h Fri Sep 19 11:03:22 2008 +0000 @@ -1,6 +1,8 @@ #ifndef DROPSLOT_H #define DROPSLOT_H +#include "item.h" + /** * \struct DropSlot * \brief charakterisiert ein Item, das ein Monster droppen kann
--- a/src/core/itemfactory.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/itemfactory.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -607,6 +607,8 @@ list<ItemBasicData*>* item_list; item_list = itemloader->loadItemBasicData("../../data/items.xml"); + // Debugging: Anzeigen der geladenen Items + /* if (item_list != 0) { list<ItemBasicData*>::iterator iter = item_list->begin(); @@ -642,7 +644,7 @@ *iter++; } } - + */ list<DropChanceData*>* drop_chance_list; drop_chance_list = itemloader->loadDropChanceData("../../data/items.xml");
--- a/src/core/itemloader.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/itemloader.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -203,7 +203,7 @@ { m_item_list->push_back(m_item_data); m_item_data = 0; - DEBUG("Item loaded"); + DEBUG5("Item loaded"); } } } @@ -235,9 +235,9 @@ if (loadOkay) { - DEBUG("Loading %s", pFilename); + DEBUG5("Loading %s", pFilename); searchItemBasicData(&doc); - DEBUG("Loading %s finished", pFilename); + DEBUG5("Loading %s finished", pFilename); return m_item_list; } else @@ -367,7 +367,7 @@ { m_drop_chance_data_list->push_back(m_drop_chance_data); m_drop_chance_data = 0; - DEBUG("DropChance loaded"); + DEBUG5("DropChance loaded"); } } } @@ -383,9 +383,9 @@ if (loadOkay) { - DEBUG("Loading %s", pFilename); + DEBUG5("Loading %s", pFilename); searchDropChanceData(&doc); - DEBUG("Loading %s finished", pFilename); + DEBUG5("Loading %s finished", pFilename); return m_drop_chance_data_list; } else
--- a/src/core/network.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/network.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -7,7 +7,7 @@ SocketDescriptor sock; m_peer->Startup(1,10,&sock, 1); - m_server_address = UNASSIGNED_SYSTEM_ADDRESS; + }
--- a/src/core/network.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/network.h Fri Sep 19 11:03:22 2008 +0000 @@ -7,6 +7,7 @@ #include "raknet/RakPeerInterface.h" #include "raknet/RakNetTypes.h" #include "raknet/BitStream.h" +#include "debug.h" #define REQ_PORT 5331 @@ -48,7 +49,8 @@ */ virtual NetStatus init( int auth_port=REQ_PORT ) { - + DEBUG("test"); + return NET_OK; }; /**
--- a/src/core/objectfactory.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/objectfactory.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -17,7 +17,7 @@ void ObjectFactory::registerMonster(WorldObject::TypeInfo::ObjectSubtype subtype, MonsterBasicData* data) { - DEBUG("registered monster for subtype %s",subtype.c_str()); + DEBUG5("registered monster for subtype %s",subtype.c_str()); m_monster_data.insert(make_pair(subtype,data)); } @@ -264,7 +264,7 @@ { WorldObject::Geometry* wob; Shape* sp; - DEBUG("create fixed object: %s",subtype.c_str()); + DEBUG5("create fixed object: %s",subtype.c_str()); ret = new FixedObject(m_world,id,subtype); wob=ret->getGeometry();
--- a/src/core/objectloader.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/objectloader.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -283,7 +283,7 @@ //registerMonster(WorldObject::TypeInfo::SUBTYPE_GOBLIN, m_monster_data); FIXME m_monster_list->push_back(m_monster_data); m_monster_data = 0; - DEBUG("Object loaded"); + DEBUG5("Object loaded"); } } } @@ -310,9 +310,9 @@ if (loadOkay) { - DEBUG("Loading %s", pFilename); + DEBUG5("Loading %s", pFilename); searchXml(&doc); - DEBUG("Loading %s finished", pFilename); + DEBUG5("Loading %s finished", pFilename); return m_monster_list; } else
--- a/src/core/player.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/player.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -49,7 +49,7 @@ bool Player::init() { - DEBUG("Player::init"); + DEBUG5("Player::init"); //eigene Initialisierung m_network_slot=-1; m_package_number =0; @@ -322,6 +322,8 @@ } } } + + DEBUG5("resulting command %i goal %f %f id %i",com->m_type,com->m_goal_coordinate_x,com->m_goal_coordinate_y, com->m_goal_object_id); } @@ -891,6 +893,8 @@ //return true; Trade* trade = 0; + + /* // handle inputs form network ServerNetwork* net = getWorld()->getNetwork(); if( net->getSlotStatus( m_network_slot )!=NET_CONNECTED ) @@ -949,10 +953,10 @@ comp.fromString(cv); DEBUG5("Kommando (%f %f) %i %i",comp.m_coordinate_x,comp.m_coordinate_y,comp.m_button, comp.m_id); - /*for (char* c =(char*) comp; c< sizeof(ClientCommand) + (char*) comp; c++) - printf("%02x",*c); - printf("\n"); - */ + //for (char* c =(char*) comp; c< sizeof(ClientCommand) + (char*) comp; c++) + // printf("%02x",*c); + //printf("\n"); + onClientCommand( &comp ); } @@ -962,11 +966,8 @@ if( headerp.m_content == PTYPE_C2S_DATA && headerp.m_chatmessage ) { DEBUG("Chatmessage erhalten"); - /*for (int i=0;i<len;i++) - printf("%c",data[i]); - printf("\n"); - */ - /* + + char* msgp = data + sizeof(ClientHeader); int len = sizeof(PackageHeader)+sizeof(Chatmessage); char sendmsg[len]; @@ -1017,14 +1018,14 @@ } } DEBUG3("Senden abgeschlossen"); - */ + } delete cv; net->deallocatePacket(data); } - +*/ // Behandlung des Handels if (getTradeId() !=0) @@ -1122,6 +1123,7 @@ net->pushSlotMessage( m_network_slot,tmp,len); */ + /* sendGameData(); @@ -1133,7 +1135,7 @@ m_save_timer = 10000; sendSavegame(); } - +*/ return true; } @@ -1165,7 +1167,7 @@ void Player::sendGameData() { - + /* // handle inputs form network ServerNetwork* net = getWorld()->getNetwork(); @@ -1288,34 +1290,26 @@ } DEBUG5("anzahl gedroppter items %i",header.m_drop_items); -/* - int len = ch.getBitStream()->GetNumberOfBytesUsed(); - cv.backToStart(); - header.toString(&cv); - ch.getBitStream()-> -*/ + +// int len = ch.getBitStream()->GetNumberOfBytesUsed(); +// cv.backToStart(); +// header.toString(&cv); +// ch.getBitStream()-> + //DEBUG5("sending %i byte of data",len); //DEBUG5("objects %i projectiles %i",header.m_objects,header.m_projectiles); - /* - for (int j=0;buf+j< bp;j++) - { - cp = (unsigned char*) buf+j; - //if (i%10==8) - // printf("\n %p\n",cp); - - printf("%c%c ",hex(*cp/16),hex(*cp%16)); -} - printf("\n\n"); - */ + DEBUG5("sending %i bytes",cv.getBitStream()->GetNumberOfBytesUsed()); net->pushSlotMessage(m_network_slot, cv.getBitStream(),HIGH_PRIORITY, UNRELIABLE_SEQUENCED); + */ } void Player::sendDetailedItem(short pos) { + /* ServerItem* it = static_cast<ServerItem*>(m_equipement->getItem(pos)); if (it!=0) @@ -1335,11 +1329,13 @@ net->pushSlotMessage(m_network_slot, cv.getBitStream()); } + */ } void Player::sendAbilityDamage(Action::ActionType act) { + /* // Wertebereich fuer Aktionen pruefen if (act<0 || act >=192) return; @@ -1366,11 +1362,12 @@ dmg.toString(&cv); net->pushSlotMessage(m_network_slot, cv.getBitStream()); - + */ } void Player::sendSavegame() { + /* ServerNetwork* net = getWorld()->getNetwork(); int len; @@ -1383,7 +1380,7 @@ header.toString(&cv); toSavegame(&cv); net->pushSlotMessage(m_network_slot, cv.getBitStream()); - + */ }
--- a/src/core/player.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/player.h Fri Sep 19 11:03:22 2008 +0000 @@ -269,6 +269,63 @@ * \brief Gibt aus, ob die Aktion einhaendig oder zweihaendig ausgefuehrt wird */ virtual Action::ActionEquip getActionEquip(); + + /** + * \fn Action::ActionType getRightAction() + */ + Action::ActionType getRightAction() + { + return m_right_action; + } + + /** + * \fn Action::ActionType getLeftAction() + */ + Action::ActionType getLeftAction() + { + return m_left_action; + } + + /** + * \fn short getAttributePoints() + */ + short getAttributePoints() + { + return m_attribute_points; + } + + /** + * \fn short getSkillPoints() + */ + short getSkillPoints() + { + return m_skill_points; + } + + /** + * \fn Damage& getBaseDamage() + */ + Damage& getBaseDamage() + { + return m_base_damage; + } + + /** + * \fn Damage& getLeftDamage() + */ + Damage& getLeftDamage() + { + return m_left_damage; + } + + /** + * \fn Damage& getRightDamage() + */ + Damage& getRightDamage() + { + return m_right_damage; + } + //Protected stuff protected:
--- a/src/core/region.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/region.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -19,7 +19,7 @@ m_players = new map<int,ServerWObject*>; // Baum fuer Projektile anlegen - m_projectiles = new list<DmgProjectile*>; + m_projectiles = new map<int,DmgProjectile*>; // Liste der Gegenstaende m_drop_items = new map<int,DropItem*>; @@ -40,10 +40,10 @@ delete i->second; } - list<DmgProjectile*>::iterator j; + map<int,DmgProjectile*>::iterator j; for (j = m_projectiles->begin(); j != m_projectiles->end(); j++) { - delete (*j); + delete (j->second); } @@ -509,12 +509,12 @@ void Region::getProjectilesOnScreen(float center_x,float center_y, list<DmgProjectile*>* result) { - list<DmgProjectile*>::iterator i; + map<int,DmgProjectile*>::iterator i; float dx,dy,r; DmgProjectile* pr; for (i=m_projectiles->begin();i!=m_projectiles->end();++i) { - pr = (*i); + pr = (i->second); r=pr->getGeometry()->m_radius; // Abstaende, in dem die Effekte von ihrem Zentrum entfernt sichtbar sind @@ -595,7 +595,7 @@ bool Region::insertProjectile(DmgProjectile* object, float x, float y) { - m_projectiles->push_back(object); + m_projectiles->insert(make_pair(object->getId(),object)); object->getGeometry()->m_coordinate_x = x; object->getGeometry()->m_coordinate_y = y; return true; @@ -717,34 +717,35 @@ DEBUG5("\nObjekt: %f %f key: %i layer %x",wob->m_shape.m_coordinate_x,wob->m_shape.m_coordinate_y ,object->getId(),object->getGeometry()->m_layer); if (object->getDestroyed()==true) { - ++iter; + DEBUG5("Objekt gelöscht: %i \n",object->getId()); object->destroy(); deleteSWObject(object); delete object; + m_objects->erase(iter++); continue; } else { // Polymorpher Funktionsaufruf object->update(time); + ++iter; } - ++iter; } DEBUG5("Update aller WeltObjekte abgeschlossen\n\n"); // alle Projektile updaten - list<DmgProjectile*>::iterator it3; + map<int,DmgProjectile*>::iterator it3; DmgProjectile* pr =0; for (it3 = m_projectiles->begin(); it3 !=m_projectiles->end();) { - pr = (*it3); + pr = (it3->second); if (pr->getState() == Projectile::DESTROYED) { DEBUG5("deleting projectile %p",pr); - it3 = m_projectiles->erase(it3); + m_projectiles->erase(it3++); delete pr; DEBUG5("loesche projektil");
--- a/src/core/region.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/region.h Fri Sep 19 11:03:22 2008 +0000 @@ -298,6 +298,11 @@ { return m_drop_items; } + + map<int,DmgProjectile*>* getProjectiles() + { + return m_projectiles; + } private: /** @@ -340,7 +345,7 @@ * \var map<int, DmgProjectile>* m_projectiles * \brief Liste aller Projektile in der Region */ - list<DmgProjectile*>* m_projectiles; + map<int,DmgProjectile*>* m_projectiles; /** * \var map<int,ServerWObject*>* m_object_bintree
--- a/src/core/server.cpp Wed Sep 17 11:01:52 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,398 +0,0 @@ -#include "server.h" - -Server::Server() - : m_logins() -{ - m_world =0; - m_network=0; - m_stop = false; -} - -Server::~Server() -{ -} - -void Server::init(int max_slots) -{ - ObjectFactory::init(); - - m_network = new ServerNetwork(max_slots); - if( m_network->init( REQ_PORT )!=NET_OK ) - { - ERRORMSG( "Error occured in network" ); - return ; - } - - long sec; - time(&sec); - srand(sec); - - m_world=new World(); - m_world->setNetwork(m_network); - - ObjectFactory::m_world = m_world; - - int gen_type=2 ; - - if (gen_type==1) - { - - } - else if(gen_type==2) - { - Region* reg = new Region(25,25); - short rid = m_world->insertRegion(reg); - - - - - // Objekte anlegen - ServerWObject* wo=0,*wo2=0; - Creature* cr =0; - CreatureBaseAttr* basm =0; - WorldObject::Geometry* wob=0; - Shape* sp=0; - Spawnpoint* spawn=0; - - // Tiles Setzen - for (int i=1;i<5;i++) - { - reg->setTile(TILE_GRASS,5,i); - } - - for (int i=7;i<10;i++) - { - reg->setTile(TILE_WATER,i,6); - } - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_FIXED_OBJECT, "fence"); - m_world->insertSWObject(wo, 4,6,rid); - - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_FIXED_OBJECT, "tree"); - m_world->insertSWObject(wo, 9,13,rid); - - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 13,8,rid); - - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "gob_dog"); - m_world->insertSWObject(wo, 14.2,8.2,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 14.5,6.7,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 14.8,5.7,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 14,10.9,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 17,8.2,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "lich"); - m_world->insertSWObject(wo, 7,5,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 18.5,7,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 17.2,6.6,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 19.9,6.9,rid); - -/* - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 16.2,3,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 19.2,3.1,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 6.5,6.4,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_MONSTER, "goblin"); - m_world->insertSWObject(wo, 8.5,6.4,rid); - */ -/* - - Spawnpoint::SpawnedMonsterGroup mg("goblin",1.0,1); - spawn = new Spawnpoint(m_world,1); - spawn->setRespawnTime(10000); - spawn->addMonsterGroup(mg); - m_world->insertSWObject(spawn,9,9,rid); -*/ -/* - int i,j; - for (i=1;i<48;i++) - { - for (int j=1;j<48;j++) - { - reg->setTile(TILE_GRASS,i,j); - } - } - - for (i=0;i<49;i++) - { - reg->setTile(TILE_WATER,i,0); - reg->setTile(TILE_WATER,i,49); - reg->setTile(TILE_WATER,49,i); - reg->setTile(TILE_WATER,0,i); - - } - - Spawnpoint::SpawnedMonsterGroup gob("goblin",0.6,6); - Spawnpoint::SpawnedMonsterGroup gob2("goblin",0.5,3); - Spawnpoint::SpawnedMonsterGroup lich("lich",0.7,1); - Spawnpoint::SpawnedMonsterGroup dog("gob_dog",0.4,4); - - spawn = new Spawnpoint(m_world,1); - spawn->setRespawnTime(100000); - spawn->addMonsterGroup(gob); - m_world->insertSWObject(spawn,9,9,rid); - - spawn = new Spawnpoint(m_world,2); - spawn->setRespawnTime(100000); - spawn->addMonsterGroup(gob); - m_world->insertSWObject(spawn,6,18,rid); - - spawn = new Spawnpoint(m_world,3); - spawn->setRespawnTime(100000); - spawn->addMonsterGroup(gob2); - spawn->addMonsterGroup(dog); - m_world->insertSWObject(spawn,22,14,rid); - - spawn = new Spawnpoint(m_world,4); - spawn->setRespawnTime(100000); - spawn->addMonsterGroup(gob); - spawn->addMonsterGroup(lich); - m_world->insertSWObject(spawn,16,25,rid); - - spawn = new Spawnpoint(m_world,5); - spawn->setRespawnTime(100000); - spawn->addMonsterGroup(gob2); - spawn->addMonsterGroup(lich); - spawn->addMonsterGroup(dog); - m_world->insertSWObject(spawn,30,27,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_FIXED_OBJECT, "tree"); - m_world->insertSWObject(wo, 24,26,rid); - - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_FIXED_OBJECT, "tree"); - m_world->insertSWObject(wo, 10,13,rid); - - wo = ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_FIXED_OBJECT, "tree"); - m_world->insertSWObject(wo, 20,18,rid); -*/ - - } - else if(gen_type==3) - { - - - //MapGenerator::createMap(m_world); - printf("World created\n"); - - } -} - -void Server::loop() -{ - float dt=0.f; - int i=0; - float s=0; - - Timer timer; - - while( !m_stop ) - { - DEBUG5("new_login_player"); - updateLogins(); - acceptLogins(); - - DEBUG5("update"); - timer.start(); - m_world->update( 25.f ); - dt = timer.getTime(); - s += dt; - if (dt >5) - { - DEBUG5("update zeit in ms: %f",dt); - } - i++; - if (i==100) - { - DEBUG5("durchschnittliche updatezeit is ms: %f",s/100); - s=0; - i=0; - } - - if( 25.f-dt>0.f ) - { -#ifdef WIN32 - Sleep( (int)(25.f-dt) ); -#else - usleep( (int)((25.f-dt)*1000) ); -#endif - } - else - { - //WARNING("server is too slow!"); - } - - // Debugging - //usleep( 1000000 ); - - DEBUG5("network->update()"); - for( int i=0 ; i<1 ; i++ ) - m_network->update(); - - } - - DEBUG("server thread end"); -} - -void Server::stop() -{ - m_stop = true; - m_network->kill(); - - pthread_join(m_server_thread,NULL); - - if( m_world ) - { - delete m_world; - } - - if (m_network) - { - - delete m_network; - } -} - -void Server::acceptLogins() -{ - int login_slot; - - while((login_slot=m_network->popNewLoginSlot()) != -1 ) - { - INFO( "user login detected: %i", login_slot ); - m_logins.push_back(login_slot); - - - } -} - -void Server::updateLogins() -{ - list<int>::iterator i; - Packet* data; - int lend; - ClientHeader header; - DEBUG5("update logins"); - for (i=m_logins.begin();i!=m_logins.end();) - { - DEBUG5("testing slot %i",(*i)); - if (m_network->numberSlotMessages((*i) )>0) - { - DEBUG5("got Package"); - m_network->popSlotMessage( (*i),data); - CharConv cv(data); - header.fromString(&cv); - if (header.m_content == PTYPE_C2S_SAVEGAME) - { - DEBUG("got savegame from slot %i",(*i)); - char binsave; - cv.fromBuffer<char>(binsave); - short version; - cv.fromBuffer<short>(version); - int len; - cv.fromBuffer<int>(len); - WorldObject::TypeInfo::ObjectSubtype ot; - char tmp[11]; - tmp[10] = '\0'; - cv.fromBuffer(tmp,10); - for (int u=0;u<10;u++) - printf("%i ",tmp[u]); - ot = tmp; - Player* pl =0; - - if (ot == "warrior") - { - DEBUG5("warrior"); - pl=new Warrior( m_world, m_world->getValidId() ); - } - else if (ot == "mage") - { - DEBUG5("mage"); - pl=new Mage( m_world, m_world->getValidId() ); - } - else if (ot == "archer") - { - DEBUG5("archer"); - pl=new Archer( m_world, m_world->getValidId() ); - } - else if (ot == "priest") - { - DEBUG5("priest"); - pl=new Priest( m_world, m_world->getValidId() ); - } - else - { - ERRORMSG("invalid savegame type: %s",ot.c_str()); - pl=new Warrior( m_world, m_world->getValidId() ); - } - - if (pl!=0) - { - DEBUG5("adress of players %p",pl); - //pl->fromSavegame(bp2); - pl->setNetworkSlot( (*i) ); - m_world->insertSWObject(pl,6,11,0); - pl->getDynAttr()->m_health=150; - - //pl->getDynAttr()->m_status_mod_time[Damage::CONFUSED] = 100000; - //pl->getDynAttr()->m_status_mod_time[Damage::BERSERK] = 100000; - - } - i = m_logins.erase(i); - } - else - { - DEBUG("unknown type %i",header.m_content); - } - m_network->deallocatePacket(data); - } - else - { - i++; - } - - } - DEBUG5("done"); - -} - -void* Server::startServer(void* arg) -{ - StartArgs* argp = (StartArgs*) arg; - - argp->m_server->loop(); -} - -void Server::run() -{ - StartArgs* arg = new StartArgs; - arg->m_server = this; - - pthread_create( &m_server_thread, NULL, &Server::startServer, arg ); -} - - - -
--- a/src/core/server.h Wed Sep 17 11:01:52 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -#ifndef SERVER_H -#define SERVER_H - -#include <unistd.h> -#include "debug.h" -#include "servernetwork.h" -#include <list> - - -#include "world.h" -//#include "mapgenerator.h" - -#include <sys/time.h> -#include <sys/types.h> -#include <unistd.h> -//#include <GL/gl.h> -//#include <GL/glut.h> - -// includes zum spaeter wieder rausnehmen... -#include "warrior.h" -#include "mage.h" -#include "archer.h" -#include "priest.h" -#include "fixedobject.h" -#include "monster.h" -#include "goblin.h" -#include "spawnpoint.h" - -#include "objectfactory.h" - -#include "timer.h" - -#ifdef WIN32 -#include <windows.h> -#endif - -#include <pthread.h> - -/** - * \class Server - * \brief Klasse fuer einen Spielserver - */ -class Server -{ - public: - - /** - * \struct StartArgs - * \brief Argumentliste fuer den Start des Serverthreads - */ - struct StartArgs - { - Server* m_server; - }; - - /** - * \fn Server() - * \brief Konstruktor - */ - Server(); - - /** - * \fn ~Server() - * \brief Destruktor - */ - ~Server(); - - /** - * \fn void init(int max_slots) - * \brief initialisiert den Server - */ - void init(int max_slots); - - /** - * \fn void run() - * \brief Startet den Server - */ - void run(); - - /** - * \fn void loop() - * \brief die Hauptspielschleife - */ - void loop(); - - /** - * \fn void stop() - * \brief Stoppt den Server - */ - void stop(); - - /** - * \fn void acceptLogins() - * \brief Fuegt Spieler die sich neu eingeloggt haben ins Spiel ein - */ - void acceptLogins(); - - /** - * \fn void updateLogins() - * \brief Aktualisiert die Liste der eingehenden Logins - */ - void updateLogins(); - - /** - * \fn static void* startServer(void* arg) - * \brief Startet den Server in einem eigenen Thread - */ - static void* startServer(void* arg); - - private: - /** - * \var bool m_stop - * \brief gibt an, ob der Server gestoppt werden soll - */ - bool m_stop; - - /** - * \var pthread_t m_server_thread - * \brief Thread Handel fuer den Thread des Servers - */ - pthread_t m_server_thread; - - /** - * \var World *m_world - * \brief Zeiger auf die Welt - */ - World *m_world; - - /** - * \var ServerNetwork * m_network - * \brief Zeiger auf das Netzwerk - */ - ServerNetwork * m_network; - - /** - * \var list<int> m_logins - * \brief Liste der Spieler die sich gerade einloggen wollen - */ - list<int> m_logins; -}; - - -#endif -
--- a/src/core/servernetwork.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/servernetwork.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -44,6 +44,8 @@ NetStatus ServerNetwork::init( int auth_port ) { + DEBUG("init servernetwork"); + m_peer = RakNetworkFactory::GetRakPeerInterface(); SocketDescriptor sock(auth_port,0);
--- a/src/core/servernetwork.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/servernetwork.h Fri Sep 19 11:03:22 2008 +0000 @@ -136,11 +136,6 @@ virtual NetStatus init( int auth_port=REQ_PORT ); - /** - * \fn NetStatus kill() - * \brief Schliesst den Server - */ - void kill(); /** * \fn NetStatus getSlotStatus( int slot=0 )
--- a/src/core/world.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/world.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -19,6 +19,7 @@ #include "world.h" +#include "player.h" /** * Constructors/Destructors @@ -28,9 +29,11 @@ */ World::World(bool server) { + m_server = server; + // diverse Initialisierungen - m_player_slots = new map<int,int>; + m_player_slots = new map<int,ServerWObject*>; // Baum fuer die Handelsvorgaenge anlegen m_trades = new map<int, Trade* >; @@ -48,9 +51,11 @@ for (int i=0;i<WORLD_MAX_REGIONS;i++) m_regions[i]=0; + m_local_player =0; } + bool World::init() { // Aktionen initialisieren @@ -64,26 +69,33 @@ if (m_server) { + DEBUG("server"); m_network = new ServerNetwork(m_max_nr_players); } else { + DEBUG("client"); m_network = new ClientNetwork(); } + long sec; + time(&sec); + srand(sec); + if( m_network->init( REQ_PORT )!=NET_OK ) { ERRORMSG( "Error occured in network" ); return false; } - long sec; - time(&sec); - srand(sec); + } -void World::generate(int type) + +void World::createRegion(short region) { + DEBUG5("creating region %i",region); + int type = 2; if (type==1) { @@ -91,7 +103,7 @@ else if(type==2) { Region* reg = new Region(25,25); - short rid = insertRegion(reg); + short rid = insertRegion(reg,region); @@ -253,6 +265,7 @@ } } + void World::updateLogins() { list<int>::iterator i; @@ -272,35 +285,7 @@ if (header.m_content == PTYPE_C2S_SAVEGAME) { DEBUG("got savegame from slot %i",(*i)); - char binsave; - cv.fromBuffer<char>(binsave); - short version; - cv.fromBuffer<short>(version); - int len; - cv.fromBuffer<int>(len); - WorldObject::TypeInfo::ObjectSubtype ot; - char tmp[11]; - tmp[10] = '\0'; - cv.fromBuffer(tmp,10); - for (int u=0;u<10;u++) - printf("%i ",tmp[u]); - ot = tmp; - ServerWObject* pl =0; - - pl=ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_PLAYER, ot); - - - if (pl!=0) - { - //pl->fromSavegame(bp2); - insertSWObject(pl,6,11,0); - m_player_slots->insert(make_pair(pl->getId(), *i)); - - //pl->getDynAttr()->m_status_mod_time[Damage::CONFUSED] = 100000; - //pl->getDynAttr()->m_status_mod_time[Damage::BERSERK] = 100000; - - } i = m_logins.erase(i); } else @@ -320,9 +305,7 @@ } -/** - * - */ + World::~World() { @@ -341,22 +324,15 @@ delete[] m_parties; delete m_player_slots; } -/** - * Methods - */ + + -short World::insertRegion(Region* region) +short World::insertRegion(Region* region, int rnr) { - short i=0; - while (i<WORLD_MAX_REGIONS) - { - if (m_regions[i]==0) - { - m_regions[i]=region; - return i; - } - } - return -1; + + m_regions[rnr]=region; + return rnr; + } WorldObject::Relation World::getRelation(WorldObject::TypeInfo::Fraction frac, ServerWObject* wo) @@ -399,6 +375,7 @@ } } + Party* World::getEmptyParty() { int i; @@ -410,6 +387,7 @@ return 0; } + bool World::intersect(Shape* s1, Shape* s2) { Shape* t=0; @@ -492,6 +470,7 @@ } + float World::getDistance(Shape& s1, Shape& s2) { return (sqrt(sqr(s1.m_coordinate_x-s2.m_coordinate_x) +sqr(s1.m_coordinate_y-s2.m_coordinate_y)) - s1.m_radius - s2.m_radius); @@ -499,9 +478,8 @@ -/** - * - */ + + ServerWObject* World::getSWObject ( int id,short rid) { return m_regions[rid]->getSWObject(id); @@ -528,6 +506,7 @@ } } + int World::newTrade(int trader1_id, int trader2_id) { // zufällige ID erzeugen; @@ -555,6 +534,7 @@ return id; } + bool World:: getSWObjectsInShape( Shape* shape, short region, list<ServerWObject*>* result,short layer, short group, ServerWObject* omit ) { @@ -598,6 +578,7 @@ } + void World::getProjectilesOnScreen(float center_x,float center_y,short region, list<DmgProjectile*>* result) { Region* r = m_regions[region]; @@ -607,6 +588,7 @@ r->getProjectilesOnScreen(center_x,center_y,result); } + bool World::lineIntersect(float xstart, float ystart, float xend,float yend ,float dir[2],Shape* s) { float p[2]; @@ -796,9 +778,8 @@ } */ -/** - * - */ + + bool World::insertSWObject (ServerWObject* object, float x, float y, short region) { DEBUG5("inserting Object at %f %f into region %i",x,y,region); @@ -808,27 +789,45 @@ if (object == 0) return false; + object->getGridLocation()->m_region = region; + object->getGeometry()->m_shape.m_coordinate_x=x; + object->getGeometry()->m_shape.m_coordinate_y=y; + Region* r = m_regions[region]; if (r==0) - return false; - - /* - if (object->getTypeInfo()->m_type == WorldObject::TypeInfo::TYPE_PLAYER) { - result &= (m_players->insert(make_pair(object->getId(),object))).second; + // Region existiert nicht + + + // Serverseite: Region erzeugen + if (m_server) + { + createRegion(region); + r = m_regions[region]; + + // wenn das Objekt nicht lokal ist + if (object != m_local_player) + { + // Daten zu dem Spieler senden, der die Informationen benoetigt + } + } } - */ - - object->getGridLocation()->m_region = region; - result &= r->insertSWObject(object,x,y); + + if (r!=0) + { + result &= r->insertSWObject(object,x,y); + } return result; } -/** -* -*/ +bool World::insertPlayer(ServerWObject* player, int slot) +{ + m_player_slots->insert(make_pair(slot,player)); +} + + bool World::moveSWObject(ServerWObject* object, float x, float y) { bool result; @@ -845,9 +844,8 @@ return result; } -/** - * - */ + + bool World::deleteSWObject (ServerWObject* object) { bool result=true; @@ -873,6 +871,7 @@ } + bool World::insertProjectile(DmgProjectile* object, float x, float y, short region) { m_regions[region]->insertProjectile(object,x,y); @@ -881,50 +880,124 @@ } -/** - * - */ + +void World::handleSavegame(char* data, int slot) +{ + // Spieler aus dem Savegame erzeugen + CharConv cv((unsigned char*) data,18); + char binsave; + cv.fromBuffer<char>(binsave); + short version; + cv.fromBuffer<short>(version); + int len; + cv.fromBuffer<int>(len); + WorldObject::TypeInfo::ObjectSubtype ot; + char tmp[11]; + tmp[10] = '\0'; + cv.fromBuffer(tmp,10); + ot = tmp; + ServerWObject* pl =0; + + + pl=ObjectFactory::createObject(WorldObject::TypeInfo::TYPE_PLAYER, ot); + + // Spieler zur Welt hinzufuegen + if (pl!=0) + { + insertPlayer(pl,slot); + insertSWObject(pl,6,11,0); -/** -* -*/ + } + + // Wenn man sich auf Serverseite befindet + if (m_server) + { + // Event hinzufuegen, dass dieser Spieler die Welt betreten hat + } + + // Spieler ist lokal + if (slot == -1) + { + m_local_player = pl; + + if (!m_server) + { + // Savegame dem Server senden + // Savegame an den Server senden + ClientHeader header; + header.m_content = PTYPE_C2S_SAVEGAME; // Savegame von Client zu Server + header.m_chatmessage = false; // keine Chatnachricht + CharConv save; + header.toString(&save); + save.toBuffer(data,len); + m_network->pushSlotMessage(save.getBitStream()); + } + } + +} + + +void World::handleCommand(ClientCommand* comm, int slot) +{ + DEBUG5("Kommando (%f %f) button: %i id: %i action: %i",comm->m_coordinate_x,comm->m_coordinate_y,comm->m_button, comm->m_id,comm->m_action); + + + // Wenn man sich nicht auf Serverseite befindet + if (!m_server) + { + // Kommando an den Server senden + CharConv cv; + + // Header anlegen + ClientHeader header; + header.m_content = PTYPE_C2S_DATA; // Daten von Client zu Server + header.m_chatmessage = false; // keine Chatnachricht + + + // Header in den Puffer schreiben + header.toString(&cv); + // Kommando in den Puffer schreiben + comm->toString(&cv); + + + + // Datenpaket zum Server senden + getNetwork()->pushSlotMessage(cv.getBitStream()); + } + + Player* pl = static_cast<Player*> ((*m_player_slots)[slot]); + if (pl == 0) + { + ERRORMSG("no player in slot %i",slot); + } + else + { + pl->onClientCommand(comm); + } + + +} + int World::getValidId() { // zufällige ID erzeugen; - int id = 0; - ServerWObject* wo; - while (id == 0) - { - id=rand(); - /* - wo=getSWObject(id); - if (wo!=0) - { - id=0; - } - */ - } - return id; + static int j=0; + return j++; } + int World::getValidProjectileId() { // zufällige ID erzeugen; - int id = 0; - while (id == 0) - { - id=rand(); - } - return id; + static int i=0; + return i++; } -/** -* -*/ + void World::update(float time) { - + DEBUG5("update %f",time); for (int i=0;i<WORLD_MAX_REGIONS;i++) { if (m_regions[i]!=0) @@ -973,10 +1046,26 @@ acceptLogins(); } + // Schleife ueber die Spieler + map<int,ServerWObject*>::iterator it; + Player* pl; + for (it = m_player_slots->begin(); it != m_player_slots->end(); ++it) + { + + pl = static_cast<Player*>(it->second); + + // TODO: weitere Bedingungen damit ein Spieler in einer Region aktiviert wird + if (pl->getState() == WorldObject::STATE_REGION_ENTERED && pl->getRegion() !=0 ) + { + pl->setState(WorldObject::STATE_ACTIVE); + } + } + m_network->update(); } + bool World::calcBlockmat(PathfindInfo * pathinfo) { float sqs = pathinfo->m_base_size / pathinfo->m_quality;
--- a/src/core/world.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/core/world.h Fri Sep 19 11:03:22 2008 +0000 @@ -30,7 +30,6 @@ #include <algorithm> #include <iostream> -//#include "player.h" #include "serverwobject.h" #include "dmgprojectile.h" #include "trade.h" @@ -95,7 +94,7 @@ */ bool init(); - void generate(int type); + void createRegion(short region); /** @@ -112,12 +111,12 @@ //Accessor Methods /** - * \fn short insertRegion(Region* region) + * \fn short insertRegion(Region* region, int rnr) * \brief Fuegt eine neue Region in die Welt ein * \param region Einzufuegende Region * \return gibt die ID der Region an, die an allen Objekten in der Region gespeichert wird. Im Falle eines Fehlers wird -1 zurueckgegeben. */ - short insertRegion(Region* region); + short insertRegion(Region* region, int rnr); //Operations /** @@ -243,6 +242,12 @@ * Wenn ein NULL-Zeiger übergeben wird, so wird false ausgegeben. */ bool insertSWObject (ServerWObject* object, float x, float y, short region); + + /** + * \fn bool insertPlayer(ServerWObject* player, int slot) + * \brief Fuegt einen neuen Spieler hinzu + */ + bool insertPlayer(ServerWObject* player, int slot); /** * \fn bool insertProjectile(DmgProjectile* object, float x, float y, short region) @@ -253,7 +258,8 @@ */ bool insertProjectile(DmgProjectile* object, float x, float y, short region); - + + /** * \fn deleteServerWObject(ServerWObject* object) * \brief Löscht ServerWObject @@ -385,7 +391,14 @@ return &(m_parties[frac - WorldObject::TypeInfo::FRAC_PLAYER_PARTY]); } - + /** + * \fn ServerWObject* getLocalPlayer() + * \brief Gibt den Spieler aus, der sich an dem Rechner befindet, auf dem diese Welt simuliert wird + */ + ServerWObject* getLocalPlayer() + { + return m_local_player; + } /** * \fn Party* getEmptyParty() @@ -408,7 +421,21 @@ */ static float getDistance(Shape& s1, Shape& s2); - + /** + * \fn void handleSavegame(char* data, int slot=-1) + * \brief Behandelt den Empfang eines Savegames + * \param data Savegame + * \param slot Slot ueber den das Savegame empfangen wurde. Wenn das Savegame nicht ueber das Netzwerk uebertragen wurde -1 + */ + void handleSavegame(char* data, int slot=-1); + + /** + * \fn void handleCommand(ClientCommand* cmd, int slot=-1) + * \brief Behandelt ein erhaltenes Kommmando + * \param cmd Kommando + * \param slot Slot ueber den das Kommando empfangen wurde. Wenn das Kommando nicht ueber das Netzwerk uebertragen wurde -1 + */ + void handleCommand(ClientCommand* cmd, int slot=-1); // debug only @@ -447,7 +474,7 @@ * \var m_players * Liste der Spieler in der Welt */ - map<int,int>* m_player_slots; + map<int,ServerWObject*>* m_player_slots; /** * \var int m_max_nr_players @@ -462,6 +489,11 @@ Network* m_network; /** + * \var ServerWObject* m_local_player + */ + ServerWObject* m_local_player; + + /** * \var list<int> m_logins * \brief Liste der Spieler die sich gerade einloggen wollen */
--- a/src/gl_gui/Makefile Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gl_gui/Makefile Fri Sep 19 11:03:22 2008 +0000 @@ -11,19 +11,19 @@ LDFLAGS = LOADLIBES = -LIBS = OIS RakNet +LIBS = RakNet LDLIBS = `pkg-config $(LIBS) --libs` LDLIBS += -lm -lrt -lGL -lglut #LDLIBS += -L../../server/trunk -CFLAGS = -m32 -O3 +CFLAGS = -m32 -g CXXFLAGS = $(CFLAGS) CXXFLAGS += `pkg-config $(LIBS) --cflags` -#CXXFLAGS += -I../../shared -I.. +CXXFLAGS += -I../core CXXFLAGS += -DDEBUG_LEVEL=$(DEBUG_LEVEL) -OBJS = $(shell cat ./Makefile.objs ) +OBJS = $(shell cat ./Makefile.objs ) $(shell cat ../core/Makefile.objs ) DIRS = $(shell find . -mindepth 1 -maxdepth 1 -type d -not -iname .svn ) build: compile $(RUN)
--- a/src/gl_gui/Makefile.objs Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gl_gui/Makefile.objs Fri Sep 19 11:03:22 2008 +0000 @@ -1,17 +1,2 @@ -../document.o -../../shared/action.o -../../shared/worldobject.o -../../shared/networkstruct.o -../../shared/projectile.o -../../shared/party.o -../../shared/debug.o -../../shared/itemlist.o -../../shared/item.o -../../shared/dropitem.o -../../shared/serveritem.o -../../shared/damage.o -../clientnetwork.o -../clientwobject.o -../clientmplayer.o main.o window_main_gl.o
--- a/src/gl_gui/main.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gl_gui/main.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -36,18 +36,21 @@ } else { - save = "../save/warrior.sav"; + save = "warrior.sav"; } // Globales Document anlegen - global_doc = new Document(Document::GL_GUI); + global_doc = new Document(); global_doc->setSaveFile(save); - global_doc->serverConnect(); + + global_doc->installShortkey(27,Document::CLOSE_ALL); + + global_doc->startGame(true); //Gtk::Main mn( argc,argv ); //Gtk::GL::init( argc,argv ); - + if ( true ) {
--- a/src/gl_gui/window_main_gl.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gl_gui/window_main_gl.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -39,8 +39,8 @@ int n =0; WorldObject::TypeInfo::ObjectSubtype i; - if (global_doc->getMainPlayer()!=0) - i = global_doc->getMainPlayer()->getTypeInfo()->m_subtype; + if (global_doc->getLocalPlayer()!=0) + i = global_doc->getLocalPlayer()->getTypeInfo()->m_subtype; if (i=="warrior") n=32; @@ -84,7 +84,7 @@ // ESC if (key == 27) { - global_doc ->onKeyPress(OIS::KC_ESCAPE); + //global_doc ->onKeyPress(OIS::KC_ESCAPE); } } @@ -110,7 +110,7 @@ if (global_doc->getState() == Document::SHUTDOWN) exit(0); - global_doc->update(); + global_doc->update(25); glutTimerFunc(25,TimerFunc,0); glutPostRedisplay(); @@ -130,11 +130,18 @@ y=y_dim-(y/fielddim); if (state == GLUT_DOWN) { + if (global_doc->getLocalPlayer() ==0) + return; + + float dx,dy; + dx = global_doc->getLocalPlayer()->getGeometry()->m_shape.m_coordinate_x; + dy = global_doc->getLocalPlayer()->getGeometry()->m_shape.m_coordinate_y; + if (button==0) { global_doc->getGUIState()->m_left_mouse_hold=true; - global_doc->onLeftMouseButtonClick(x, y); + global_doc->onLeftMouseButtonClick(x+dx, y+dy); DEBUG5("Left Button press"); } @@ -143,7 +150,7 @@ if (button==2) { global_doc->getGUIState()->m_right_mouse_hold=true; - global_doc->onRightMouseButtonClick(x, y); + global_doc->onRightMouseButtonClick(x+dx, y+dy); DEBUG5("right Button press"); @@ -206,8 +213,14 @@ glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity (); + if (global_doc->getLocalPlayer() ==0) + return; + + + Region* region = global_doc->getLocalPlayer()->getRegion(); + if (region ==0) + return; - static std::map<int,ClientWObject*>::iterator i; static float x = 0; static float y = 0; @@ -216,7 +229,7 @@ glDisable(GL_BLEND); - if (global_doc->getMainPlayer()==0) + if (global_doc->getLocalPlayer()==0) { glFlush (); // Daten an Server (fuer die Darstellung) // schicken @@ -229,18 +242,16 @@ global_doc->lock(); - x = global_doc->getMainPlayer()->getGeometry()->m_shape.m_coordinate_x; - y = global_doc->getMainPlayer()->getGeometry()->m_shape.m_coordinate_y; - + x = global_doc->getLocalPlayer()->getGeometry()->m_shape.m_coordinate_x; + y = global_doc->getLocalPlayer()->getGeometry()->m_shape.m_coordinate_y; int action_idx ; - ClientWObject* cwo; - WorldObject* wo; float c[3]; - + // Tiles zeichnen + /* Matrix2d<char>* mat = global_doc->getRegionData()->m_tiles; int dimx = global_doc->getRegionData()->m_dimx; int dimy = global_doc->getRegionData()->m_dimy; @@ -290,16 +301,29 @@ } } - +*/ - map<int,WorldObject*>::iterator it; - map<int,WorldObject*>* stat_objs = (global_doc->getRegionData()->m_static_objects); + list<ServerWObject*> stat_objs; + list<ServerWObject*> obj; + list<ServerWObject*>::iterator it; + Shape s; + s.m_coordinate_x = x; + s.m_coordinate_y = y; + s.m_type = Shape::RECT; + s.m_extent_x = 10; + s.m_extent_y = 10; + + ServerWObject* wo, *cwo; + Creature* cr; + + region->getSWObjectsInShape(&s,&stat_objs, WorldObject::Geometry::LAYER_ALL,WorldObject::FIXED); + region->getSWObjectsInShape(&s,&obj, WorldObject::Geometry::LAYER_ALL,WorldObject::GROUP_ALL & ~WorldObject::FIXED); - for (it = stat_objs->begin(); it !=stat_objs->end();++it) + for (it = stat_objs.begin(); it !=stat_objs.end();++it) { glPushMatrix(); - wo = it->second; + wo = *it; cx = wo->getGeometry()->m_shape.m_coordinate_x; cy = wo->getGeometry()->m_shape.m_coordinate_y; @@ -347,11 +371,11 @@ glPopMatrix(); } - for (i = global_doc->getObjects()->begin(); i != global_doc->getObjects()->end(); ++i) + for (it = obj.begin(); it != obj.end(); ++it) { glPushMatrix(); - cwo = i->second; + cwo = *it; //DEBUG("displaying obj %i",cwo->getId()); c[0]=0; c[1]=0; @@ -434,6 +458,7 @@ if (cwo->getTypeInfo()->m_type != WorldObject::TypeInfo::TYPE_FIXED_OBJECT) { + cr = static_cast<Creature*> (cwo); glColor3f(0,0,0); glBegin(GL_QUADS); glVertex3f(-0.8*r,-0.2*r,0.1); @@ -443,8 +468,9 @@ glEnd(); - DEBUG5("health percent %f",cwo->m_health_perc); - float p = cwo->m_health_perc; + //DEBUG5("health percent %f",cwo->m_health_perc); + float p = cr->getDynAttr()->m_health / cr->getBaseAttrMod()->m_max_health; + float* status_mods = cr->getDynAttr()->m_status_mod_time; if (p<=0) p=0; glColor3f(c[0],c[1],c[2]); @@ -456,7 +482,7 @@ glEnd(); - if (cwo->m_status_mods & 1) + if (status_mods[0] >0) { glColor3f(1,1,1); glBegin(GL_QUADS); @@ -468,7 +494,7 @@ glEnd(); } - if (cwo->m_status_mods & 2) + if (status_mods[1] >0) { glColor3f(0,0.6,0); glBegin(GL_QUADS); @@ -480,7 +506,7 @@ glEnd(); } - if (cwo->m_status_mods & 4) + if (status_mods[2] >0) { glColor3f(0.7,0,0); glBegin(GL_QUADS); @@ -492,7 +518,7 @@ glEnd(); } - if (cwo->m_status_mods & 8) + if (status_mods[3] >0) { glColor3f(0.5,0.5,0.5); glBegin(GL_QUADS); @@ -504,7 +530,7 @@ glEnd(); } - if (cwo->m_status_mods & 16) + if (status_mods[4] >0) { glColor3f(0.7,0,0.7); glBegin(GL_QUADS); @@ -516,7 +542,7 @@ glEnd(); } - if (cwo->m_status_mods & 32) + if (status_mods[5] >0) { glColor3f(1,1,0); glBegin(GL_QUADS); @@ -528,7 +554,7 @@ glEnd(); } - if (cwo->m_status_mods & 64) + if (status_mods[6] >0) { glColor3f(0.6,0.6,1); glBegin(GL_QUADS); @@ -540,7 +566,7 @@ glEnd(); } - if (cwo->m_status_mods & 128) + if (status_mods[7] >0) { glColor3f(1,0.8,0.3); glBegin(GL_QUADS); @@ -562,11 +588,14 @@ } - map<int,Projectile*>::iterator i2; + list<DmgProjectile*> proj; + list<DmgProjectile*>::iterator i2; + + region->getProjectilesOnScreen(x,y,&proj); Projectile* pr; - for (i2=global_doc->getProjectiles()->begin(); i2 != global_doc->getProjectiles()->end(); ++i2) + for (i2=proj.begin(); i2 != proj.end(); ++i2) { - pr = (i2->second); + pr = *i2; glPushMatrix(); c[0]=0; c[1]=0; @@ -680,7 +709,7 @@ glPopMatrix(); } - +/* r=0.5; glPushMatrix(); glTranslatef(-8,-4,0); @@ -689,7 +718,7 @@ glBegin(GL_TRIANGLE_FAN); glVertex3f(0, 0,0.8); - for (float a=0;a<=(1-global_doc->getMainPlayer()->m_timer1_perc)*6.3;a+=0.1) + for (float a=0;a<=(1-global_doc->getLocalPlayer()->m_timer1_perc)*6.3;a+=0.1) { glVertex3f(cos(a)*r, sin(a)*r,0.8); } @@ -704,14 +733,14 @@ glBegin(GL_TRIANGLE_FAN); glVertex3f(0, 0,0.8); - for (float a=0;a<=(1-global_doc->getMainPlayer()->m_timer2_perc)*6.3;a+=0.1) + for (float a=0;a<=(1-global_doc->getLocalPlayer()->m_timer2_perc)*6.3;a+=0.1) { glVertex3f(cos(a)*r, sin(a)*r,0.8); } glEnd(); glPopMatrix(); - +*/ // Daten entsperren global_doc->unlock();
--- a/src/gl_gui/window_main_gl.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gl_gui/window_main_gl.h Fri Sep 19 11:03:22 2008 +0000 @@ -1,35 +1,35 @@ #ifndef WINMAIN_H -#define WINMAIN_H - -class WindowMain -{ - public: - - - WindowMain(); - ~WindowMain(){} - - static void DisplayFunc (); - static void ReshapeFunc (int,int); - static void MouseFunc (int,int,int,int); - static void SetCamera(); - static void KeyboardFunc (unsigned char,int,int); - static void KeyboardUpFunc (unsigned char,int,int); - static void SpecialKeyboardUpFunc (int key, int x, int y); - static void SpecialKeyboardFunc (int key, int x, int y); - static void TimerFunc(int dummy); - - -}; +#define WINMAIN_H + +class WindowMain +{ + public: + + + WindowMain(); + ~WindowMain(){} + + static void DisplayFunc (); + static void ReshapeFunc (int,int); + static void MouseFunc (int,int,int,int); + static void SetCamera(); + static void KeyboardFunc (unsigned char,int,int); + static void KeyboardUpFunc (unsigned char,int,int); + static void SpecialKeyboardUpFunc (int key, int x, int y); + static void SpecialKeyboardFunc (int key, int x, int y); + static void TimerFunc(int dummy); + + +}; #pragma message("WinMain definiert") #include <GL/glut.h> -#include "../document.h" +#include "document.h" #include <stdlib.h> #include <math.h> #pragma message("header ende") - + #endif
--- a/src/gui/Makefile Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gui/Makefile Fri Sep 19 11:03:22 2008 +0000 @@ -16,14 +16,14 @@ LDLIBS += -lm -lrt -lGL -lglut #LDLIBS += -L../../server/trunk -CFLAGS = -m32 -O3 +CFLAGS = -m32 -g CXXFLAGS = $(CFLAGS) CXXFLAGS += `pkg-config $(LIBS) --cflags` -#CXXFLAGS += -I../shared +CXXFLAGS += -I../core CXXFLAGS += -DDEBUG_LEVEL=$(DEBUG_LEVEL) -OBJS = $(shell cat ./Makefile.objs ) +OBJS = $(shell cat ./Makefile.objs ) $(shell cat ../core/Makefile.objs ) DIRS = $(shell find . -mindepth 1 -maxdepth 1 -type d -not -iname .svn ) build: compile $(RUN)
--- a/src/gui/Makefile.objs Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gui/Makefile.objs Fri Sep 19 11:03:22 2008 +0000 @@ -1,20 +1,4 @@ -document.o -../shared/action.o -../shared/worldobject.o -../shared/networkstruct.o -../shared/projectile.o -../shared/party.o -../shared/debug.o -../shared/itemlist.o -../shared/item.o -../shared/dropitem.o -clientnetwork.o -clientwobject.o -clientmplayer.o main_gui.o +mainwindow.o +scene.o client.o -mainwindow.o -numberedwindow.o -../shared/serveritem.o -../shared/damage.o -scene.o
--- a/src/gui/client.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gui/client.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -1,6 +1,6 @@ #include "client.h" -Client::Client() +Application::Application() { // Anwendung initialisieren bool ret = init(); @@ -13,7 +13,7 @@ } -bool Client::init() +bool Application::init() { bool ret = true; @@ -94,7 +94,7 @@ } -Client::~Client() +Application::~Application() { // dynamisch angelegte Objekte in umgekehrter Reihenfolge freigeben @@ -105,12 +105,12 @@ delete m_ogre_root; } -void Client::run() +void Application::run() { printf("started\n"); Ogre::Timer timer; unsigned long ltime; - float time=0; + float time=0,ftime; float uptime =0; //m_ogre_root->startRendering(); float timesum=0; @@ -121,32 +121,38 @@ { ltime =timer.getMicroseconds (); - time = ltime / ( 1000000.0); + ftime = ltime / ( 1000000.0); timer.reset(); - if (time>0.025) - { - DEBUG5("frame time was %f",time*1000); - } - + DEBUG5("overall frame time was %f",ftime*1000); + + timer2.reset(); + update(); - ltime =timer.getMicroseconds (); - uptime = ltime / ( 1000000.0); - if (uptime>0.025) - { - DEBUG("update time was %f",time*1000); - } + ltime =timer2.getMicroseconds (); + time = ltime / ( 1000000.0); + + DEBUG5("update time was %f",time*1000); + timer2.reset(); // run the message pump Ogre::WindowEventUtilities::messagePump(); - + ltime =timer2.getMicroseconds (); + time = ltime / ( 1000000.0); + DEBUG5("message pump time was %f",time*1000); + + timer2.reset(); + // Document aktualisieren - DEBUG5("document update"); - m_document->update(time*1000); - DEBUG5("done"); - + m_document->update(ftime*1000); + + ltime =timer2.getMicroseconds (); + time = ltime / ( 1000000.0); + DEBUG5("document update time was %f",time*1000); + + /* count ++; timesum += time; if (count ==100) @@ -156,12 +162,19 @@ DEBUG5("frame time is %f",timesum); timesum =0; } + */ try { + timer2.reset(); + // View aktualisieren DEBUG5("main window update"); m_main_window->update(); + + ltime =timer2.getMicroseconds (); + time = ltime / ( 1000000.0); + DEBUG5("view update time was %f",time*1000); } catch (CEGUI::Exception e) { @@ -170,31 +183,25 @@ //DEBUG("frame time in s %f",time); - m_cegui_system->injectTimePulse(time); + m_cegui_system->injectTimePulse(ftime); // rendern - DEBUG5("ogre frame"); timer2.reset(); m_ogre_root->renderOneFrame(); - ltime =timer.getMicroseconds (); + ltime =timer2.getMicroseconds (); time = ltime / ( 1000000.0); - - if (time>0.025) - { - DEBUG5("ogre frame time was %f",time*1000); - } - - DEBUG5("ogre frame end"); + DEBUG5("ogre frame time was %f",time*1000); + } } -bool Client::initOgre() +bool Application::initOgre() { DEBUG("init ogre"); // Fenster anlegen, Ogre initialisieren @@ -207,7 +214,7 @@ } -bool Client::configureOgre() +bool Application::configureOgre() { DEBUG("configure ogre"); // Logging nur fuer Fehlermeldungen verwenden @@ -219,7 +226,7 @@ renderSystems = m_ogre_root->getAvailableRenderers(); if (renderSystems->empty()) { - // ERRORMSG("no rendering system available"); + ERRORMSG("no rendering system available"); return false; } r_it = renderSystems->begin(); @@ -240,26 +247,26 @@ return true; } -bool Client::setupResources() +bool Application::setupResources() { DEBUG("initalizing resources"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/resources/models", "FileSystem", "General"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/resources/materials/scripts", "FileSystem", "General"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/resources/materials/textures", "FileSystem", "General"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/resources/particle", "FileSystem", "General"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../resources/models", "FileSystem", "General"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../resources/materials/scripts", "FileSystem", "General"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../resources/materials/textures", "FileSystem", "General"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../resources/particle", "FileSystem", "General"); // CEGUI Resourcen laden - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/resources/gui/configs", "FileSystem", "GUI"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/resources/gui/fonts", "FileSystem", "GUI"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../resources/gui/configs", "FileSystem", "GUI"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../resources/gui/fonts", "FileSystem", "GUI"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/resources/gui/imagesets", "FileSystem", "GUI"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/resources/gui/layouts", "FileSystem", "GUI"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/resources/gui/looknfeel", "FileSystem", "GUI"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/resources/gui/schemes", "FileSystem", "GUI"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../resources/gui/imagesets", "FileSystem", "GUI"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../resources/gui/layouts", "FileSystem", "GUI"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../resources/gui/looknfeel", "FileSystem", "GUI"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../resources/gui/schemes", "FileSystem", "GUI"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/resources/gui/schemes", "FileSystem", "GUI"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../resources/gui/schemes", "FileSystem", "GUI"); - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../client/save", "FileSystem", "Savegame"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("../../save", "FileSystem", "Savegame"); #if defined(WIN32) @@ -285,7 +292,7 @@ return true; } -bool Client::initGettext() +bool Application::initGettext() { DEBUG("initializing internationalisation"); #ifndef WIN32 @@ -318,7 +325,7 @@ return true; } -bool Client::initCEGUI() +bool Application::initCEGUI() { DEBUG("init CEGUI\n"); m_ogre_cegui_renderer = new CEGUI::OgreCEGUIRenderer( @@ -368,16 +375,33 @@ return true; } -bool Client::createDocument() +bool Application::createDocument() { DEBUG("create document\n"); m_document = new Document(); - + + m_document->installShortkey(OIS::KC_ESCAPE,Document::CLOSE_ALL); + m_document->installShortkey(OIS::KC_I,Document::SHOW_INVENTORY); + m_document->installShortkey(OIS::KC_C,Document::SHOW_CHARINFO); + m_document->installShortkey(OIS::KC_T,Document::SHOW_SKILLTREE); + m_document->installShortkey(OIS::KC_P,Document::SHOW_PARTYMENU); + m_document->installShortkey(OIS::KC_M,Document::SHOW_CHATBOX); + m_document->installShortkey(OIS::KC_W,Document::SWAP_EQUIP); + m_document->installShortkey(OIS::KC_1,Document::USE_POTION); + m_document->installShortkey(OIS::KC_2,(Document::ShortkeyDestination) (Document::USE_POTION+1)); + m_document->installShortkey(OIS::KC_3,(Document::ShortkeyDestination) (Document::USE_POTION+2)); + m_document->installShortkey(OIS::KC_4,(Document::ShortkeyDestination) (Document::USE_POTION+3)); + m_document->installShortkey(OIS::KC_5,(Document::ShortkeyDestination) (Document::USE_POTION+4)); + m_document->installShortkey(OIS::KC_6,(Document::ShortkeyDestination) (Document::USE_POTION+5)); + m_document->installShortkey(OIS::KC_7,(Document::ShortkeyDestination) (Document::USE_POTION+6)); + m_document->installShortkey(OIS::KC_8,(Document::ShortkeyDestination) (Document::USE_POTION+7)); + m_document->installShortkey(OIS::KC_9,(Document::ShortkeyDestination) (Document::USE_POTION+8)); + m_document->installShortkey(OIS::KC_0,(Document::ShortkeyDestination) (Document::USE_POTION+9)); return true; } -bool Client::createView() +bool Application::createView() { DEBUG("create view\n"); m_main_window = new MainWindow(m_ogre_root, m_cegui_system,m_window,m_document); @@ -386,7 +410,7 @@ return true; } -void Client::update() +void Application::update() { }
--- a/src/gui/client.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gui/client.h Fri Sep 19 11:03:22 2008 +0000 @@ -1,6 +1,6 @@ -#ifndef CLIENT_H -#define CLIENT_H +#ifndef APPLICATION_H +#define APPLICATION_H @@ -27,25 +27,25 @@ /** - * \class Client + * \class Application * \brief Basisklasse der Anwendung */ -class Client +class Application { public: /** - * \fn Client() + * \fn Application() * \brief Konstruktor */ - Client(); + Application(); /** - * \fn ~Client() + * \fn ~Application() * \brief Destruktor */ - ~Client(); + ~Application(); /** * \fn run() @@ -172,7 +172,6 @@ * \brief Hauptfenster der Applikation */ MainWindow* m_main_window; - };
--- a/src/gui/main_gui.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gui/main_gui.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -13,7 +13,7 @@ // Applikation anlegen - Client* app = new Client(); + Application* app = new Application(); // Debugging: Kommandozeilen Parameter auslesen und Savefile setzen string save; @@ -24,18 +24,21 @@ } else { - save = "save/default.sav"; + save = "default.sav"; } #else - save = "save/default.sav"; + save = "default.sav"; #endif Document* doc = app->getDocument(); doc->setSaveFile(save); - doc->setState(Document::CONNECT_REQUEST); + + doc->setServer(true); + doc->setState(Document::START_GAME); doc->getGUIState()->m_sheet= Document::GAME_SCREEN; doc->getGUIState()->m_shown_windows = Document::NO_WINDOWS; // laufen lassen + try {
--- a/src/gui/mainwindow.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gui/mainwindow.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -38,7 +38,7 @@ result &= setupGameScreen(); // Aktuelle Ebene setzen - CEGUI::System::getSingleton().setGUISheet(m_game_screen); + CEGUI::System::getSingleton().setGUISheet(m_main_menu); return result; @@ -262,11 +262,11 @@ inventory->setVisible(false); } - if (m_document->getMainPlayer()!=0) + if (m_document->getLocalPlayer()!=0) { // Skilltree anzeigen wenn entsprechendes Flag gesetzt CEGUI::TabControl* skilltree = (CEGUI::TabControl*) win_mgr.getWindow("SkilltreeMage"); - ClientMPlayer* player = m_document->getMainPlayer(); + Player* player = m_document->getLocalPlayer(); // Skilltree einstellen der der Spielerklasse entspricht if (player->getTypeInfo()->m_subtype == "warrior") @@ -289,25 +289,15 @@ } - if (m_document->getModified() & Document::ITEM_MODIFIED) - { - // Tooltip fuer das Item ueber dem die Maus ist neu setzen - updateItemTooltip(); - m_document->setModified(m_document->getModified() & ~Document::ITEM_MODIFIED); - } - - if (m_document->getModified() & Document::ABILITY_MODIFIED) + // Objekte aus dem Dokument darstellen + if (m_document->getLocalPlayer()!=0) { - // Tooltip fuer die Faehigkeit ueber der die Maus ist neu setzen - updateAbilityTooltip(); - m_document->setModified(m_document->getModified() & ~Document::ABILITY_MODIFIED); - } - - // Objekte aus dem Dokument darstellen - if (m_document->getMainPlayer()!=0) - { + + // Szene aktualisieren m_scene->update(); + + // ObjectInfo aktualisieren updateObjectInfo(); @@ -2125,7 +2115,7 @@ DEBUG("file found %s",it->c_str()); //File oeffnen - file.open(("../client/save/"+(*it)).c_str(),ios::in| ios::binary); + file.open(("../../save/"+(*it)).c_str(),ios::in| ios::binary); if (file.is_open()) { savelist->addRow(); @@ -2166,7 +2156,7 @@ savelist->setItem(new ListItem(classname),1,n); name = bp; - savelist->setItem(new SaveListItem(name,"save/"+(*it)),0,n); + savelist->setItem(new SaveListItem(name,(*it)),0,n); n++; file.close(); @@ -2178,7 +2168,7 @@ void MainWindow::updateCharInfo() { // Spielerobjekt - ClientMPlayer* player = m_document->getMainPlayer(); + Player* player = m_document->getLocalPlayer(); std::string tooltip; @@ -2225,7 +2215,7 @@ // Label Level label = win_mgr.getWindow("LevelLabel"); out_stream.str(""); - out_stream << "Level "<<(int) player->m_level; + out_stream << "Level "<<(int) player->getBaseAttr()->m_level; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2234,7 +2224,7 @@ // Label Staerke label = win_mgr.getWindow("StrengthValueLabel"); out_stream.str(""); - out_stream << player->m_strength; + out_stream << player->getBaseAttrMod()->m_strength; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2243,7 +2233,7 @@ // Label Zauberkraft label = win_mgr.getWindow("MagicpowerValueLabel"); out_stream.str(""); - out_stream << player->m_magic_power; + out_stream << player->getBaseAttrMod()->m_magic_power; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2252,7 +2242,7 @@ // Label Willenskraft label = win_mgr.getWindow("WillpowerValueLabel"); out_stream.str(""); - out_stream << player->m_willpower; + out_stream << player->getBaseAttrMod()->m_willpower; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2261,7 +2251,7 @@ // Label Geschick label = win_mgr.getWindow("DexterityValueLabel"); out_stream.str(""); - out_stream << player->m_dexterity; + out_stream << player->getBaseAttrMod()->m_dexterity; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2269,7 +2259,7 @@ // Buttons zum erhoehen von Attributen sind nur sichtbar wenn Attributpunkt zu verteilen sind bool add_but_vis = false; - if ( player->m_attribute_points>0) + if ( player->getAttributePoints()>0) { add_but_vis=true; } @@ -2287,7 +2277,7 @@ // Label freie Attributspunkte label = win_mgr.getWindow("AttrPointsValueLabel"); out_stream.str(""); - out_stream << player->m_attribute_points;; + out_stream << player->getAttributePoints(); //label->setVisible(add_but_vis); if (label->getText()!=out_stream.str()) { @@ -2297,7 +2287,7 @@ // Label Ruestung label = win_mgr.getWindow("ArmorValueLabel"); out_stream.str(""); - out_stream << player->m_armor; + out_stream << player->getBaseAttrMod()->m_armor; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2306,7 +2296,7 @@ // Label Attacke label = win_mgr.getWindow("AttackValueLabel"); out_stream.str(""); - out_stream << player->m_base_damage.m_attack; + out_stream << player->getBaseDamage().m_attack; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2315,7 +2305,7 @@ // Label Block label = win_mgr.getWindow("BlockValueLabel"); out_stream.str(""); - out_stream << player->m_block; + out_stream << player->getBaseAttrMod()->m_block; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2324,7 +2314,7 @@ // Label HP label = win_mgr.getWindow("HitpointsValueLabel"); out_stream.str(""); - out_stream << (int) player->m_health <<"/" <<(int) player->m_max_health; + out_stream << (int) player->getDynAttr()->m_health <<"/" <<(int) player->getBaseAttrMod()->m_max_health; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2333,7 +2323,7 @@ // Label Exp label = win_mgr.getWindow("ExperienceValueLabel"); out_stream.str(""); - out_stream << (int) player->m_experience <<"/" <<(int) player->m_max_experience; + out_stream << (int) player->getDynAttr()->m_experience <<"/" <<(int) player->getBaseAttr()->m_max_experience; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2342,7 +2332,7 @@ // Label Phys Resistenz label = win_mgr.getWindow("ResistPhysValueLabel"); out_stream.str(""); - out_stream << player->m_resistances[Damage::PHYSICAL]; + out_stream << player->getBaseAttrMod()->m_resistances[Damage::PHYSICAL]; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2351,7 +2341,7 @@ // Label Feuer Resistenz label = win_mgr.getWindow("ResistFireValueLabel"); out_stream.str(""); - out_stream << player->m_resistances[Damage::FIRE]; + out_stream << player->getBaseAttrMod()->m_resistances[Damage::FIRE]; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2360,7 +2350,7 @@ // Label Eis Resistenz label = win_mgr.getWindow("ResistIceValueLabel"); out_stream.str(""); - out_stream << player->m_resistances[Damage::ICE]; + out_stream << player->getBaseAttrMod()->m_resistances[Damage::ICE]; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2369,7 +2359,7 @@ // Label Luft Resistenz label = win_mgr.getWindow("ResistAirValueLabel"); out_stream.str(""); - out_stream << player->m_resistances[Damage::AIR]; + out_stream << player->getBaseAttrMod()->m_resistances[Damage::AIR]; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2378,7 +2368,7 @@ // Label Angriffsgeschwindigkeit label = win_mgr.getWindow("AttackSpeedValueLabel"); out_stream.str(""); - out_stream << player->m_attack_speed; + out_stream << player->getBaseAttrMod()->m_attack_speed; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2387,7 +2377,7 @@ // Label Reichweite label = win_mgr.getWindow("RangeValueLabel"); out_stream.str(""); - out_stream << player->m_attack_range; + out_stream << player->getBaseAttrMod()->m_attack_range; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2396,21 +2386,21 @@ // Label Durchschlagskraft label = win_mgr.getWindow("PowerValueLabel"); out_stream.str(""); - out_stream << player->m_base_damage.m_power; + out_stream << player->getBaseDamage().m_power; if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); } // Schaden Basisattacke - float minb=player->m_base_damage.getSumMinDamage(); - float maxb=player->m_base_damage.getSumMaxDamage(); + float minb=player->getBaseDamage().getSumMinDamage(); + float maxb=player->getBaseDamage().getSumMaxDamage(); // Schaden Attacke links - float minl=player->m_left_damage.getSumMinDamage(); - float maxl=player->m_left_damage.getSumMaxDamage(); + float minl=player->getLeftDamage().getSumMinDamage(); + float maxl=player->getLeftDamage().getSumMaxDamage(); // Schaden Attacke rechts - float minr=player->m_right_damage.getSumMinDamage(); - float maxr=player->m_right_damage.getSumMaxDamage(); + float minr=player->getRightDamage().getSumMinDamage(); + float maxr=player->getRightDamage().getSumMaxDamage(); @@ -2439,7 +2429,7 @@ { label->setText(out_stream.str()); } - tooltip = player->m_base_damage.getDamageString(); + tooltip = player->getBaseDamage().getDamageString(); if (tooltip != label->getTooltipText()) { label->setTooltipText(tooltip); @@ -2448,7 +2438,7 @@ // Label Attacke links label = win_mgr.getWindow( "Skill1DmgLabel"); out_stream.str(""); - out_stream << Action::getName(m_document->getLeftAction()); + out_stream << Action::getName(player->getLeftAction()); if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2463,7 +2453,7 @@ { label->setText(out_stream.str()); } - tooltip = player->m_left_damage.getDamageString(); + tooltip = player->getLeftDamage().getDamageString(); if (tooltip != label->getTooltipText()) { label->setTooltipText(tooltip); @@ -2474,7 +2464,7 @@ // Label Attacke rechts label = win_mgr.getWindow( "Skill2DmgLabel"); out_stream.str(""); - out_stream << Action::getName(m_document->getRightAction()); + out_stream << Action::getName(player->getRightAction()); if (label->getText()!=out_stream.str()) { label->setText(out_stream.str()); @@ -2489,7 +2479,7 @@ { label->setText(out_stream.str()); } - tooltip = player->m_right_damage.getDamageString(); + tooltip = player->getRightDamage().getDamageString(); if (tooltip != label->getTooltipText()) { label->setTooltipText(tooltip); @@ -2506,9 +2496,11 @@ float perc=0; std::string name; + Player* player = m_document->getLocalPlayer(); + // Balken fuer HP CEGUI::ProgressBar* bar = static_cast<CEGUI::ProgressBar*>(win_mgr.getWindow( "HealthProgressBar")); - float hperc = m_document->getMainPlayer()->getHealthPerc(); + float hperc = player->getDynAttr()->m_health / player->getBaseAttrMod()->m_max_health; if (bar->getProgress() != hperc) { bar->setProgress(hperc); @@ -2516,7 +2508,7 @@ // Image Schaden Attacke links label = win_mgr.getWindow( "LeftClickAbilityImage"); - name = Action::getActionInfo((Action::ActionType) m_document->getLeftAction())->m_enum_name; + name = Action::getActionInfo((Action::ActionType) player->getLeftAction())->m_enum_name; if (("set:skills image:" + name) != label->getProperty("Image")) { label->setProperty("Image", "set:skills image:" + name); @@ -2524,16 +2516,9 @@ // Balken fuer Schaden Attacke links bar = static_cast<CEGUI::ProgressBar*>(win_mgr.getWindow( "LeftClickAbilityProgressBar")); - timernr = Action::getActionInfo(m_document->getLeftAction())->m_timer_nr; - if (timernr==1) - { - perc = m_document->getMainPlayer()->m_timer1_perc; - } - if (timernr==2) - { - perc = m_document->getMainPlayer()->m_timer2_perc; - } - + timernr = Action::getActionInfo(player->getLeftAction())->m_timer_nr; + perc = player->getTimerPercent(timernr); + if (bar->getProgress() != perc) { bar->setProgress(perc); @@ -2543,7 +2528,7 @@ // Image Attacke rechts label = win_mgr.getWindow( "RightClickAbilityImage"); - name = Action::getActionInfo((Action::ActionType) m_document->getRightAction())->m_enum_name; + name = Action::getActionInfo((Action::ActionType) player->getRightAction())->m_enum_name; if (("set:skills image:" + name) != label->getProperty("Image")) { label->setProperty("Image", "set:skills image:" + name); @@ -2551,15 +2536,8 @@ // Balken fuer Schaden Attacke rechts bar = static_cast<CEGUI::ProgressBar*>(win_mgr.getWindow( "RightClickAbilityProgressBar")); - timernr = Action::getActionInfo(m_document->getRightAction())->m_timer_nr; - if (timernr==1) - { - perc = m_document->getMainPlayer()->m_timer1_perc; - } - if (timernr==2) - { - perc = m_document->getMainPlayer()->m_timer2_perc; - } + timernr = Action::getActionInfo(player->getRightAction())->m_timer_nr; + perc = player->getTimerPercent(timernr); if (bar->getProgress() != perc) { @@ -2567,7 +2545,7 @@ } Item* it; - Equipement* equ = m_document->getMainPlayer()->m_equipement; + Equipement* equ = player->getEquipement(); // Guertel for (int i=0;i<10;i++) @@ -2594,10 +2572,12 @@ CEGUI::WindowManager& win_mgr = CEGUI::WindowManager::getSingleton(); CEGUI::Window* label; ostringstream out_stream; + + Player* player = m_document->getLocalPlayer(); // Label Ruestung out_stream.str(""); - Equipement* equ = m_document->getMainPlayer()->m_equipement; + Equipement* equ = player->getEquipement(); if (equ->getItem(Equipement::ARMOR)!=0) { out_stream << equ->getItem(Equipement::ARMOR)->getName(); @@ -2610,9 +2590,9 @@ // Label Waffe out_stream.str(""); - if (equ->getItem(Equipement::WEAPON)!=0) + if (player->getWeapon()!=0) { - out_stream << equ->getItem(Equipement::WEAPON)->getName(); + out_stream << player->getWeapon()->getName(); } label = win_mgr.getWindow("WeaponItemLabel"); if (label->getText()!=out_stream.str()) @@ -2634,9 +2614,9 @@ // Label Schild out_stream.str(""); - if (equ->getItem(Equipement::SHIELD)!=0) + if (player->getShield()!=0) { - out_stream << equ->getItem(Equipement::SHIELD)->getName(); + out_stream << player->getShield()->getName(); } label = win_mgr.getWindow("ShieldItemLabel"); if (label->getText()!=out_stream.str()) @@ -2670,7 +2650,6 @@ // Label Ring rechts out_stream.str(""); - equ = m_document->getMainPlayer()->m_equipement; if (equ->getItem(Equipement::RING_RIGHT)!=0) { out_stream << equ->getItem(Equipement::RING_RIGHT)->getName(); @@ -2680,9 +2659,9 @@ { label->setText(out_stream.str()); } + // Label Amulet out_stream.str(""); - equ = m_document->getMainPlayer()->m_equipement; if (equ->getItem(Equipement::AMULET)!=0) { out_stream << equ->getItem(Equipement::AMULET)->getName(); @@ -2758,7 +2737,7 @@ CEGUI::Window* label; ostringstream out_stream; - ClientMPlayer* player = m_document->getMainPlayer(); + Player* player = m_document->getLocalPlayer(); // Enum Wert bei dem die Skillz des Spielers anfangen int i=Action::BASH; @@ -2800,84 +2779,92 @@ } } -void MainWindow::updateItemTooltip() +void MainWindow::updateItemTooltip(unsigned int pos) { - if (m_document->getDetailedItem()) + ServerItem* item = static_cast<ServerItem*>(m_document->getLocalPlayer()->getEquipement()->getItem(pos)); + if (item ==0) + return; + + DEBUG5("setting tool tip for item at %i",pos); + CEGUI::WindowManager& win_mgr = CEGUI::WindowManager::getSingleton(); + CEGUI::Window* label; + ostringstream out_stream; + out_stream.str(""); + if (pos == Equipement::ARMOR) + out_stream << "ArmorItemLabel"; + if (pos == Equipement::WEAPON || pos == Equipement::WEAPON2) + out_stream << "WeaponItemLabel"; + if (pos == Equipement::HELMET) + out_stream << "HelmetItemLabel"; + if (pos == Equipement::SHIELD || pos == Equipement::SHIELD2) + out_stream << "ShieldItemLabel"; + if (pos == Equipement::GLOVES) + out_stream << "GlovesItemLabel"; + if (pos == Equipement::RING_LEFT) + out_stream << "RingLeftLabel"; + if (pos == Equipement::RING_RIGHT) + out_stream << "RingRightItemLabel"; + if (pos == Equipement::AMULET) + out_stream << "AmuletItemLabel"; + if (pos>= Equipement::BIG_ITEMS && pos < Equipement::MEDIUM_ITEMS) { - short pos= m_document->getDetailedItemPos(); - DEBUG5("setting tool tip for item at %i",pos); - CEGUI::WindowManager& win_mgr = CEGUI::WindowManager::getSingleton(); - CEGUI::Window* label; - ostringstream out_stream; + out_stream << "BigItem"<<pos-Equipement::BIG_ITEMS<<"Label"; + } + if (pos>= Equipement::MEDIUM_ITEMS && pos < Equipement::SMALL_ITEMS) + { + out_stream << "MediumItem"<<pos-Equipement::MEDIUM_ITEMS<<"Label"; + } + if (pos>= Equipement::SMALL_ITEMS) + { + out_stream << "SmallItem"<<pos-Equipement::SMALL_ITEMS<<"Label"; + } + label = win_mgr.getWindow(out_stream.str()); + + + + std::string msg =item->getDescription(); + label->setTooltipText(msg); + + DEBUG5("Label: %s \ndescription: \n%s",out_stream.str().c_str(),msg.c_str()); + + if (pos>= Equipement::SMALL_ITEMS && pos< Equipement::SMALL_ITEMS+10) + { + // Item befindet sich im Guertel out_stream.str(""); - if (pos == Equipement::ARMOR) - out_stream << "ArmorItemLabel"; - if (pos == Equipement::WEAPON || pos == Equipement::WEAPON2) - out_stream << "WeaponItemLabel"; - if (pos == Equipement::HELMET) - out_stream << "HelmetItemLabel"; - if (pos == Equipement::SHIELD || pos == Equipement::SHIELD2) - out_stream << "ShieldItemLabel"; - if (pos == Equipement::GLOVES) - out_stream << "GlovesItemLabel"; - if (pos == Equipement::RING_LEFT) - out_stream << "RingLeftLabel"; - if (pos == Equipement::RING_RIGHT) - out_stream << "RingRightItemLabel"; - if (pos == Equipement::AMULET) - out_stream << "AmuletItemLabel"; - if (pos>= Equipement::BIG_ITEMS && pos < Equipement::MEDIUM_ITEMS) - { - out_stream << "BigItem"<<pos-Equipement::BIG_ITEMS<<"Label"; - } - if (pos>= Equipement::MEDIUM_ITEMS && pos < Equipement::SMALL_ITEMS) - { - out_stream << "MediumItem"<<pos-Equipement::MEDIUM_ITEMS<<"Label"; - } - if (pos>= Equipement::SMALL_ITEMS) - { - out_stream << "SmallItem"<<pos-Equipement::SMALL_ITEMS<<"Label"; - } + out_stream << "InventoryItem"<<pos-Equipement::SMALL_ITEMS; label = win_mgr.getWindow(out_stream.str()); - - - std::string msg =m_document->getDetailedItem()->getDescription(); label->setTooltipText(msg); - - if (pos>= Equipement::SMALL_ITEMS && pos< Equipement::SMALL_ITEMS+10) - { - // Item befindet sich im Guertel - out_stream.str(""); - out_stream << "InventoryItem"<<pos-Equipement::SMALL_ITEMS; - label = win_mgr.getWindow(out_stream.str()); - label->setTooltipText(msg); - } } + } -void MainWindow::updateAbilityTooltip() +void MainWindow::updateAbilityTooltip(unsigned int pos) { - if (m_document->getAbilityPos()!=Action::NOACTION) + + if (pos!=Action::NOACTION) { - DEBUG("update tooltip for %i", m_document->getAbilityPos()); + DEBUG("update tooltip for %i", pos); CEGUI::WindowManager& win_mgr = CEGUI::WindowManager::getSingleton(); CEGUI::Window* label; ostringstream out_stream; out_stream.str(""); - out_stream << Action::getActionInfo(m_document->getAbilityPos())->m_enum_name << "Label"; + out_stream << Action::getActionInfo((Action::ActionType) pos)->m_enum_name << "Label"; label = win_mgr.getWindow(out_stream.str()); - std::string tooltip = m_document->getAbilityDescription(); + std::string tooltip = m_document->getAbilityDescription((Action::ActionType) pos); label->setTooltipText(tooltip); } + } void MainWindow::updateObjectInfo() { + Player* player = m_document->getLocalPlayer(); + // Ogre Name des Objektes auf das der Mauszeiger zeigt std::string objname = ""; @@ -2921,12 +2908,12 @@ map<int,string>* objects = m_scene->getObjects(); map<int,string>::iterator it; - // minimale Distanz eine Objektes im Kamerastrahl + // minimale Distanz eines Objektes im Kamerastrahl float mindist = 1000000; for (it = objects->begin();it != objects->end();++it) { - if (m_document->getMainPlayer()->getId() == it->first) + if (m_document->getLocalPlayer()->getId() == it->first) { // Spieler selbst ueberspringen continue; @@ -2964,6 +2951,7 @@ std::string name; std::ostringstream string_stream; + short rid = player->getGridLocation()->m_region; if (objname!="") { @@ -2982,20 +2970,21 @@ string_stream<<name; // zur ID gehoerendes Objekt - ClientWObject* cwo; - map<int, ClientWObject*>::iterator it2 =m_document->getObjects()->find(id); - if (it2 != m_document->getObjects()->end()) + ServerWObject* cwo; + cwo = m_document->getWorld()->getSWObject(id,rid); + Creature* cr; + + if (cwo !=0) { // Objekt existiert m_document->getGUIState()->m_cursor_object_id = id; - cwo = it2->second; if (cwo->getTypeInfo()->m_type != WorldObject::TypeInfo::TYPE_FIXED_OBJECT) { - // Objekt ist ein Lebewesen - // Lebenspunkte anfuegen - - string_stream << " " << max(0,(int) (cwo->getHealthPerc()*100)) <<"%"; + // Objekt ist ein Lebewesen + // Lebenspunkte anfuegen + cr = static_cast<Creature*>(cwo); + string_stream << " " << max(0,(int) (cr->getDynAttr()->m_health / cr->getBaseAttrMod()->m_max_health*100)) <<"%"; } } else @@ -3043,9 +3032,9 @@ stream >> id; string_stream<<name; - map<int,DropItem>::iterator it3 =m_document->getDropItems()->find(id); - - if (it3 != m_document->getDropItems()->end()) + Item* itm = player->getRegion()->getItem(id); + + if (itm !=0) { // Objekt existiert m_document->getGUIState()->m_cursor_item_id = id; @@ -3104,8 +3093,8 @@ int y =evt.state.Y.abs; DEBUG5("maus %i %i",x,y); - ClientMPlayer* m_pl = m_document->getMainPlayer(); - if (m_pl!=0) + Player* player = m_document->getLocalPlayer(); + if (player!=0) { // Spiel ist mit Server verbunden @@ -3113,7 +3102,7 @@ // TODO: vernuenftige Vorgehensweise um Klicks auf GUI Elemente zu erkennen if (not m_gui_hit && not ret) { - if (m_document->getMainPlayer()->m_equipement->getItem(Equipement::CURSOR_ITEM)!=0) + if (player->getEquipement()->getItem(Equipement::CURSOR_ITEM)!=0) { // Spieler hat Item in der Hand, fallen lassen m_document->dropCursorItem(); @@ -3122,8 +3111,8 @@ { // Koordinaten des Spielers - float mpx=m_pl->getGeometry()->m_shape.m_coordinate_x; - float mpy=m_pl->getGeometry()->m_shape.m_coordinate_y; + float mpx=player->getGeometry()->m_shape.m_coordinate_x; + float mpy=player->getGeometry()->m_shape.m_coordinate_y; // Position des Mausklicks relativ zum Viewport Ogre::Viewport* viewport = m_scene->getViewport(); @@ -3156,8 +3145,8 @@ DEBUG5("Punkt in Spielkoordinaten %f %f",gx,gy); // Koordinaten relativ zum Spieler - gx -= mpx; - gy -= mpy; + //gx -= mpx; + //gy -= mpy; if (btn == OIS::MB_Left) { @@ -3306,9 +3295,9 @@ if (we.button == CEGUI::LeftButton) { DEBUG("left button pressed on skill %i",id); - if (m_document->getMainPlayer()) + if (m_document->getLocalPlayer()) { - if (m_document->getMainPlayer()->checkAbility((Action::ActionType) id)) + if (m_document->getLocalPlayer()->checkAbility((Action::ActionType) id)) { // Faehigkeit ist verfuegbar, setzen m_document->setLeftAction((Action::ActionType) id); @@ -3337,20 +3326,23 @@ bool MainWindow::onItemHover(const CEGUI::EventArgs& evt) { + const CEGUI::MouseEventArgs& we = static_cast<const CEGUI::MouseEventArgs&>(evt); unsigned int id = we.window->getID(); - DEBUG5("mouse entered Item %i",id); - m_document->requestItemDetailedInfo((short) id); + updateItemTooltip(id); + } bool MainWindow::onAbilityHover(const CEGUI::EventArgs& evt) { + const CEGUI::MouseEventArgs& we = static_cast<const CEGUI::MouseEventArgs&>(evt); unsigned int id = we.window->getID(); DEBUG5("mouse entered Ability %i",id); - m_document->requestAbilityDamage((Action::ActionType) id); + updateAbilityTooltip(id); + } bool MainWindow::onIncreaseAttributeButtonClicked(const CEGUI::EventArgs& evt) @@ -3407,39 +3399,32 @@ { DEBUG("start single player game"); // Spieler ist selbst der Host - m_document->getNetworkInfo()->m_host = true; - // Server laeuft auf dem eigenen Rechner - strcpy(m_document->getNetworkInfo()->m_server_ip,"127.0.0.1"); - + m_document->setServer(true); + // Verbindung aufbauen - m_document->setState(Document::START_SERVER); + m_document->setState(Document::START_GAME); } bool MainWindow::onStartMultiPlayer(const CEGUI::EventArgs& evt) { DEBUG("start multi player game"); - // Spieler ist selbst der Host - m_document->getNetworkInfo()->m_host = false; - - // Server laeuft auf dem entferntem Rechner - // IP setzen... - strcpy(m_document->getNetworkInfo()->m_server_ip,"127.0.0.1");; + + m_document->setServer(false); + // Verbindung aufbauen - m_document->setState(Document::CONNECT_REQUEST); + m_document->setState(Document::START_GAME); } bool MainWindow::onStartMultiPlayerHost(const CEGUI::EventArgs& evt) { DEBUG("start single player game"); // Spieler ist selbst der Host - m_document->getNetworkInfo()->m_host = true; - - // Server laeuft auf dem eigenen Rechner - strcpy(m_document->getNetworkInfo()->m_server_ip,"127.0.0.1"); - + m_document->setServer(true); + + // Verbindung aufbauen - m_document->setState(Document::START_SERVER); + m_document->setState(Document::START_GAME); }
--- a/src/gui/mainwindow.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gui/mainwindow.h Fri Sep 19 11:03:22 2008 +0000 @@ -22,7 +22,8 @@ #include "document.h" #include "scene.h" -#include "../shared/gettext.h" +#include "gettext.h" +#include "player.h" // Sample sub-class for ListboxTextItem that auto-sets the selection brush // image. This saves doing it manually every time in the code. @@ -173,16 +174,17 @@ void updateSkilltree(); /** - * \fn void updateItemTooltip() + * \fn void updateItemTooltip(unsigned int pos) * \brief Aktualisiert den Tooltip fuer das Item ueber dem die Maus ist + * \param pos Nummer des zu aktualisierenden Items */ - void updateItemTooltip(); + void updateItemTooltip(unsigned int pos); /** - * \fn void updateAbilityTooltip() + * \fn void updateAbilityTooltip(unsigned int pos) * \brief Aktualisiert den Tooltip fuer die Faehigkeit ueber der die Maus ist */ - void updateAbilityTooltip(); + void updateAbilityTooltip(unsigned int pos); /** * \fn void updateObjectInfo()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gui/ogre.cfg Fri Sep 19 11:03:22 2008 +0000 @@ -0,0 +1,7 @@ +Render System=OpenGL Rendering Subsystem + +[OpenGL Rendering Subsystem] +FSAA=0 +Full Screen=No +RTT Preferred Mode=PBuffer +Video Mode=940 x 705
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gui/plugins.cfg Fri Sep 19 11:03:22 2008 +0000 @@ -0,0 +1,11 @@ +# Defines plugins to load + +# Define plugin folder +PluginFolder=/usr/lib/OGRE + +# Define D3D rendering implementation plugin +Plugin=RenderSystem_GL.so +Plugin=Plugin_ParticleFX.so +Plugin=Plugin_BSPSceneManager.so +Plugin=Plugin_OctreeSceneManager.so +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gui/plugins_win.cfg Fri Sep 19 11:03:22 2008 +0000 @@ -0,0 +1,14 @@ +# Defines plugins to load + +# Define plugin folder +PluginFolder=.\obj\Debug + +# Define plugins +Plugin=RenderSystem_Direct3D9_d +Plugin=RenderSystem_GL_d +Plugin=Plugin_ParticleFX_d +Plugin=Plugin_BSPSceneManager_d +Plugin=Plugin_OctreeSceneManager_d +Plugin=Plugin_CgProgramManager_d + +
--- a/src/gui/scene.cpp Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gui/scene.cpp Fri Sep 19 11:03:22 2008 +0000 @@ -26,6 +26,8 @@ m_projectiles = new map<int,std::string>; registerMeshes(); + + m_region_id = -1; } @@ -100,9 +102,9 @@ registerItem("leath_arm","armor.mesh"); registerItem("tiled_arm","armor.mesh"); - registerItem("heavy_arm","armor.mesh"); - - registerItem("wood_sh","shield.mesh"); + registerItem("heavy_arm","armor.mesh"); + + registerItem("wood_sh","shield.mesh"); registerItem("iron_sh","shield.mesh"); registerItem("steel_hlm","helmet.mesh"); @@ -192,50 +194,94 @@ void Scene::update(float ms) { + DEBUG5("update scene"); + // Spielerobjekt - ClientMPlayer* player = m_document->getMainPlayer(); + Player* player = m_document->getLocalPlayer(); + + if (player ==0) + return; + // Nummer der region in der sich der Spieler befindet + short region_nr = player->getGridLocation()->m_region; + + + + + if (region_nr != m_region_id) + { + // Spieler hat eine neue Region betreten + m_region_id = region_nr; + if (player->getState() == WorldObject::STATE_ACTIVE) + { + // Szene komplett neu aufbauen + createScene(); + + m_document->setModified(m_document->getModified() & ~Document::REGION_MODIFIED); + } + else + { + // Spieler ist der Region noch nicht aktiviert + return; + } + } + // Koordinaten des Spielers float x=player->getGeometry()->m_shape.m_coordinate_x; float y=player->getGeometry()->m_shape.m_coordinate_y; + // Kamera auf Spieler ausrichten m_camera->setPosition(Ogre::Vector3(x*50, 1000, y*50+300)); m_camera->lookAt(Ogre::Vector3(x*50,0,y*50)); - if (m_document->getModified() & Document::REGION_MODIFIED) - { - // Spieler hat eine neue Region betreten - - // Szene komplett neu aufbauen - createScene(); - - m_document->setModified(m_document->getModified() & ~Document::REGION_MODIFIED); - } - + // alle Objekte aktualisieren updateObjects(); + + DEBUG5("update items"); // alle Items aktualisieren updateItems(); + updateProjectiles(); } void Scene::updateObjects() { + DEBUG5("update objects"); + // Spielerobjekt + Player* player = m_document->getLocalPlayer(); + // aktuelle Liste der Objekte holen - map<int, ClientWObject*>* objs; - map<int, ClientWObject*>::iterator it; - objs = m_document->getObjects(); - ClientWObject* obj; - + float x,y; + x = player->getGeometry()->m_shape.m_coordinate_x; + y = player->getGeometry()->m_shape.m_coordinate_y; + + list<ServerWObject*> objs; + ServerWObject* obj; + list<ServerWObject*>::iterator it; + Shape s; + s.m_coordinate_x = x; + s.m_coordinate_y = y; + s.m_type = Shape::RECT; + s.m_extent_x = 20; + s.m_extent_y = 20; + + ServerWObject* wo, *cwo; + Creature* cr; + + player->getRegion()->getSWObjectsInShape(&s,&objs, WorldObject::Geometry::LAYER_ALL,WorldObject::CREATURE); + player->getRegion()->getSWObjectsInShape(&s,&objs, WorldObject::Geometry::LAYER_ALL,WorldObject::DEAD); + + // Liste der aktuell in der Szene vorhanden Objekte durchmustern map<int, string>::iterator it2; int id; for (it2 = m_objects->begin();it2 != m_objects->end();) { id = it2->first; - if (objs->find(id) == objs->end()) + if (player->getRegion()->getSWObject(id) == 0) { // Objekt existiert nicht in der Liste im Dokument @@ -252,9 +298,9 @@ } // aller Objekte im Dokument durchmustern - for (it = objs->begin();it != objs->end(); ++it) + for (it = objs.begin();it != objs.end(); ++it) { - obj = it->second; + obj = *it; // Darstellung fuer das Objekt aktualisieren updateObject(obj); } @@ -262,10 +308,12 @@ void Scene::updateItems() { + Player* player = m_document->getLocalPlayer(); + // Liste der aktuell in der Szene vorhandenen Items durchmustern - map<int,DropItem>* itms; - map<int,DropItem>::iterator it; - itms = m_document->getDropItems(); + map<int,DropItem*>* itms; + map<int,DropItem*>::iterator it; + itms = player->getRegion()->getDropItems(); DropItem* di; map<int, string>::iterator it2; @@ -295,7 +343,7 @@ // Liste der Objekte im Dokument durchmustern for (it = itms->begin();it != itms->end(); ++it) { - di = &(it->second); + di = (it->second); // Name des Items std::string name = di->getNameId(); @@ -310,7 +358,7 @@ } } -void Scene::updateObject(ClientWObject* obj) +void Scene::updateObject(ServerWObject* obj) { std::string name = obj->getNameId(); DEBUG5("handle obj %s",name.c_str()); @@ -355,82 +403,88 @@ std::string mod_name; int i; Ogre::ParticleSystem *mod_part; - // Bitmaske welche Mods gesetzt sind - char mask = obj->m_status_mods; - + + // Animation anpassen // Status der Animation Ogre::AnimationState* anim; - Ogre::AnimationStateSet* anim_set; - + Ogre::AnimationStateSet* anim_set; + + DEBUG5("animation"); // Aktion des Objeks - Action::ActionType act = obj->getAction()->m_type; - Action::ActionInfo* aci = Action::getActionInfo(act); - - // Name der Animation - std::vector<std::string>& animations = aci->m_animation[obj->getAction()->m_action_equip]; - std::string anim_name = ""; - if (!animations.empty()) - { - anim_name = animations[obj->getAction()->m_animation_number % animations.size()]; - } - - obj_ent = m_scene_manager->getEntity(name); - if (obj_ent == 0) - { - ERRORMSG("object %s not found",name.c_str()); - } - if (anim_name != "") + Creature* cr=0; + if (obj->getTypeInfo()->m_type != WorldObject::TypeInfo::TYPE_FIXED_OBJECT) { - // status der Animation setzen - //Iterator ueber alle aktiven Animationen - anim_set = obj_ent->getAllAnimationStates(); - - // Testen ob das Objekt animiert ist - if (anim_set != 0) - { - - Ogre::ConstEnabledAnimationStateIterator anim_it = anim_set->getEnabledAnimationStateIterator(); - - //deaktiviert alle animationen, die gerade nicht verwendet werden - while(anim_it.hasMoreElements()) - { - anim = anim_it.getNext(); - //TODO - //if(anim->getAnimationName!=anim_name) - anim->setEnabled(false); - } - - try - { - if (anim_set->hasAnimationState(anim_name)) - { - anim = obj_ent->getAnimationState(anim_name); - anim->setEnabled(true); - - // prozentsatz zu dem die Animation fortgeschritten ist - float perc = obj->getAction()->m_elapsed_time / obj->getAction()->m_time ; - DEBUG5("setting animation %s to %f",anim_name.c_str(),perc); - anim->setTimePosition(perc); - } - } - catch (Ogre::Exception e) - { - ERRORMSG(e.what()); - } - } + cr = static_cast<Creature*>(obj); + Action::ActionType act = cr->getAction()->m_type; + Action::ActionInfo* aci = Action::getActionInfo(act); + // Name der Animation + std::vector<std::string>& animations = aci->m_animation[cr->getActionEquip()]; + std::string anim_name = ""; + if (!animations.empty()) + { + anim_name = animations[cr->getAction()->m_animation_number % animations.size()]; + } + + obj_ent = m_scene_manager->getEntity(name); + if (obj_ent == 0) + { + ERRORMSG("object %s not found",name.c_str()); + } + + if (anim_name != "") + { + // status der Animation setzen + //Iterator ueber alle aktiven Animationen + anim_set = obj_ent->getAllAnimationStates(); + + // Testen ob das Objekt animiert ist + if (anim_set != 0) + { + + Ogre::ConstEnabledAnimationStateIterator anim_it = anim_set->getEnabledAnimationStateIterator(); + + //deaktiviert alle animationen, die gerade nicht verwendet werden + while(anim_it.hasMoreElements()) + { + anim = anim_it.getNext(); + //TODO + //if(anim->getAnimationName!=anim_name) + anim->setEnabled(false); + } + + try + { + if (anim_set->hasAnimationState(anim_name)) + { + anim = obj_ent->getAnimationState(anim_name); + anim->setEnabled(true); + + // prozentsatz zu dem die Animation fortgeschritten ist + float perc = cr->getAction()->m_elapsed_time / cr->getAction()->m_time ; + DEBUG5("setting animation %s to %f",anim_name.c_str(),perc); + anim->setTimePosition(perc); + } + } + catch (Ogre::Exception e) + { + ERRORMSG(e.what()); + } + } + } + else + { + //keine Animation + } } - else - { - //keine Animation - } - + + DEBUG5("extra meshes"); // angehaengte Meshes an die verwendeten Items anpassen if (obj->getTypeInfo()->m_type == WorldObject::TypeInfo::TYPE_PLAYER) { // Objekt ist ein Spieler - ClientMPlayer* cmp = static_cast<ClientMPlayer*>(obj); - Equipement* equ = cmp->m_equipement; + Player* cmp = static_cast<Player*>(obj); + Equipement* equ = cmp->getEquipement(); // Schleife ueber alle angehaengten Entities Ogre::Entity* attch_ent; @@ -502,7 +556,7 @@ { // Objekt befindet sich im Zielzustand nicht am Knochen - DEBUG("removed mesh %s from bone %s",old_ent_name.c_str(),bone.c_str()); + DEBUG5("removed mesh %s from bone %s",old_ent_name.c_str(),bone.c_str()); // Mesh entfernen obj_ent->detachObjectFromBone(attch_ent); m_scene_manager->destroyEntity(attch_ent); @@ -513,7 +567,7 @@ for (jt = goal_atch.begin(); jt != goal_atch.end();++jt) { bone = jt->first; - DEBUG("attached mesh %s at bone %s",jt->second.c_str(),bone.c_str()); + DEBUG5("attached mesh %s at bone %s",jt->second.c_str(),bone.c_str()); attch_ent = m_scene_manager->createEntity(name+bone,jt->second); obj_ent->attachObjectToBone(bone,attch_ent); @@ -523,42 +577,47 @@ } } - + DEBUG5("particle"); //zeigt an ob ein Partikelsystem sichtbar is bool vis; - - for (i=0;i<NR_STATUS_MODS;i++) + if (cr !=0) { - num.str(""); - num <<"mod"<< i; - - mod_name = name + num.str(); - - mod_part = m_scene_manager->getParticleSystem(mod_name); - vis = mod_part->isVisible(); - - if ( ((mask & (1 << i)) !=0) ^ vis) - { - mod_part->setVisible(!vis); - } - } + // Feld das angibt, welche Mods gesetzt sind + float * status_mods = cr->getDynAttr()->m_status_mod_time; - // weitere Effekte anpassen - mask = obj->m_effects; - - for (i=0;i<NR_EFFECTS;i++) - { - num.str(""); - num <<"effect"<< i; - - mod_name = name + num.str(); - - mod_part = m_scene_manager->getParticleSystem(mod_name); - vis = mod_part->isVisible(); - - if ( ((mask & (1 << i)) !=0) ^ vis) + for (i=0;i<NR_STATUS_MODS;i++) { - mod_part->setVisible(!vis); + num.str(""); + num <<"mod"<< i; + + mod_name = name + num.str(); + + mod_part = m_scene_manager->getParticleSystem(mod_name); + vis = mod_part->isVisible(); + + if ( (status_mods[i]>0) ^ vis) + { + mod_part->setVisible(!vis); + } + } + + // weitere Effekte anpassen + float* effects = cr->getDynAttr()->m_effect_time; + + for (i=0;i<NR_EFFECTS;i++) + { + num.str(""); + num <<"effect"<< i; + + mod_name = name + num.str(); + + mod_part = m_scene_manager->getParticleSystem(mod_name); + vis = mod_part->isVisible(); + + if ( (effects[i]>0) ^ vis) + { + mod_part->setVisible(!vis); + } } } } @@ -575,6 +634,7 @@ void Scene::createObject(WorldObject* obj,std::string& name, bool is_static) { + DEBUG5("creating object %s",name.c_str()); std::string node_name = name + "Node"; // Koordinaten des Objektes @@ -665,7 +725,6 @@ part = m_scene_manager->createParticleSystem(name+"effect0", "Hit"); obj_node->attachObject(part); } - } void Scene::createItem(DropItem* di, std::string& name) @@ -707,9 +766,11 @@ void Scene::updateProjectiles() { - map<int,Projectile*>* projectiles; - map<int,Projectile*>::iterator it; - projectiles = m_document->getProjectiles(); + Player* player = m_document->getLocalPlayer(); + + map<int,DmgProjectile*>* projectiles; + map<int,DmgProjectile*>::iterator it; + projectiles = player->getRegion()->getProjectiles(); Projectile* pr; map<int, string>::iterator it2; @@ -997,20 +1058,32 @@ void Scene::createScene() { + DEBUG5("create Scene"); // alle bisherigen Objekte aus der Szene loeschen m_scene_manager->clearScene(); clearObjects(); // Liste der statischen Objekte - map<int,WorldObject*>* stat_objs = (m_document->getRegionData()->m_static_objects); - map<int,WorldObject*>::iterator it; + list<ServerWObject*> stat_objs; + + Region* region = m_document->getLocalPlayer()->getRegion(); + + Shape s; + s.m_coordinate_x = 0; + s.m_coordinate_y = 0; + s.m_type = Shape::RECT; + s.m_extent_x = 10000; + s.m_extent_y = 10000; + + region->getSWObjectsInShape(&s,&stat_objs, WorldObject::Geometry::LAYER_ALL,WorldObject::FIXED); + list<ServerWObject*>::iterator it; std::string name; - for (it = stat_objs->begin(); it !=stat_objs->end();++it) + for (it = stat_objs.begin(); it !=stat_objs.end();++it) { - name = it->second->getNameId(); + name = (*it)->getNameId(); // Objekt in der Szene erzeugen - createObject(it->second,name,true); + createObject((*it),name,true); } @@ -1021,6 +1094,7 @@ void Scene::insertTiles() { + /* // Matrix der Tiles Matrix2d<char>* mat = m_document->getRegionData()->m_tiles; @@ -1059,6 +1133,7 @@ } } + */ }
--- a/src/gui/scene.h Wed Sep 17 11:01:52 2008 +0000 +++ b/src/gui/scene.h Fri Sep 19 11:03:22 2008 +0000 @@ -6,8 +6,8 @@ #include <string> #include "document.h" +#include "serverwobject.h" // TODO : include anpassen (es wird nur ein Spieler allgemein benoetigt) -#include "clientmplayer.h" using namespace std; @@ -133,10 +133,10 @@ void updateObjects(); /** - * \fn void updateObject(ClientWObject* obj); + * \fn void updateObject(ServerWObject* obj); * \brief Fuegt das Objekt in die Szene ein */ - void updateObject(ClientWObject* obj); + void updateObject(ServerWObject* obj); /** @@ -350,6 +350,12 @@ * \brief Dokument, dessen Daten dargestellt werden sollen */ Document* m_document; + + /** + * \var short m_region_id + * \brief ID der Region, die gerade angezeigt wird + */ + short m_region_id; /** * \var Ogre::RenderWindow* m_window