From 210123ac3334650e92aa95b9f4aa05f023494623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Mon, 27 Aug 2007 14:15:03 +0000 Subject: [PATCH] * improved minimap * live event handling on adventure map * added CCallback * minor stuff (as usual) --- CAdvmapInterface.cpp | 15 +++++++++++++++ CAdvmapInterface.h | 3 ++- CAmbarCendamo.cpp | 8 +++----- CCallback.cpp | 7 +++++++ CCallback.h | 12 ++++++++++++ CGameInterface.cpp | 18 +++++++++++++++++- CGameInterface.h | 8 ++++++++ CGameState.h | 7 +++++-- h3m.txt | Bin 108258 -> 107152 bytes map.cpp | 7 +++---- map.h | 1 + 11 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 CCallback.cpp create mode 100644 CCallback.h diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index fe7baacf2..bb17440f1 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -268,6 +268,10 @@ void CMinimap::clickRight (tribool down) {} void CMinimap::clickLeft (tribool down) { + if (down && (!pressedL)) + MotionInterested::activate(); + else if (!down) + MotionInterested::deactivate(); ClickableL::clickLeft(down); if (!((bool)down)) return; @@ -300,14 +304,25 @@ void CMinimap::hover (bool on) else if (LOCPLINT->adventureInt->statusbar.current==statusbarTxt) LOCPLINT->adventureInt->statusbar.clear(); } +void CMinimap::mouseMoved (SDL_MouseMotionEvent & sEvent) +{ + if (pressedL) + { + clickLeft(true); + } +} void CMinimap::activate() { ClickableL::activate(); ClickableR::activate(); Hoverable::activate(); + if (pressedL) + MotionInterested::activate(); } void CMinimap::deactivate() { + if (pressedL) + MotionInterested::deactivate(); ClickableL::deactivate(); ClickableR::deactivate(); Hoverable::deactivate(); diff --git a/CAdvmapInterface.h b/CAdvmapInterface.h index eb943cbcd..b048c6076 100644 --- a/CAdvmapInterface.h +++ b/CAdvmapInterface.h @@ -99,7 +99,7 @@ public: void show(); //shows statusbar (with current text) }; class CMinimap - : public ClickableL, public ClickableR, public Hoverable, public virtual CIntObject + : public ClickableL, public ClickableR, public Hoverable, public MotionInterested, public virtual CIntObject { public: CDefHandler * radar; //radar.def; TODO: radars for maps with custom dimensions @@ -117,6 +117,7 @@ public: void clickRight (tribool down); void clickLeft (tribool down); void hover (bool on); + void mouseMoved (SDL_MouseMotionEvent & sEvent); void activate(); // makes button active void deactivate(); // makes button inactive (but don't deletes) }; diff --git a/CAmbarCendamo.cpp b/CAmbarCendamo.cpp index 98dd7c3cc..b010ff527 100644 --- a/CAmbarCendamo.cpp +++ b/CAmbarCendamo.cpp @@ -132,10 +132,9 @@ void CAmbarCendamo::deh3m() } - - i++; //unknown - - if(bufor[i++]!=0xff) + map.players[pom].p8= bufor[i++]; + map.players[pom].p9= bufor[i++]; + if(map.players[pom].p9!=0xff) { map.players[pom].mainHeroPortrait = bufor[i++]; int nameLength = bufor[i++]; @@ -144,7 +143,6 @@ void CAmbarCendamo::deh3m() map.players[pom].mainHeroName+=bufor[i++]; } - //i++; //unknown byte if(map.version != Eformat::RoE) { i++; ////unknown byte diff --git a/CCallback.cpp b/CCallback.cpp new file mode 100644 index 000000000..9ebb08fab --- /dev/null +++ b/CCallback.cpp @@ -0,0 +1,7 @@ +#include "stdafx.h" +#include "CCallback.h" + +bool CCallback::moveHero(int ID, int3 destPoint) +{ + return false; +} \ No newline at end of file diff --git a/CCallback.h b/CCallback.h new file mode 100644 index 000000000..21cb58a6f --- /dev/null +++ b/CCallback.h @@ -0,0 +1,12 @@ +#ifndef CCALLBACK_H +#define CCALLBACK_H +class CGameState; +class CCallback +{ +protected: + CGameState * gs; +public: + bool moveHero(int ID, int3 destPoint); +}; + +#endif //CCALLBACK_H \ No newline at end of file diff --git a/CGameInterface.cpp b/CGameInterface.cpp index f3fcddaba..adc903755 100644 --- a/CGameInterface.cpp +++ b/CGameInterface.cpp @@ -81,6 +81,15 @@ void KeyInterested::deactivate() LOCPLINT-> keyinterested.erase(std::find(LOCPLINT->keyinterested.begin(),LOCPLINT->keyinterested.end(),this)); } +void MotionInterested::activate() +{ + LOCPLINT->motioninterested.push_back(this); +} +void MotionInterested::deactivate() +{ + LOCPLINT-> + motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this)); +} CPlayerInterface::CPlayerInterface(int Player, int serial) { playerID=Player; @@ -111,7 +120,7 @@ void CPlayerInterface::yourTurn() CGI->screenh->updateScreen(); LOCPLINT->adventureInt->updateScreen = false; - if(SDL_PollEvent(&sEvent)) //wait for event... + while (SDL_PollEvent(&sEvent)) //wait for event... { handleEvent(&sEvent); } @@ -259,6 +268,13 @@ void CPlayerInterface::handleEvent(SDL_Event *sEvent) hoverable[i]->hover(false); } } + for(int i=0; ipos,sEvent->motion.x,sEvent->motion.y)) + { + motioninterested[i]->mouseMoved(sEvent->motion); + } + } if(sEvent->motion.x<15) { LOCPLINT->adventureInt->scrollingLeft = true; diff --git a/CGameInterface.h b/CGameInterface.h index 7ae7cf9fe..f0b2943a5 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -64,6 +64,13 @@ public: virtual void activate()=0; virtual void deactivate()=0; }; +class MotionInterested: public virtual CIntObject +{ +public: + virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0; + virtual void activate()=0; + virtual void deactivate()=0; +}; class CGameInterface { public: @@ -88,6 +95,7 @@ public: std::vector rclickable; std::vector hoverable; std::vector keyinterested; + std::vector motioninterested; void yourTurn(); void handleEvent(SDL_Event * sEvent); diff --git a/CGameState.h b/CGameState.h index de24ba28a..b97138644 100644 --- a/CGameState.h +++ b/CGameState.h @@ -14,7 +14,7 @@ #include "CDefObjInfoHandler.h" #include "CLodHandler.h" #include "CTownHandler.h" - +class CCallback; struct PlayerState { public: @@ -27,9 +27,12 @@ public: class CGameState { -public: int currentPlayer; std::map players; //color <-> playerstate +public: + friend CCallback; + friend int _tmain(int argc, _TCHAR* argv[]); + CCallback * cb; //for communication between PlayerInterface/AI and GameState }; #endif //CGAMESTATE_H \ No newline at end of file diff --git a/h3m.txt b/h3m.txt index b0b55f3541902ece500b50c61cde68fede89a1ac..33ea5f961b10799709aa4b74cf932079ed5d8682 100644 GIT binary patch delta 323 zcmaEKmTkgOwhc_ytO^Xe3<{Gc+K5kfvQ^l0j=i7+_#pHy5@(lS5*$hPt zsSMGKISh#mo15$t7?~3pawb1@Q0FydFox?gnf%qM+dB`aMu8yNQ!2G%_~7QYjeHxdTv%j20fsM7y6g78o^n{Fczl?h{d46U^&^) eUwrbCfGAc|u-xB(QdTn%tGO_6dto4BVJHBND@#-W delta 1198 zcmbVL%}PQ+7(G*2*bl8DS~bu@Bc-lpCPrb9Mn6k86@i(Q>CKBt(jP8*fnb8@4O&Ii zqFvCUWiQbiM6~bBm?3mG%JAJg_nULRIdkqeS8v@P@7)g_@o_J9P(%q?6ksC*hvAx2 znfRzBF@Ro#+!1b-npoksSkrB>BCWB)67`eKw8ryjp1es2VJR8vnuwBqj69AQl_on~ za!tm}w#ACI#^Mq6ud^`KCeLb(7im~(nRan;z|AS`N{=zM$yVju^#`MLI>^xFBn|cm z3E#gG9^unC^|>_sbRFLooke8S_nhx0DMUd3qO^rD5nd!YBqkXlL^#|sbs=Z$>l5^F zKb!aDT;#|p@wSwa!=~T{2&hzItX8C^U9MD#mhhV$#u4B=i&K-+{4%u{*d7`&#nC|Q zb4~AY$Tht~)x2%Pcetjj=x3Et!XCbOYc;N7vNrOPLKa2Ih?RemwPgofDL|^h)KKk| z7z+L)F0)9PC32J{jjT!?ZG>c*YX~}I-XS()q+R@W(=-uY9>d~Wo2h62zw1V_|J2C* p?Njfs3mg~Yv{{T{g*1iA$ diff --git a/map.cpp b/map.cpp index d87a72ad2..36ba48e75 100644 --- a/map.cpp +++ b/map.cpp @@ -89,10 +89,9 @@ CMapHeader::CMapHeader(unsigned char *map) this->players[pom].posOfMainTown.y = map[i++]; this->players[pom].posOfMainTown.z = map[i++]; } - - i++; //unknown byte - int customPortrait = map[i++]; - if (customPortrait != 255) + players[pom].p8= map[i++]; + players[pom].p9= map[i++]; + if(players[pom].p9!=0xff) { players[pom].mainHeroPortrait = map[i++]; int nameLength = map[i++]; diff --git a/map.h b/map.h index 3264b3df3..9e4d0ff7a 100644 --- a/map.h +++ b/map.h @@ -75,6 +75,7 @@ struct SheroName //name of starting hero }; struct PlayerInfo { + int p8, p9; bool canHumanPlay; bool canComputerPlay; unsigned int AITactic; //(00 - random, 01 - warrior, 02 - builder, 03 - explorer)