diff --git a/src/game/collision.cpp b/src/game/collision.cpp index 49981129f..246a42470 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -21,10 +21,6 @@ CCollision::CCollision() m_pSpeedup = 0; m_pFront = 0; } -int CCollision::IsSolid(int x, int y) -{ - return (GetTile(x,y)&COLFLAG_SOLID); -} void CCollision::Init(class CLayers *pLayers) { @@ -113,7 +109,9 @@ int CCollision::GetMapIndex(vec2 PrevPos, vec2 Pos) else dbg_msg("GetMapIndex(","ny*m_Width+nx %d",ny*m_Width+nx);//REMOVE */ if((m_pTiles[ny*m_Width+nx].m_Index >= TILE_THROUGH && m_pTiles[ny*m_Width+nx].m_Index < TILE_TELEIN) || - ((m_pTiles[ny*m_Width+nx].m_Index >TILE_BOOST)&&(m_pTiles[ny*m_Width+nx].m_Index <= TILE_NPH) ) || + ((m_pTiles[ny*m_Width+nx].m_Index >TILE_BOOST)&&(m_pTiles[ny*m_Width+nx].m_Index <= TILE_NPH) ) || + (m_pFront && (m_pFront[ny*m_Width+nx].m_Index >= TILE_THROUGH && m_pFront[ny*m_Width+nx].m_Index < TILE_TELEIN)) || + (m_pFront && ((m_pFront[ny*m_Width+nx].m_Index >TILE_BOOST)&&(m_pFront[ny*m_Width+nx].m_Index <= TILE_NPH))) || (m_pTele && (m_pTele[ny*m_Width+nx].m_Type == TILE_TELEIN || m_pTele[ny*m_Width+nx].m_Type == TILE_TELEOUT)) || (m_pSpeedup && m_pSpeedup[ny*m_Width+nx].m_Force > 0)) { @@ -133,9 +131,11 @@ int CCollision::GetMapIndex(vec2 PrevPos, vec2 Pos) nx = clamp((int)Tmp.x/32, 0, m_Width-1); ny = clamp((int)Tmp.y/32, 0, m_Height-1); if((m_pTiles[ny*m_Width+nx].m_Index >= TILE_THROUGH && m_pTiles[ny*m_Width+nx].m_Index < TILE_TELEIN) || - ((m_pTiles[ny*m_Width+nx].m_Index >TILE_BOOST)&&(m_pTiles[ny*m_Width+nx].m_Index <= TILE_NPH) ) || - (m_pTele && (m_pTele[ny*m_Width+nx].m_Type == TILE_TELEIN || m_pTele[ny*m_Width+nx].m_Type == TILE_TELEOUT)) || - (m_pSpeedup && m_pSpeedup[ny*m_Width+nx].m_Force > 0)) + ((m_pTiles[ny*m_Width+nx].m_Index >TILE_BOOST)&&(m_pTiles[ny*m_Width+nx].m_Index <= TILE_NPH) ) || + (m_pFront && (m_pFront[ny*m_Width+nx].m_Index >= TILE_THROUGH && m_pFront[ny*m_Width+nx].m_Index < TILE_TELEIN)) || + (m_pFront && ((m_pFront[ny*m_Width+nx].m_Index >TILE_BOOST)&&(m_pFront[ny*m_Width+nx].m_Index <= TILE_NPH))) || + (m_pTele && (m_pTele[ny*m_Width+nx].m_Type == TILE_TELEIN || m_pTele[ny*m_Width+nx].m_Type == TILE_TELEOUT)) || + (m_pSpeedup && m_pSpeedup[ny*m_Width+nx].m_Force > 0)) { return ny*m_Width+nx; } @@ -159,6 +159,13 @@ int CCollision::GetCollisionDDRace(int Index) return 0; return m_pTiles[Index].m_Index; } +int CCollision::GetCollisionDDRace2(int Index) +{ + /*dbg_msg("GetCollisionDDRace2","m_pFront[%d].m_Index = %d",Index,m_pFront[Index].m_Index);//Remove*/ + if(Index < 0) + return 0; + return m_pFront[Index].m_Index; +} int CCollision::GetTile(int x, int y) { @@ -173,9 +180,9 @@ int CCollision::GetTile(int x, int y) else return 0; } -int CCollision::Entitiy(int x, int y) +int CCollision::Entity(int x, int y, bool Front) { - int Index = m_pTiles[y*m_Width+x].m_Index; + int Index = Front?m_pFront[y*m_Width+x].m_Index:m_pTiles[y*m_Width+x].m_Index; return Index-ENTITY_OFFSET; } void CCollision::SetCollisionAt(float x, float y, int flag) @@ -379,6 +386,11 @@ bool CCollision::TestBox(vec2 Pos, vec2 Size) return false; } +int CCollision::IsSolid(int x, int y) +{ + return (GetTile(x,y)&COLFLAG_SOLID); +} + int CCollision::IsNoLaser(int x, int y) { return (CCollision::GetTile(x,y) & COLFLAG_NOLASER); @@ -444,10 +456,11 @@ bool CCollision::IsFront(int x, int y) if(m_pFront[ny*m_pLayers->FrontLayer()->m_Width+nx].m_Index > 0) { - dbg_msg("IsFront","True m_Index=%d",m_pFront[ny*m_pLayers->FrontLayer()->m_Width+nx].m_Index);//Remove*/ + /*dbg_msg("IsFront","True m_Index=%d",m_pFront[ny*m_pLayers->FrontLayer()->m_Width+nx].m_Index);//Remove*/ return true; } - else dbg_msg("IsFront","Welcome to the front layer m_Index=%d",m_pFront[ny*m_pLayers->FrontLayer()->m_Width+nx].m_Index);//Remove*/ + /*else dbg_msg("IsFront","Welcome to the front layer m_Index=%d",m_pFront[ny*m_pLayers->FrontLayer()->m_Width+nx].m_Index);//Remove*/ + return false; } int CCollision::IsCp(int x, int y) diff --git a/src/game/collision.h b/src/game/collision.h index 265860bef..098ec05b8 100644 --- a/src/game/collision.h +++ b/src/game/collision.h @@ -34,11 +34,12 @@ public: void MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elasticity); bool TestBox(vec2 Pos, vec2 Size); int GetTile(int x, int y); - int Entitiy(int x, int y); + int Entity(int x, int y, bool Front); //DDRace int GetMapIndex(vec2 PrevPos, vec2 Pos); vec2 GetPos(int Index); int GetCollisionDDRace(int Index); + int GetCollisionDDRace2(int Index); int IsTeleport(int x, int y); int IsCheckpoint(int Index); bool IsSpeedup(int x, int y); diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index c12658c88..b1cfaeb42 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -558,7 +558,8 @@ void CCharacter::OnDirectInput(CNetObj_PlayerInput *pNewInput) void CCharacter::Tick() { int MapIndex = GameServer()->Collision()->GetMapIndex(m_PrevPos, m_Pos); - int TileIndex = GameServer()->Collision()->GetCollisionDDRace(MapIndex); + int TileIndex1 = GameServer()->Collision()->GetCollisionDDRace(MapIndex); + int TileIndex2 = GameServer()->Collision()->GetCollisionDDRace2(MapIndex); if(m_RaceState == RACE_PAUSE) { m_Input.m_Direction = 0; m_Input.m_Jump = 0; @@ -600,7 +601,7 @@ void CCharacter::Tick() m_Core.m_HookTick = 0; if (m_Super && m_Core.m_Jumped > 1) m_Core.m_Jumped = 1; - /*dbg_msg("character","TileIndex%d",TileIndex); //REMOVE*/ + /*dbg_msg("character","TileIndex1=%d , TileIndex2=%d",TileIndex1,TileIndex2); //REMOVE*/ //DDRace char aBuftime[128]; float time = (float)(Server()->Tick() - m_StartTime) / ((float)Server()->TickSpeed()); @@ -619,13 +620,13 @@ void CCharacter::Tick() } m_RefreshTime = Server()->Tick(); } - else if((TileIndex == TILE_BEGIN) && (m_RaceState == RACE_NONE || m_RaceState == RACE_STARTED)) + if(((TileIndex1 == TILE_BEGIN) || (TileIndex2 == TILE_BEGIN)) && (m_RaceState == RACE_NONE || m_RaceState == RACE_STARTED)) { m_StartTime = Server()->Tick(); m_RefreshTime = Server()->Tick(); m_RaceState = RACE_STARTED; } - else if((TileIndex == TILE_END) && m_RaceState == RACE_STARTED) + if(((TileIndex1 == TILE_END) || (TileIndex2 == TILE_END)) && m_RaceState == RACE_STARTED) { char aBuf[128]; if ((int)time / 60 != 0) @@ -649,60 +650,103 @@ void CCharacter::Tick() if(strncmp(Server()->ClientName(m_pPlayer->GetCID()), "nameless tee", 12) != 0) ((CGameControllerDDRace*)GameServer()->m_pController)->m_Score.ParsePlayer(Server()->ClientName(m_pPlayer->GetCID()), (float)time); } - else if((TileIndex == TILE_FREEZE) && !m_Super) + if(((TileIndex1 == TILE_FREEZE) || (TileIndex2 == TILE_FREEZE)) && !m_Super) { Freeze(Server()->TickSpeed()*3); } - else if(TileIndex == TILE_UNFREEZE) + else if((TileIndex1 == TILE_UNFREEZE) || (TileIndex2 == TILE_UNFREEZE)) { UnFreeze(); } - else if ((TileIndex >= TILE_BOOST_L && TileIndex <= TILE_BOOST_U) || (TileIndex >= TILE_BOOST_L2 && TileIndex <= TILE_BOOST_U2)) + if (((TileIndex1 >= TILE_BOOST_L && TileIndex1 <= TILE_BOOST_U) || (TileIndex1 >= TILE_BOOST_L2 && TileIndex1 <= TILE_BOOST_U2))) { - int booster = TileIndex; + int booster = TileIndex1; + m_Core.m_Vel += GameServer()->Collision()->BoostAccelerator(booster); + } + if ((TileIndex2 >= TILE_BOOST_L && TileIndex2 <= TILE_BOOST_U) || (TileIndex2 >= TILE_BOOST_L2 && TileIndex2 <= TILE_BOOST_U2)) + { + int booster = TileIndex2; m_Core.m_Vel += GameServer()->Collision()->BoostAccelerator(booster); } - else if(GameServer()->Collision()->GetCollisionDDRace(TileIndex) == TILE_STOPL) + if(TileIndex1 == TILE_STOPL) { if(m_Core.m_Vel.x > 0) { - if((int)GameServer()->Collision()->GetPos(TileIndex).x < (int)m_Core.m_Pos.x) + if((int)GameServer()->Collision()->GetPos(TileIndex1).x < (int)m_Core.m_Pos.x) m_Core.m_Pos.x = m_PrevPos.x; m_Core.m_Vel.x = 0; } } - else if(GameServer()->Collision()->GetCollisionDDRace(TileIndex) == TILE_STOPR) + if(TileIndex2 == TILE_STOPL) + { + if(m_Core.m_Vel.x > 0) + { + if((int)GameServer()->Collision()->GetPos(TileIndex2).x < (int)m_Core.m_Pos.x) + m_Core.m_Pos.x = m_PrevPos.x; + m_Core.m_Vel.x = 0; + } + } + if(TileIndex1 == TILE_STOPR) { if(m_Core.m_Vel.x < 0) { - if((int)GameServer()->Collision()->GetPos(TileIndex).x > (int)m_Core.m_Pos.x) + if((int)GameServer()->Collision()->GetPos(TileIndex1).x > (int)m_Core.m_Pos.x) m_Core.m_Pos.x = m_PrevPos.x; m_Core.m_Vel.x = 0; } } - else if(GameServer()->Collision()->GetCollisionDDRace(TileIndex) == TILE_STOPB) + if(TileIndex1 == TILE_STOPB) { if(m_Core.m_Vel.y < 0) { - if((int)GameServer()->Collision()->GetPos(TileIndex).y > (int)m_Core.m_Pos.y) + if((int)GameServer()->Collision()->GetPos(TileIndex1).y > (int)m_Core.m_Pos.y) m_Core.m_Pos.y = m_PrevPos.y; m_Core.m_Vel.y = 0; } } - else if(GameServer()->Collision()->GetCollisionDDRace(TileIndex) == TILE_STOPT) + if(TileIndex1 == TILE_STOPT) { if(m_Core.m_Vel.y > 0) { - if((int)GameServer()->Collision()->GetPos(TileIndex).y < (int)m_Core.m_Pos.y) + if((int)GameServer()->Collision()->GetPos(TileIndex1).y < (int)m_Core.m_Pos.y) m_Core.m_Pos.y = m_PrevPos.y; if(m_Jumped&3 && m_Core.m_Jumped != m_Jumped) // check double jump m_Core.m_Jumped = m_Jumped; m_Core.m_Vel.y = 0; } } - else if(GameServer()->Collision()->IsFront((int)m_Core.m_Pos.x, (int)m_Core.m_Pos.y)) + if(TileIndex2 == TILE_STOPR) + { + if(m_Core.m_Vel.x < 0) + { + if((int)GameServer()->Collision()->GetPos(TileIndex2).x > (int)m_Core.m_Pos.x) + m_Core.m_Pos.x = m_PrevPos.x; + m_Core.m_Vel.x = 0; + } + } + if(TileIndex2 == TILE_STOPB) + { + if(m_Core.m_Vel.y < 0) + { + if((int)GameServer()->Collision()->GetPos(TileIndex2).y > (int)m_Core.m_Pos.y) + m_Core.m_Pos.y = m_PrevPos.y; + m_Core.m_Vel.y = 0; + } + } + if(TileIndex2 == TILE_STOPT) + { + if(m_Core.m_Vel.y > 0) + { + if((int)GameServer()->Collision()->GetPos(TileIndex2).y < (int)m_Core.m_Pos.y) + m_Core.m_Pos.y = m_PrevPos.y; + if(m_Jumped&3 && m_Core.m_Jumped != m_Jumped) // check double jump + m_Core.m_Jumped = m_Jumped; + m_Core.m_Vel.y = 0; + } + } + if(GameServer()->Collision()->IsFront((int)m_Core.m_Pos.x, (int)m_Core.m_Pos.y)) ; - else if(GameServer()->Collision()->IsSpeedup((int)m_Core.m_Pos.x, (int)m_Core.m_Pos.y)) + if(GameServer()->Collision()->IsSpeedup((int)m_Core.m_Pos.x, (int)m_Core.m_Pos.y)) { vec2 Direction; int Force; @@ -710,7 +754,7 @@ void CCharacter::Tick() m_Core.m_Vel += Direction*Force; } - else if(z) + if(z) { m_Core.m_HookedPlayer = -1; m_Core.m_HookState = HOOK_RETRACTED; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 0503a54df..8862554b2 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -21,10 +21,10 @@ void CGameContext::Construct(int Resetting) { m_Resetting = 0; m_pServer = 0; - + for(int i = 0; i < MAX_CLIENTS; i++) m_apPlayers[i] = 0; - + m_pController = 0; m_VoteCloseTime = 0; m_pVoteOptionFirst = 0; @@ -65,7 +65,7 @@ void CGameContext::Clear() this->~CGameContext(); mem_zero(this, sizeof(*this)); new (this) CGameContext(RESET); - //this->m_Cheats = cheats; + //this->m_Cheats = cheats; m_pVoteOptionHeap = pVoteOptionHeap; m_pVoteOptionFirst = pVoteOptionFirst; @@ -143,7 +143,7 @@ void CGameContext::CreateExplosion(vec2 p, int Owner, int Weapon, bool NoDamage) apEnts[i]->TakeDamage(ForceDir*Dmg*2, (int)Dmg, Owner, Weapon); if(!g_Config.m_SvHit) break; } - + } } } @@ -240,7 +240,7 @@ void CGameContext::SendChat(int ChatterClientId, int Team, const char *pText) Msg.m_Team = 1; Msg.m_Cid = ChatterClientId; Msg.m_pMessage = pText; - + // pack one for the recording only Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NOSEND, -1); @@ -276,7 +276,7 @@ void CGameContext::SendBroadcast(const char *pText, int ClientId) Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientId); } -// +// void CGameContext::StartVote(const char *pDesc, const char *pCommand) { // check if a vote is already running @@ -293,7 +293,7 @@ void CGameContext::StartVote(const char *pDesc, const char *pCommand) m_apPlayers[i]->m_VotePos = 0; } } - + // start vote m_VoteCloseTime = time_get() + time_freq()*25; str_copy(m_aVoteDescription, pDesc, sizeof(m_aVoteDescription)); @@ -336,7 +336,7 @@ void CGameContext::SendVoteStatus(int ClientId, int Total, int Yes, int No) Msg.m_Pass = Total - (Yes+No); Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientId); - + } void CGameContext::AbortVoteKickOnDisconnect(int ClientId) @@ -351,7 +351,7 @@ void CGameContext::CheckPureTuning() // might not be created yet during start up if(!m_pController) return; - + if( str_comp(m_pController->m_pGameType, "DM")==0 || str_comp(m_pController->m_pGameType, "TDM")==0 || str_comp(m_pController->m_pGameType, "CTF")==0) @@ -362,13 +362,13 @@ void CGameContext::CheckPureTuning() dbg_msg("server", "resetting tuning due to pure server"); m_Tuning = p; } - } + } } void CGameContext::SendTuningParams(int Cid) { CheckPureTuning(); - + CMsgPacker Msg(NETMSGTYPE_SV_TUNEPARAMS); int *pParams = (int *)&m_Tuning; for(unsigned i = 0; i < sizeof(m_Tuning)/sizeof(int); i++) @@ -387,13 +387,13 @@ void CGameContext::OnTick() //if(world.paused) // make sure that the game object always updates m_pController->Tick(); - + for(int i = 0; i < MAX_CLIENTS; i++) { if(m_apPlayers[i]) m_apPlayers[i]->Tick(); } - + // update voting if(m_VoteCloseTime) { @@ -418,10 +418,10 @@ void CGameContext::OnTick() { if(!m_apPlayers[i] || m_apPlayers[i]->GetTeam() == -1 || aVoteChecked[i]) // don't count in votes by spectators continue; - + int ActVote = m_apPlayers[i]->m_Vote; int ActVotePos = m_apPlayers[i]->m_VotePos; - + // check for more players with the same ip (only use the vote of the one who voted first) for(int j = i+1; j < MAX_CLIENTS; ++j) { @@ -448,7 +448,7 @@ void CGameContext::OnTick() else if(No >= Total/2+1 || Yes+No == Total) m_VoteEnforce = VOTE_ENFORCE_NO; } - + if(m_VoteEnforce == VOTE_ENFORCE_YES) { //Console()->ExecuteLine(m_aVoteCommand, 4, -1); @@ -483,7 +483,7 @@ void CGameContext::OnTick() } } } - + #ifdef CONF_DEBUG if(g_Config.m_DbgDummies) @@ -495,7 +495,7 @@ void CGameContext::OnTick() m_apPlayers[MAX_CLIENTS-i-1]->OnPredictedInput(&Input); } } -#endif +#endif } // Server hooks @@ -520,7 +520,7 @@ void CGameContext::OnClientEnter(int ClientId) char aBuf[512]; str_format(aBuf, sizeof(aBuf), "%s entered and joined the %s", Server()->ClientName(ClientId), m_pController->GetTeamName(m_apPlayers[ClientId]->GetTeam())); - SendChat(-1, CGameContext::CHAT_ALL, aBuf); + SendChat(-1, CGameContext::CHAT_ALL, aBuf); SendChatTarget(ClientId, "DDRace Mod. Version: " DDRACE_VERSION); SendChatTarget(ClientId, "Official site: DDRace.info"); SendChatTarget(ClientId, "For more Info /CMDList"); @@ -532,15 +532,15 @@ void CGameContext::OnClientEnter(int ClientId) m_VoteUpdate = true; } -bool compare_players(CPlayer *pl1, CPlayer *pl2) -{ - if (pl1->m_Authed>pl2->m_Authed) - return true; - else - return false; -} +bool compare_players(CPlayer *pl1, CPlayer *pl2) +{ + if (pl1->m_Authed>pl2->m_Authed) + return true; + else + return false; +} -void CGameContext::OnSetAuthed(int client_id, int Level) +void CGameContext::OnSetAuthed(int client_id, int Level) { if(m_apPlayers[client_id]) { @@ -554,12 +554,12 @@ void CGameContext::OnSetAuthed(int client_id, int Level) dbg_msg("hooks","Aborting vote"); } } -} - -void CGameContext::OnSetResistent(int client_id, int Resistent) -{ - if(m_apPlayers[client_id]) - m_apPlayers[client_id]->m_Resistent = Resistent; +} + +void CGameContext::OnSetResistent(int client_id, int Resistent) +{ + if(m_apPlayers[client_id]) + m_apPlayers[client_id]->m_Resistent = Resistent; } void CGameContext::OnClientConnected(int ClientId) @@ -570,7 +570,7 @@ void CGameContext::OnClientConnected(int ClientId) m_apPlayers[ClientId] = new(ClientId) CPlayer(this, ClientId, StartTeam); //players[client_id].init(client_id); //players[client_id].client_id = client_id; - + //(void)m_pController->CheckTeamBalance(); #ifdef CONF_DEBUG @@ -597,7 +597,7 @@ void CGameContext::OnClientDrop(int ClientId) m_apPlayers[ClientId]->OnDisconnect(); delete m_apPlayers[ClientId]; m_apPlayers[ClientId] = 0; - + //(void)m_pController->CheckTeamBalance(); m_VoteUpdate = true; } @@ -606,13 +606,13 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) { void *pRawMsg = m_NetObjHandler.SecureUnpackMsg(MsgId, pUnpacker); CPlayer *p = m_apPlayers[ClientId]; - + if(!pRawMsg) { dbg_msg("server", "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgId), MsgId, m_NetObjHandler.FailedMsgOn()); return; } - + if(MsgId == NETMSGTYPE_CL_SAY) { CNetMsg_Cl_Say *pMsg = (CNetMsg_Cl_Say *)pRawMsg; @@ -621,14 +621,14 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) Team = p->GetTeam(); else Team = CGameContext::CHAT_ALL; - + if(g_Config.m_SvSpamprotection && p->m_Last_Chat && p->m_Last_Chat+Server()->TickSpeed() > Server()->Tick()) return; if(str_length(pMsg->m_pMessage)>370) { SendChatTarget(ClientId, "Your Message is too long"); return; } - + p->m_Last_Chat = Server()->Tick(); // check for invalid chars @@ -653,11 +653,11 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) { CCharacter* chr = m_apPlayers[ClientId]->GetCharacter(); if(chr) - { + { if(chr->m_RaceState==RACE_STARTED) chr->m_RaceState = RACE_PAUSE; else if(chr->m_RaceState==RACE_PAUSE) - chr->m_RaceState = RACE_STARTED; + chr->m_RaceState = RACE_STARTED; } } } else if(!str_comp_nocase(pMsg->m_pMessage, "/info")) @@ -740,15 +740,15 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) } else SendChatTarget(ClientId, "No such command!"); - + } else { if (m_apPlayers[ClientId]->m_Muted == 0) SendChat(ClientId, Team, pMsg->m_pMessage); else SendChatTarget(ClientId, "You are muted"); } - - + + } else if(MsgId == NETMSGTYPE_CL_CALLVOTE) { @@ -768,7 +768,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) SendChatTarget(ClientId, "Wait for current vote to end before calling a new one."); return; } - + int Timeleft = p->m_Last_VoteCall + Server()->TickSpeed()*60 - Now; if(p->m_Last_VoteCall && Timeleft > 0) { @@ -777,7 +777,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) SendChatTarget(ClientId, aChatmsg); return; } - + char aChatmsg[512] = {0}; char aDesc[512] = {0}; char aCmd[512] = {0}; @@ -791,11 +791,11 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) if(str_comp_nocase(pMsg->m_Value, pOption->m_aCommand) == 0) { if(m_apPlayers[ClientId]->m_Authed == 0 && strncmp(pOption->m_aCommand, "sv_map ", 7) == 0 && time_get() < last_mapvote + (time_freq() * g_Config.m_SvVoteMapTimeDelay)) - { + { char chatmsg[512] = {0}; str_format(chatmsg, sizeof(chatmsg), "There's a %d second delay between map-votes,Please wait %d Second(s)", g_Config.m_SvVoteMapTimeDelay,((last_mapvote+(g_Config.m_SvVoteMapTimeDelay * time_freq()))/time_freq())-(time_get()/time_freq())); SendChatTarget(ClientId, chatmsg); - + return; } str_format(aChatmsg, sizeof(aChatmsg), "%s called vote to change server option '%s'", Server()->ClientName(ClientId), pOption->m_aCommand); @@ -807,7 +807,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) pOption = pOption->m_pNext; } - + if(!pOption) { str_format(aChatmsg, sizeof(aChatmsg), "'%s' isn't an option on this server", pMsg->m_Value); @@ -818,9 +818,9 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) } else if(str_comp_nocase(pMsg->m_Type, "kick") == 0) { - if(m_apPlayers[ClientId]->m_Authed == 0 && time_get() < m_apPlayers[ClientId]->m_Last_KickVote + (time_freq() * 5)) + if(m_apPlayers[ClientId]->m_Authed == 0 && time_get() < m_apPlayers[ClientId]->m_Last_KickVote + (time_freq() * 5)) return; - else if(m_apPlayers[ClientId]->m_Authed == 0 && time_get() < m_apPlayers[ClientId]->m_Last_KickVote + (time_freq() * g_Config.m_SvVoteKickTimeDelay)) + else if(m_apPlayers[ClientId]->m_Authed == 0 && time_get() < m_apPlayers[ClientId]->m_Last_KickVote + (time_freq() * g_Config.m_SvVoteKickTimeDelay)) { char chatmsg[512] = {0}; str_format(chatmsg, sizeof(chatmsg), "There's a %d second waittime between kickvotes for each player please wait %d second(s)", @@ -837,7 +837,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) m_apPlayers[ClientId]->m_Last_KickVote = time_get(); return; } - + int KickId = str_toint(pMsg->m_Value); if(KickId < 0 || KickId >= MAX_CLIENTS || !m_apPlayers[KickId]) { @@ -859,7 +859,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) SendChatTarget(KickId, aBufKick); return; } - + str_format(aChatmsg, sizeof(aChatmsg), "%s called for vote to kick '%s'", Server()->ClientName(ClientId), Server()->ClientName(KickId)); str_format(aDesc, sizeof(aDesc), "Kick '%s'", Server()->ClientName(KickId)); if (!g_Config.m_SvVoteKickBanTime) @@ -872,7 +872,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) } m_apPlayers[ClientId]->m_Last_KickVote = time_get(); } - + if(aCmd[0]) { SendChat(-1, CGameContext::CHAT_ALL, aChatmsg); @@ -902,7 +902,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) else if (MsgId == NETMSGTYPE_CL_SETTEAM && !m_World.m_Paused) { CNetMsg_Cl_SetTeam *pMsg = (CNetMsg_Cl_SetTeam *)pRawMsg; - + if(p->GetTeam() == pMsg->m_Team || (g_Config.m_SvSpamprotection && p->m_Last_SetTeam && p->m_Last_SetTeam+Server()->TickSpeed()*3 > Server()->Tick())) return; @@ -930,10 +930,10 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) else if (MsgId == NETMSGTYPE_CL_CHANGEINFO || MsgId == NETMSGTYPE_CL_STARTINFO) { CNetMsg_Cl_ChangeInfo *pMsg = (CNetMsg_Cl_ChangeInfo *)pRawMsg; - + if(g_Config.m_SvSpamprotection && p->m_Last_ChangeInfo && p->m_Last_ChangeInfo+Server()->TickSpeed()*5 > Server()->Tick()) return; - + p->m_Last_ChangeInfo = time_get(); if (!p->m_ColorSet|| g_Config.m_SvAllowColorChange) { @@ -945,7 +945,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) // copy old name char aOldName[MAX_NAME_LENGTH]; str_copy(aOldName, Server()->ClientName(ClientId), MAX_NAME_LENGTH); - + Server()->SetClientName(ClientId, pMsg->m_pName); if(MsgId == NETMSGTYPE_CL_CHANGEINFO && str_comp(aOldName, Server()->ClientName(ClientId)) != 0) { @@ -953,12 +953,12 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) str_format(aChatText, sizeof(aChatText), "%s changed name to %s", aOldName, Server()->ClientName(ClientId)); SendChat(-1, CGameContext::CHAT_ALL, aChatText); } - + // set skin str_copy(p->m_TeeInfos.m_SkinName, pMsg->m_pSkin, sizeof(p->m_TeeInfos.m_SkinName)); - + //m_pController->OnPlayerInfoChange(p); - + if(MsgId == NETMSGTYPE_CL_STARTINFO) { // send vote options @@ -972,7 +972,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, ClientId); pCurrent = pCurrent->m_pNext; } - + // send tuning parameters to client SendTuningParams(ClientId); @@ -984,19 +984,19 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId) else if (MsgId == NETMSGTYPE_CL_EMOTICON && !m_World.m_Paused) { CNetMsg_Cl_Emoticon *pMsg = (CNetMsg_Cl_Emoticon *)pRawMsg; - + if(g_Config.m_SvSpamprotection && p->m_Last_Emote && p->m_Last_Emote+Server()->TickSpeed()*3 > Server()->Tick()) return; - + p->m_Last_Emote = Server()->Tick(); - + SendEmoticon(ClientId, pMsg->m_Emoticon); } else if (MsgId == NETMSGTYPE_CL_KILL && !m_World.m_Paused) { if(p->m_Last_Kill && p->m_Last_Kill+Server()->TickSpeed()*3 > Server()->Tick()) return; - + p->m_Last_Kill = Server()->Tick(); p->KillCharacter(WEAPON_SELF); p->m_RespawnTick = Server()->Tick()+Server()->TickSpeed()*3; @@ -1070,12 +1070,12 @@ void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData, int c CGameContext *pSelf = (CGameContext *)pUserData; int ClientId = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); int Team = clamp(pResult->GetInteger(1), -1, 1); - + dbg_msg("set_team", "%d %d", ClientId, Team); - + if(!pSelf->m_apPlayers[ClientId] || !compare_players(pSelf->m_apPlayers[cid], pSelf->m_apPlayers[ClientId])) return; - + pSelf->m_apPlayers[ClientId]->SetTeam(Team); //(void)pSelf->m_pController->CheckTeamBalance(); } @@ -1084,7 +1084,7 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData, int C { CGameContext *pSelf = (CGameContext *)pUserData; int Len = str_length(pResult->GetString(0)); - + CGameContext::CVoteOption *pOption = (CGameContext::CVoteOption *)pSelf->m_pVoteOptionHeap->Allocate(sizeof(CGameContext::CVoteOption) + Len); pOption->m_pNext = 0; pOption->m_pPrev = pSelf->m_pVoteOptionLast; @@ -1093,7 +1093,7 @@ void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData, int C pSelf->m_pVoteOptionLast = pOption; if(!pSelf->m_pVoteOptionFirst) pSelf->m_pVoteOptionFirst = pOption; - + mem_copy(pOption->m_aCommand, pResult->GetString(0), Len+1); dbg_msg("server", "added option '%s'", pOption->m_aCommand); @@ -1136,7 +1136,7 @@ bool CGameContext::CheatsAvailable(int cid) { void CGameContext::ConGoLeft(IConsole::IResult *pResult, void *pUserData, int cid) { CGameContext *pSelf = (CGameContext *)pUserData; - + if (!pSelf->CheatsAvailable(cid)) return; CCharacter* chr = pSelf->GetPlayerChar(cid); @@ -1219,7 +1219,7 @@ void CGameContext::ConKillPlayer(IConsole::IResult *pResult, void *pUserData, in int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); if(!pSelf->m_apPlayers[cid1]) return; - + if (pSelf->m_apPlayers[cid1] && compare_players(pSelf->m_apPlayers[cid],pSelf->m_apPlayers[cid1])) { pSelf->m_apPlayers[cid1]->KillCharacter(WEAPON_GAME); @@ -1232,7 +1232,7 @@ void CGameContext::ConKillPlayer(IConsole::IResult *pResult, void *pUserData, in void CGameContext::ConNinjaMe(IConsole::IResult *pResult, void *pUserData, int cid) { CGameContext *pSelf = (CGameContext *)pUserData; if(!pSelf->CheatsAvailable(cid)) return; - + CCharacter* chr = pSelf->GetPlayerChar(cid); if(chr) { chr->GiveNinja(); @@ -1259,7 +1259,7 @@ void CGameContext::ConHammer(IConsole::IResult *pResult, void *pUserData, int ci CGameContext *pSelf = (CGameContext *)pUserData; if(!pSelf->CheatsAvailable(cid)) return; char buf[128]; - + int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); int type = pResult->GetInteger(1); CCharacter* chr = pSelf->GetPlayerChar(cid1); @@ -1281,7 +1281,7 @@ void CGameContext::ConHammer(IConsole::IResult *pResult, void *pUserData, int ci } void CGameContext::ConHammerMe(IConsole::IResult *pResult, void *pUserData, int cid) -{ +{ CGameContext *pSelf = (CGameContext *)pUserData; if(!pSelf->CheatsAvailable(cid)) return; char buf[128]; @@ -1306,7 +1306,7 @@ void CGameContext::ConHammerMe(IConsole::IResult *pResult, void *pUserData, int void CGameContext::ConSuper(IConsole::IResult *pResult, void *pUserData, int cid) -{ +{ CGameContext *pSelf = (CGameContext *)pUserData; if(!pSelf->CheatsAvailable(cid)) return; int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); @@ -1323,7 +1323,7 @@ void CGameContext::ConSuper(IConsole::IResult *pResult, void *pUserData, int cid } void CGameContext::ConUnSuper(IConsole::IResult *pResult, void *pUserData, int cid) -{ +{ CGameContext *pSelf = (CGameContext *)pUserData; if(!pSelf->CheatsAvailable(cid)) return; int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); @@ -1338,7 +1338,7 @@ void CGameContext::ConUnSuper(IConsole::IResult *pResult, void *pUserData, int c } void CGameContext::ConSuperMe(IConsole::IResult *pResult, void *pUserData, int cid) -{ +{ CGameContext *pSelf = (CGameContext *)pUserData; if(!pSelf->CheatsAvailable(cid)) return; if (pSelf->m_apPlayers[cid]) @@ -1354,7 +1354,7 @@ void CGameContext::ConSuperMe(IConsole::IResult *pResult, void *pUserData, int c } void CGameContext::ConUnSuperMe(IConsole::IResult *pResult, void *pUserData, int cid) -{ +{ CGameContext *pSelf = (CGameContext *)pUserData; if(!pSelf->CheatsAvailable(cid)) return; if (pSelf->m_apPlayers[cid]) @@ -1425,10 +1425,10 @@ void CGameContext::ConTimer(IConsole::IResult *pResult, void *pUserData, int cid char buf[128]; CServer* serv = (CServer*)pSelf->Server(); if(!g_Config.m_SvTimer) { - + int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); int type = pResult->GetInteger(1); - + CCharacter* chr = pSelf->GetPlayerChar(cid1); if (!chr) return; @@ -1437,7 +1437,7 @@ void CGameContext::ConTimer(IConsole::IResult *pResult, void *pUserData, int cid serv->SendRconLine(cid, "Select 0 for no time & 1 for with time"); } else - { + { if(type) { chr->m_RaceState = RACE_STARTED; @@ -1451,7 +1451,7 @@ void CGameContext::ConTimer(IConsole::IResult *pResult, void *pUserData, int cid serv->SendRconLine(cid1, buf); } } else { - + serv->SendRconLine(cid, "Command timer does't allowed"); } } @@ -1461,9 +1461,9 @@ void CGameContext::ConTimerReset(IConsole::IResult *pResult, void *pUserData, in CGameContext *pSelf = (CGameContext *)pUserData; if(!pSelf->CheatsAvailable(cid)) return; char buf[128]; - + int cid1 = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); - + CCharacter* chr = pSelf->GetPlayerChar(cid1); if (!chr) return; @@ -1472,38 +1472,38 @@ void CGameContext::ConTimerReset(IConsole::IResult *pResult, void *pUserData, in str_format(buf, sizeof(buf), "Cid=%d time resetted.",cid1); CServer* serv = (CServer*)pSelf->Server(); serv->SendRconLine(cid1, buf); - + } void CGameContext::OnConsoleInit() { m_pServer = Kernel()->RequestInterface(); m_pConsole = Kernel()->RequestInterface(); - + Console()->Register("timer", "ii", CFGFLAG_SERVER, ConTimer, this, "Sets the timer of player i1 to i2 0/1 on/off",2); Console()->Register("timerreset", "i", CFGFLAG_SERVER, ConTimerReset, this, "resets the timer of player i (to start count again timer cid 1)",1); Console()->Register("tele", "ii", CFGFLAG_SERVER, ConTeleport, this, "",2); - + Console()->Register("weapons", "i", CFGFLAG_SERVER, ConWeapons, this, "",2); Console()->Register("weapons_me", "", CFGFLAG_SERVER, ConWeaponsMe, this, "",1); - + Console()->Register("super", "i", CFGFLAG_SERVER, ConSuper, this, "",2); Console()->Register("unsuper", "i", CFGFLAG_SERVER, ConUnSuper, this, "",2); Console()->Register("super_me", "", CFGFLAG_SERVER, ConSuperMe, this, "",1); Console()->Register("unsuper_me", "", CFGFLAG_SERVER, ConUnSuperMe, this, "",1);// Mo - + Console()->Register("hammer_me", "i", CFGFLAG_SERVER, ConHammerMe, this, "",1); Console()->Register("hammer", "ii", CFGFLAG_SERVER, ConHammer, this, "",2); - + Console()->Register("ninja", "i", CFGFLAG_SERVER, ConNinja, this, "",2); Console()->Register("ninja_me", "", CFGFLAG_SERVER, ConNinjaMe, this, "",1); - - + + Console()->Register("kill_pl", "i", CFGFLAG_SERVER, ConKillPlayer, this, "",2); Console()->Register("auth", "ii", CFGFLAG_SERVER, ConSetlvl, this, "",3); Console()->Register("mute", "ii", CFGFLAG_SERVER, ConMute, this, "", 2); - + Console()->Register("tune", "si", CFGFLAG_SERVER, ConTuneParam, this, "", 4); Console()->Register("tune_reset", "", CFGFLAG_SERVER, ConTuneReset, this, "", 4); Console()->Register("tune_dump", "", CFGFLAG_SERVER, ConTuneDump, this, "", 4); @@ -1513,7 +1513,7 @@ void CGameContext::OnConsoleInit() Console()->Register("broadcast", "r", CFGFLAG_SERVER, ConBroadcast, this, "", 3); Console()->Register("say", "r", CFGFLAG_SERVER, ConSay, this, "", 3); Console()->Register("set_team", "ii", CFGFLAG_SERVER, ConSetTeam, this, "", 2); - + Console()->Register("left", "", CFGFLAG_SERVER, ConGoLeft, this, "",1); Console()->Register("right", "", CFGFLAG_SERVER, ConGoRight, this, "",1); Console()->Register("up", "", CFGFLAG_SERVER, ConGoUp, this, "",1); @@ -1523,7 +1523,7 @@ void CGameContext::OnConsoleInit() Console()->Register("vote", "r", CFGFLAG_SERVER, ConVote, this, "", 3); Console()->Chain("sv_motd", ConchainSpecialMotdupdate, this); - + } void CGameContext::OnInit(/*class IKernel *pKernel*/) @@ -1532,10 +1532,10 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/) m_pConsole = Kernel()->RequestInterface(); m_World.SetGameServer(this); m_Events.SetGameServer(this); - + //if(!data) // only load once //data = load_data_from_memory(internal_data); - + for(int i = 0; i < NUM_NETOBJTYPES; i++) Server()->SnapSetStaticsize(i, m_NetObjHandler.GetObjSize(i)); @@ -1546,22 +1546,22 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/) //world = new GAMEWORLD; //players = new CPlayer[MAX_CLIENTS]; - char buf[512]; - str_format(buf, sizeof(buf), "data/maps/%s.cfg", g_Config.m_SvMap); // + char buf[512]; + str_format(buf, sizeof(buf), "data/maps/%s.cfg", g_Config.m_SvMap); // Console()->ExecuteFile(buf); - str_format(buf, sizeof(buf), "data/maps/%s.map.cfg", g_Config.m_SvMap); + str_format(buf, sizeof(buf), "data/maps/%s.map.cfg", g_Config.m_SvMap); Console()->ExecuteFile(buf); -// dbg_msg("Note","For map cfgs in windows and linux u need the files"); -// dbg_msg("Note","in a folder i nthe same dir as teeworlds_srv"); -// dbg_msg("Note","data/maps/%s.cfg", config.sv_map); +// dbg_msg("Note","For map cfgs in windows and linux u need the files"); +// dbg_msg("Note","in a folder i nthe same dir as teeworlds_srv"); +// dbg_msg("Note","data/maps/%s.cfg", config.sv_map); // select gametype m_pController = new CGameControllerDDRace(this); //float temp; //m_Tuning.Get("player_hooking",&temp); //g_Config.m_SvPhook = temp; //m_Tuning.Get("player_collision",&temp); - //g_Config.m_SvNpc=(!temp); - + //g_Config.m_SvNpc=(!temp); + Server()->SetBrowseInfo(m_pController->m_pGameType, -1); // setup core world @@ -1571,18 +1571,29 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/) // create all entities from the game layer CMapItemLayerTilemap *pTileMap = m_Layers.GameLayer(); CTile *pTiles = (CTile *)Kernel()->RequestInterface()->GetData(pTileMap->m_Data); - - //windows usually crshes here + //CMapItemLayerTilemap *pFrontMap = m_Layers.FrontLayer(); not needed game layer and front layer are always the same size + CTile *pFront=0; + if (m_Layers.FrontLayer()) + pFront = (CTile *)Kernel()->RequestInterface()->GetData(pTileMap->m_Front); + for(int y = 0; y < pTileMap->m_Height; y++) { for(int x = 0; x < pTileMap->m_Width; x++) { int Index = pTiles[y*pTileMap->m_Width+x].m_Index; - if(Index >= ENTITY_OFFSET) { vec2 Pos(x*32.0f+16.0f, y*32.0f+16.0f); - m_pController->OnEntity(Index-ENTITY_OFFSET, Pos); + m_pController->OnEntity(Index-ENTITY_OFFSET, Pos,false); + } + if (pFront) + { + int FIndex = pFront[y*pTileMap->m_Width+x].m_Index; + if(FIndex >= ENTITY_OFFSET) + { + vec2 Pos(x*32.0f+16.0f, y*32.0f+16.0f); + m_pController->OnEntity(FIndex-ENTITY_OFFSET, Pos,true); + } } } } @@ -1610,7 +1621,7 @@ void CGameContext::OnSnap(int ClientId) m_World.Snap(ClientId); m_pController->Snap(ClientId); m_Events.Snap(ClientId); - + for(int i = 0; i < MAX_CLIENTS; i++) { if(m_apPlayers[i]) diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 19110c7a0..b8366c396 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -8,13 +8,13 @@ #include "gamecontroller.h" #include "gamecontext.h" -#include "entities/light.h" -#include "entities/drager.h" -#include "entities/gun.h" -#include "entities/projectile.h" -#include "entities/plasma.h" -#include "entities/trigger.h" -#include "entities/door.h" +#include "entities/light.h" +#include "entities/drager.h" +#include "entities/gun.h" +#include "entities/projectile.h" +#include "entities/plasma.h" +#include "entities/trigger.h" +#include "entities/door.h" #include @@ -24,7 +24,7 @@ IGameController::IGameController(class CGameContext *pGameServer) m_pGameServer = pGameServer; m_pServer = m_pGameServer->Server(); m_pGameType = "unknown"; - + // DoWarmup(g_Config.m_SvWarmup); m_GameOverTick = -1; @@ -35,10 +35,10 @@ IGameController::IGameController(class CGameContext *pGameServer) //m_aTeamscore[0] = 0; //m_aTeamscore[1] = 0; m_aMapWish[0] = 0; - + m_UnbalancedTick = -1; m_ForceBalanced = false; - + m_aNumSpawnPoints[0] = 0; m_aNumSpawnPoints[1] = 0; m_aNumSpawnPoints[2] = 0; @@ -58,14 +58,14 @@ float IGameController::EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos) float Scoremod = 1.0f; if(pEval->m_FriendlyTeam != -1 && pC->GetPlayer()->GetTeam() == pEval->m_FriendlyTeam) Scoremod = 0.5f; - + float d = distance(Pos, pC->m_Pos); if(d == 0) Score += 1000000000.0f; else Score += 1.0f/d; } - + return Score; } @@ -88,15 +88,15 @@ void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int T) bool IGameController::CanSpawn(CPlayer *pPlayer, vec2 *pOutPos) { CSpawnEval Eval; - + // spectators can't spawn if(pPlayer->GetTeam() == -1) return false; - + /*if(IsTeamplay()) { Eval.m_FriendlyTeam = pPlayer->GetTeam(); - + // try first try own team spawn, then normal spawn and then enemy EvaluateSpawnType(&Eval, 1+(pPlayer->GetTeam()&1)); if(!Eval.m_Got) @@ -112,37 +112,40 @@ bool IGameController::CanSpawn(CPlayer *pPlayer, vec2 *pOutPos) EvaluateSpawnType(&Eval, 1); EvaluateSpawnType(&Eval, 2); //} - + *pOutPos = Eval.m_Pos; return Eval.m_Got; } -bool IGameController::OnEntity(int Index, vec2 Pos) +bool IGameController::OnEntity(int Index, vec2 Pos, bool Front) { + //if (Index<0) + //return false; + dbg_msg("OnEntity","Index=%d, Pos=(%d,%d), Front=%d",Index,Pos.x,Pos.y,Front);//Remove*/ int Type = -1; int SubType = 0; int x,y; x=(Pos.x-16.0f)/32.0f; - y=(Pos.y-16.0f)/32.0f; - dbg_msg("OnEntity","Pos(%d,%d)",x,y); + y=(Pos.y-16.0f)/32.0f; + /*dbg_msg("OnEntity","Pos(%d,%d)",x,y);//Remove*/ int sides[8]; - sides[0]=GameServer()->Collision()->Entitiy(x,y+1); - sides[1]=GameServer()->Collision()->Entitiy(x+1,y+1); - sides[2]=GameServer()->Collision()->Entitiy(x+1,y); - sides[3]=GameServer()->Collision()->Entitiy(x+1,y-1); - sides[4]=GameServer()->Collision()->Entitiy(x,y-1); - sides[5]=GameServer()->Collision()->Entitiy(x-1,y-1); - sides[6]=GameServer()->Collision()->Entitiy(x-1,y); - sides[7]=GameServer()->Collision()->Entitiy(x-1,y+1); - - + sides[0]=GameServer()->Collision()->Entity(x,y+1, Front); + sides[1]=GameServer()->Collision()->Entity(x+1,y+1, Front); + sides[2]=GameServer()->Collision()->Entity(x+1,y, Front); + sides[3]=GameServer()->Collision()->Entity(x+1,y-1, Front); + sides[4]=GameServer()->Collision()->Entity(x,y-1, Front); + sides[5]=GameServer()->Collision()->Entity(x-1,y-1, Front); + sides[6]=GameServer()->Collision()->Entity(x-1,y, Front); + sides[7]=GameServer()->Collision()->Entity(x-1,y+1, Front); + + if(Index == ENTITY_SPAWN) m_aaSpawnPoints[0][m_aNumSpawnPoints[0]++] = Pos; else if(Index == ENTITY_SPAWN_RED) m_aaSpawnPoints[1][m_aNumSpawnPoints[1]++] = Pos; else if(Index == ENTITY_SPAWN_BLUE) m_aaSpawnPoints[2][m_aNumSpawnPoints[2]++] = Pos; - + if(Index == ENTITY_DOOR) { for(int i=0; i<8;i++) @@ -152,7 +155,7 @@ bool IGameController::OnEntity(int Index, vec2 Pos) CDoor * door = new CDoor(&GameServer()->m_World, Pos, pi/4*i, 32*3 + 32*(sides[i] - ENTITY_LASER_SHORT)*3, false); //for (int j = 0; j < 8; j++) // if (j != i) - Connector(vec2(x, y), door); + Connector(vec2(x, y), door, Front); } } } @@ -163,7 +166,7 @@ bool IGameController::OnEntity(int Index, vec2 Pos) if (Index - ENTITY_CRAZY_SHOTGUN_U_EX == i) { float Deg = i*(pi/2); - CProjectile *bullet = new CProjectile(&GameServer()->m_World, + CProjectile *bullet = new CProjectile(&GameServer()->m_World, WEAPON_SHOTGUN, //Type -1, //Owner Pos, //Pos @@ -171,8 +174,8 @@ bool IGameController::OnEntity(int Index, vec2 Pos) -2, //Span true, //Freeze true, //Explosive - 0, - SOUND_GRENADE_EXPLODE, + 0, + SOUND_GRENADE_EXPLODE, WEAPON_SHOTGUN); bullet->SetBouncing(2 - (i % 2)); @@ -186,7 +189,7 @@ bool IGameController::OnEntity(int Index, vec2 Pos) if (Index - ENTITY_CRAZY_SHOTGUN_U == i) { float Deg = i*(pi/2); - CProjectile *bullet = new CProjectile(&GameServer()->m_World, + CProjectile *bullet = new CProjectile(&GameServer()->m_World, WEAPON_SHOTGUN, //Type -1, //Owner Pos, //Pos @@ -194,14 +197,14 @@ bool IGameController::OnEntity(int Index, vec2 Pos) -2, //Span true, //Freeze false, //Explosive - 0, - SOUND_GRENADE_EXPLODE, + 0, + SOUND_GRENADE_EXPLODE, WEAPON_SHOTGUN); bullet->SetBouncing(2 - (i % 2)); } } } - + if(Index == ENTITY_ARMOR_1) Type = POWERUP_ARMOR; else if(Index == ENTITY_HEALTH_1) @@ -226,76 +229,76 @@ bool IGameController::OnEntity(int Index, vec2 Pos) Type = POWERUP_NINJA; SubType = WEAPON_NINJA; } - else if(Index >= ENTITY_LASER_FAST_CW && Index <= ENTITY_LASER_FAST_CCW) - { + else if(Index >= ENTITY_LASER_FAST_CW && Index <= ENTITY_LASER_FAST_CCW) + { int sides2[8]; - sides2[0]=GameServer()->Collision()->Entitiy(x,y+2); - sides2[1]=GameServer()->Collision()->Entitiy(x+2,y+2); - sides2[2]=GameServer()->Collision()->Entitiy(x+2,y); - sides2[3]=GameServer()->Collision()->Entitiy(x+2,y-2); - sides2[4]=GameServer()->Collision()->Entitiy(x,y-2); - sides2[5]=GameServer()->Collision()->Entitiy(x-2,y-2); - sides2[6]=GameServer()->Collision()->Entitiy(x-2,y); - sides2[7]=GameServer()->Collision()->Entitiy(x-2,y+2); + sides2[0]=GameServer()->Collision()->Entity(x,y+2, Front); + sides2[1]=GameServer()->Collision()->Entity(x+2,y+2, Front); + sides2[2]=GameServer()->Collision()->Entity(x+2,y, Front); + sides2[3]=GameServer()->Collision()->Entity(x+2,y-2, Front); + sides2[4]=GameServer()->Collision()->Entity(x,y-2, Front); + sides2[5]=GameServer()->Collision()->Entity(x-2,y-2, Front); + sides2[6]=GameServer()->Collision()->Entity(x-2,y, Front); + sides2[7]=GameServer()->Collision()->Entity(x-2,y+2, Front); - float ang_speed; - int ind=Index-ENTITY_LASER_STOP; - int m; - if (ind<0) - { - ind=-ind; - m=1; - } - else if(ind==0) - m=0; - else - m=-1; - - - if (ind==0) - ang_speed=0.0f; - else if (ind==1) - ang_speed=pi/360; - else if (ind==2) - ang_speed=pi/180; - else if (ind==3) - ang_speed=pi/90; - ang_speed*=m; - - for(int i=0; i<8;i++) - { - if (sides[i] >= ENTITY_LASER_SHORT && sides[i] <= ENTITY_LASER_LONG) - { - CLight *lgt = new CLight(&GameServer()->m_World, Pos, pi/4*i,32*3 + 32*(sides[i] - ENTITY_LASER_SHORT)*3); - lgt->ang_speed=ang_speed; - if (sides2[i]>=ENTITY_LASER_C_SLOW && sides2[i]<=ENTITY_LASER_C_FAST) - { - lgt->speed=1+(sides2[i]-ENTITY_LASER_C_SLOW)*2; - lgt->cur_length=lgt->length; - } - else if(sides2[i]>=ENTITY_LASER_O_SLOW && sides2[i]<=ENTITY_LASER_O_FAST) - { - lgt->speed=1+(sides2[i]-ENTITY_LASER_O_SLOW)*2; - lgt->cur_length=0; - } - else - lgt->cur_length=lgt->length; - } - } + float ang_speed; + int ind=Index-ENTITY_LASER_STOP; + int m; + if (ind<0) + { + ind=-ind; + m=1; + } + else if(ind==0) + m=0; + else + m=-1; - } - else if(Index>=ENTITY_DRAGGER_WEAK && Index <=ENTITY_DRAGGER_STRONG) - { - new CDrager(&GameServer()->m_World,Pos,Index-ENTITY_DRAGGER_WEAK+1); - } - else if(Index>=ENTITY_DRAGGER_WEAK_NW && Index <=ENTITY_DRAGGER_STRONG_NW) - { - new CDrager(&GameServer()->m_World, Pos,Index-ENTITY_DRAGGER_WEAK_NW+1,true); - } - else if(Index==ENTITY_PLASMA) - { - new CGun(&GameServer()->m_World, Pos); - } + + if (ind==0) + ang_speed=0.0f; + else if (ind==1) + ang_speed=pi/360; + else if (ind==2) + ang_speed=pi/180; + else if (ind==3) + ang_speed=pi/90; + ang_speed*=m; + + for(int i=0; i<8;i++) + { + if (sides[i] >= ENTITY_LASER_SHORT && sides[i] <= ENTITY_LASER_LONG) + { + CLight *lgt = new CLight(&GameServer()->m_World, Pos, pi/4*i,32*3 + 32*(sides[i] - ENTITY_LASER_SHORT)*3); + lgt->ang_speed=ang_speed; + if (sides2[i]>=ENTITY_LASER_C_SLOW && sides2[i]<=ENTITY_LASER_C_FAST) + { + lgt->speed=1+(sides2[i]-ENTITY_LASER_C_SLOW)*2; + lgt->cur_length=lgt->length; + } + else if(sides2[i]>=ENTITY_LASER_O_SLOW && sides2[i]<=ENTITY_LASER_O_FAST) + { + lgt->speed=1+(sides2[i]-ENTITY_LASER_O_SLOW)*2; + lgt->cur_length=0; + } + else + lgt->cur_length=lgt->length; + } + } + + } + else if(Index>=ENTITY_DRAGGER_WEAK && Index <=ENTITY_DRAGGER_STRONG) + { + new CDrager(&GameServer()->m_World,Pos,Index-ENTITY_DRAGGER_WEAK+1); + } + else if(Index>=ENTITY_DRAGGER_WEAK_NW && Index <=ENTITY_DRAGGER_STRONG_NW) + { + new CDrager(&GameServer()->m_World, Pos,Index-ENTITY_DRAGGER_WEAK_NW+1,true); + } + else if(Index==ENTITY_PLASMA) + { + new CGun(&GameServer()->m_World, Pos); + } if(Type != -1) { CPickup *pPickup = new CPickup(&GameServer()->m_World, Type, SubType); @@ -322,21 +325,21 @@ vec2 GetSidePos(int side) { return vec2(0, 0); } -void IGameController::Connector(vec2 Pos, CDoor* Door) { +void IGameController::Connector(vec2 Pos, CDoor* Door, bool Front) { int sides[8]; - sides[0] = GameServer()->Collision()->Entitiy(Pos.x, Pos.y + 1); - sides[1] = GameServer()->Collision()->Entitiy(Pos.x + 1, Pos.y + 1); - sides[2] = GameServer()->Collision()->Entitiy(Pos.x + 1, Pos.y); - sides[3] = GameServer()->Collision()->Entitiy(Pos.x + 1, Pos.y - 1); - sides[4] = GameServer()->Collision()->Entitiy(Pos.x, Pos.y - 1); - sides[5] = GameServer()->Collision()->Entitiy(Pos.x - 1, Pos.y - 1); - sides[6] = GameServer()->Collision()->Entitiy(Pos.x - 1, Pos.y); - sides[7] = GameServer()->Collision()->Entitiy(Pos.x - 1, Pos.y + 1); + sides[0] = GameServer()->Collision()->Entity(Pos.x, Pos.y + 1, Front); + sides[1] = GameServer()->Collision()->Entity(Pos.x + 1, Pos.y + 1, Front); + sides[2] = GameServer()->Collision()->Entity(Pos.x + 1, Pos.y, Front); + sides[3] = GameServer()->Collision()->Entity(Pos.x + 1, Pos.y - 1, Front); + sides[4] = GameServer()->Collision()->Entity(Pos.x, Pos.y - 1, Front); + sides[5] = GameServer()->Collision()->Entity(Pos.x - 1, Pos.y - 1, Front); + sides[6] = GameServer()->Collision()->Entity(Pos.x - 1, Pos.y, Front); + sides[7] = GameServer()->Collision()->Entity(Pos.x - 1, Pos.y + 1, Front); for (int i=0;i<8;i++) { vec2 shift = GetSidePos(i); if (sides[i]==ENTITY_CONNECTOR_D+(i+4) % 8) - Connector(Pos + shift, Door); + Connector(Pos + shift, Door, Front); else if(sides[i]==ENTITY_TRIGGER) { vec2 pos((Pos.x + shift.x)*32.0f + 16.0f, (Pos.y + shift.y)*32.0f + 16.0f); @@ -349,7 +352,7 @@ void IGameController::EndRound() { if(m_Warmup) // game can't end when we are running warmup return; - + GameServer()->m_World.m_Paused = true; m_GameOverTick = Server()->Tick(); m_SuddenDeath = 0; @@ -373,7 +376,7 @@ bool IsSeparator(char c) { return c == ';' || c == ' ' || c == ',' || c == '\t'; void IGameController::StartRound() { ResetGame(); - + m_RoundStartTick = Server()->Tick(); m_SuddenDeath = 0; m_GameOverTick = -1; @@ -403,11 +406,11 @@ void IGameController::CycleMap() if(m_RoundCount < g_Config.m_SvRoundsPerMap-1) return; - + // handle maprotation const char *pMapRotation = g_Config.m_SvMaprotation; const char *pCurrentMap = g_Config.m_SvMap; - + int CurrentMapLen = str_length(pCurrentMap); const char *pNextMap = pMapRotation; while(*pNextMap) @@ -415,25 +418,25 @@ void IGameController::CycleMap() int WordLen = 0; while(pNextMap[WordLen] && !IsSeparator(pNextMap[WordLen])) WordLen++; - + if(WordLen == CurrentMapLen && str_comp_num(pNextMap, pCurrentMap, CurrentMapLen) == 0) { // map found pNextMap += CurrentMapLen; while(*pNextMap && IsSeparator(*pNextMap)) pNextMap++; - + break; } - + pNextMap++; } - + // restart rotation if(pNextMap[0] == 0) pNextMap = pMapRotation; - // cut out the next map + // cut out the next map char Buf[512]; for(int i = 0; i < 512; i++) { @@ -444,14 +447,14 @@ void IGameController::CycleMap() break; } } - + // skip spaces int i = 0; while(IsSeparator(Buf[i])) i++; - + m_RoundCount = 0; - + dbg_msg("game", "rotating map to %s", &Buf[i]); str_copy(g_Config.m_SvMap, &Buf[i], sizeof(g_Config.m_SvMap)); } @@ -469,7 +472,7 @@ void IGameController::PostReset() } } } -/* +/* void IGameController::OnPlayerInfoChange(class CPlayer *pP) { const int aTeamColors[2] = {65387, 10223467}; @@ -507,7 +510,7 @@ void IGameController::OnCharacterSpawn(class CCharacter *pChr) { // default health pChr->IncreaseHealth(10); - + // give default weapons //pChr->GiveAllWeapons(); pChr->GiveWeapon(WEAPON_HAMMER, -1); @@ -526,16 +529,16 @@ bool IGameController::IsFriendlyFire(int Cid1, int Cid2) { if(Cid1 == Cid2) return false; - + if(IsTeamplay()) { if(!GameServer()->m_apPlayers[Cid1] || !GameServer()->m_apPlayers[Cid2]) return false; - + if(GameServer()->m_apPlayers[Cid1]->GetTeam() == GameServer()->m_apPlayers[Cid2]->GetTeam()) return true; } - + return false; } */ @@ -564,7 +567,7 @@ void IGameController::Tick() if(!m_Warmup) StartRound(); } - + if(m_GameOverTick != -1) { // game over.. wait for restart @@ -580,7 +583,7 @@ void IGameController::Tick() if (IsTeamplay() && m_UnbalancedTick != -1 && Server()->Tick() > m_UnbalancedTick+g_Config.m_SvTeambalanceTime*Server()->TickSpeed()*60) { dbg_msg("game", "Balancing teams"); - + int aT[2] = {0,0}; float aTScore[2] = {0,0}; float aPScore[MAX_CLIENTS] = {0.0f}; @@ -594,13 +597,13 @@ void IGameController::Tick() aTScore[GameServer()->m_apPlayers[i]->GetTeam()] += aPScore[i]; } } - + // are teams unbalanced? if(absolute(aT[0]-aT[1]) >= 2) { int M = (aT[0] > aT[1]) ? 0 : 1; int NumBalance = absolute(aT[0]-aT[1]) / 2; - + do { CPlayer *pP = 0; @@ -616,14 +619,14 @@ void IGameController::Tick() PD = absolute((aTScore[M^1]+aPScore[i]) - (aTScore[M]-aPScore[i])); } } - + // move the player to the other team pP->SetTeam(M^1); - + pP->Respawn(); pP->m_ForceBalanced = true; } while (--NumBalance); - + m_ForceBalanced = true; } m_UnbalancedTick = -1; @@ -670,18 +673,18 @@ void IGameController::Snap(int SnappingClient) pGameObj->m_Paused = GameServer()->m_World.m_Paused; pGameObj->m_GameOver = m_GameOverTick==-1?0:1; pGameObj->m_SuddenDeath = m_SuddenDeath; - + //pGameObj->m_ScoreLimit = g_Config.m_SvScorelimit; //pGameObj->m_TimeLimit = g_Config.m_SvTimelimit; pGameObj->m_RoundStartTick = m_RoundStartTick; pGameObj->m_Flags = m_GameFlags; - + pGameObj->m_Warmup = m_Warmup; - + pGameObj->m_RoundNum = /*(str_length(g_Config.m_SvMaprotation) && g_Config.m_SvRoundsPerMap) ? g_Config.m_SvRoundsPerMap :*/ 0; pGameObj->m_RoundCurrent = m_RoundCount+1; - - + + if(SnappingClient == -1) { // we are recording a demo, just set the scores @@ -701,7 +704,7 @@ int IGameController::GetAutoTeam(int Notthisid) // this will force the auto balancer to work overtime aswell if(g_Config.m_DbgStress) return 0; - + int aNumplayers[2] = {0,0}; for(int i = 0; i < MAX_CLIENTS; i++) { @@ -715,7 +718,7 @@ int IGameController::GetAutoTeam(int Notthisid) int Team = 0; //if(IsTeamplay()) // Team = aNumplayers[0] > aNumplayers[1] ? 1 : 0; - + if(CanJoinTeam(Team, Notthisid)) return Team; return -1; @@ -735,7 +738,7 @@ bool IGameController::CanJoinTeam(int Team, int Notthisid) aNumplayers[GameServer()->m_apPlayers[i]->GetTeam()]++; } } - + return (aNumplayers[0] + aNumplayers[1]) < g_Config.m_SvMaxClients-g_Config.m_SvSpectatorSlots; } /* @@ -743,7 +746,7 @@ bool IGameController::CheckTeamBalance() { if(!IsTeamplay() || !g_Config.m_SvTeambalanceTime) return true; - + int aT[2] = {0, 0}; for(int i = 0; i < MAX_CLIENTS; i++) { @@ -751,7 +754,7 @@ bool IGameController::CheckTeamBalance() if(pP && pP->GetTeam() != -1) aT[pP->GetTeam()]++; } - + if(absolute(aT[0]-aT[1]) >= 2) { dbg_msg("game", "Team is NOT balanced (red=%d blue=%d)", aT[0], aT[1]); @@ -770,22 +773,22 @@ bool IGameController::CheckTeamBalance() bool IGameController::CanChangeTeam(CPlayer *pPlayer, int JoinTeam) { int aT[2] = {0, 0}; - + if (!IsTeamplay() || JoinTeam == -1 || !g_Config.m_SvTeambalanceTime) return true; - + for(int i = 0; i < MAX_CLIENTS; i++) { CPlayer *pP = GameServer()->m_apPlayers[i]; if(pP && pP->GetTeam() != -1) aT[pP->GetTeam()]++; } - + // simulate what would happen if changed team aT[JoinTeam]++; if (pPlayer->GetTeam() != -1) aT[JoinTeam^1]--; - + // there is a player-difference of at least 2 if(absolute(aT[0]-aT[1]) >= 2) { @@ -819,7 +822,7 @@ void IGameController::DoPlayerScoreWincheck() TopscoreCount++; } } - + // check score win condition if((g_Config.m_SvScorelimit > 0 && Topscore >= g_Config.m_SvScorelimit) || (g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60)) @@ -858,4 +861,4 @@ int IGameController::ClampTeam(int Team) //if(IsTeamplay()) // return Team&1; return 0; -} \ No newline at end of file +} diff --git a/src/game/server/gamecontroller.h b/src/game/server/gamecontroller.h index 8101225c1..fcb39e2d2 100644 --- a/src/game/server/gamecontroller.h +++ b/src/game/server/gamecontroller.h @@ -101,9 +101,9 @@ public: Returns: bool? */ - virtual bool OnEntity(int Index, vec2 Pos); + virtual bool OnEntity(int Index, vec2 Pos, bool Front); - virtual void Connector(vec2 Pos, CDoor* Door); + virtual void Connector(vec2 Pos, CDoor* Door, bool Front); /* Function: on_CCharacter_spawn diff --git a/src/game/server/gameworld.cpp b/src/game/server/gameworld.cpp index 42c194873..9e8a25d1f 100644 --- a/src/game/server/gameworld.cpp +++ b/src/game/server/gameworld.cpp @@ -10,7 +10,7 @@ CGameWorld::CGameWorld() { m_pGameServer = 0x0; m_pServer = 0x0; - + m_Paused = false; m_ResetRequested = false; m_pFirstEntity = 0x0; @@ -159,7 +159,7 @@ void CGameWorld::Tick() // update all objects for(CEntity *pEnt = m_pFirstEntity; pEnt; pEnt = pEnt->m_pNextEntity) pEnt->Tick(); - + for(CEntity *pEnt = m_pFirstEntity; pEnt; pEnt = pEnt->m_pNextEntity) pEnt->TickDefered(); } @@ -181,7 +181,7 @@ CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, v { if(p == pNotThis) continue; - + vec2 IntersectPos = closest_point_on_line(Pos0, Pos1, p->m_Pos); float Len = distance(p->m_Pos, IntersectPos); if(Len < p->m_ProximityRadius+Radius) @@ -194,7 +194,7 @@ CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, v } } } - + return pClosest; } @@ -204,13 +204,13 @@ CCharacter *CGameWorld::ClosestCharacter(vec2 Pos, float Radius, CEntity *pNotTh // Find other players float ClosestRange = Radius*2; CCharacter *pClosest = 0; - + CCharacter *p = (CCharacter *)GameServer()->m_World.FindFirst(NETOBJTYPE_CHARACTER); for(; p; p = (CCharacter *)p->TypeNext()) { if(p == pNotThis) continue; - + float Len = distance(Pos, p->m_Pos); if(Len < p->m_ProximityRadius+Radius) { @@ -221,6 +221,6 @@ CCharacter *CGameWorld::ClosestCharacter(vec2 Pos, float Radius, CEntity *pNotTh } } } - + return pClosest; }