X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_game.pas;h=4fbede48721b20714b43ca74026b6d2683a21efc;hb=3c0e17ab63db38746eff53276a32d1aebcbfad1b;hp=47251204f2b021a78262a60f265d830d63308bda;hpb=b00b458845d9f1bcf5d7643c47aaad4455600eb2;p=d2df-sdl.git diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 4725120..4fbede4 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -29,7 +29,7 @@ type GameType: Byte; GameMode: Byte; TimeLimit: Word; - GoalLimit: Word; + ScoreLimit: Word; WarmupTime: Word; SpawnInvul: Word; ItemRespawnTime: Word; @@ -103,8 +103,8 @@ procedure g_Game_RemovePlayer(); procedure g_Game_Spectate(); procedure g_Game_SpectateCenterView(); procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte); -procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte); -procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word); +procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte); +procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word); procedure g_Game_StartClient(Addr: String; Port: Word; PW: String); procedure g_Game_Restart(); procedure g_Game_RestartLevel(); @@ -275,7 +275,7 @@ var gPauseHolmes: Boolean = false; gShowTime: Boolean = False; gShowFPS: Boolean = False; - gShowGoals: Boolean = True; + gShowScore: Boolean = True; gShowStat: Boolean = True; gShowPIDs: Boolean = False; gShowKillMsg: Boolean = True; @@ -680,6 +680,7 @@ begin fname := e_CatPath(fname, StatFilename + '.csv'); AssignFile(s, fname); try + SetTextCodePage(s, CP_UTF8); Rewrite(s); // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players if g_Game_IsNet then fname := NetServerName else fname := ''; @@ -698,7 +699,7 @@ begin dquoteStr(map), mode, gGameSettings.TimeLimit, - gGameSettings.GoalLimit, + gGameSettings.ScoreLimit, gGameSettings.Options, etime, Length(Stat.PlayerStat) @@ -709,7 +710,7 @@ begin // otherwise nothing if Stat.GameMode in [GM_TDM, GM_CTF] then WriteLn(s, - Format('red_score,blue_score' + LineEnding + '%d,%d', [Stat.TeamStat[TEAM_RED].Goals, Stat.TeamStat[TEAM_BLUE].Goals])) + Format('red_score,blue_score' + LineEnding + '%d,%d', [Stat.TeamStat[TEAM_RED].Score, Stat.TeamStat[TEAM_BLUE].Score])) else if Stat.GameMode in [GM_COOP, GM_SINGLE] then WriteLn(s, Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding + '%d,%d,%d,%d',[gCoopMonstersKilled, gTotalMonsters, gCoopSecretsFound, gSecretsCount])); @@ -727,6 +728,17 @@ begin CloseFile(s); end; +procedure ClearDebugCvars(); +begin + g_debug_Sounds := False; + g_debug_Frames := False; + g_debug_WinMsgs := False; + g_debug_MonsterOff := False; + g_debug_BotAIOff := 0; + g_debug_HealthBar := False; + g_Debug_Player := False; +end; + function g_Game_ModeToText(Mode: Byte): string; begin Result := ''; @@ -1207,7 +1219,7 @@ begin s1 := _lc[I_GAME_DM] else s1 := _lc[I_GAME_LMS]; - s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]); + s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]); s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]); end; @@ -1217,14 +1229,14 @@ begin s1 := _lc[I_GAME_TDM] else s1 := _lc[I_GAME_TLMS]; - s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]); + s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]); s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]); end; GM_CTF: begin s1 := _lc[I_GAME_CTF]; - s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.GoalLimit]); + s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]); s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]); end; @@ -1294,7 +1306,7 @@ begin end; e_TextureFontPrintEx(x+16, _y, s1, gStdFont, r, g, b, 1); - e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Goals), + e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Score), gStdFont, r, g, b, 1); _y := _y+ch+(ch div 4); @@ -2010,7 +2022,7 @@ begin gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK; // Áûë çàäàí ëèìèò ïîáåä: - if (gGameSettings.GoalLimit > 0) then + if (gGameSettings.ScoreLimit > 0) then begin b := 0; @@ -2024,11 +2036,11 @@ begin else if gGameSettings.GameMode in [GM_TDM, GM_CTF] then begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì - b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals); + b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score); end; // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ: - if b >= gGameSettings.GoalLimit then + if b >= gGameSettings.ScoreLimit then begin g_Game_NextLevel(); Exit; @@ -2847,8 +2859,8 @@ begin _y := _y+16+16; with CustomStat do - if TeamStat[TEAM_RED].Goals > TeamStat[TEAM_BLUE].Goals then s1 := _lc[I_GAME_WIN_RED] - else if TeamStat[TEAM_BLUE].Goals > TeamStat[TEAM_RED].Goals then s1 := _lc[I_GAME_WIN_BLUE] + if TeamStat[TEAM_RED].Score > TeamStat[TEAM_BLUE].Score then s1 := _lc[I_GAME_WIN_RED] + else if TeamStat[TEAM_BLUE].Score > TeamStat[TEAM_RED].Score then s1 := _lc[I_GAME_WIN_BLUE] else s1 := _lc[I_GAME_WIN_DRAW]; e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1); @@ -2860,7 +2872,7 @@ begin begin e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED], gStdFont, 255, 0, 0, 1); - e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Goals), + e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Score), gStdFont, 255, 0, 0, 1); r := 255; g := 0; @@ -2870,7 +2882,7 @@ begin begin e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE], gStdFont, 0, 0, 255, 1); - e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Goals), + e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Score), gStdFont, 0, 0, 255, 1); r := 0; g := 0; @@ -4548,7 +4560,7 @@ begin end; procedure g_Game_StartCustom(Map: String; GameMode: Byte; - TimeLimit, GoalLimit: Word; + TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte); var @@ -4565,7 +4577,7 @@ begin gGameSettings.GameMode := GameMode; gSwitchGameMode := GameMode; gGameSettings.TimeLimit := TimeLimit; - gGameSettings.GoalLimit := GoalLimit; + gGameSettings.ScoreLimit := ScoreLimit; gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives); gGameSettings.Options := Options; @@ -4661,7 +4673,7 @@ begin end; procedure g_Game_StartServer(Map: String; GameMode: Byte; - TimeLimit, GoalLimit: Word; MaxLives: Byte; + TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word); begin @@ -4672,12 +4684,14 @@ begin g_Game_ClearLoading(); + ClearDebugCvars(); + // Íàñòðîéêè èãðû: gGameSettings.GameType := GT_SERVER; gGameSettings.GameMode := GameMode; gSwitchGameMode := GameMode; gGameSettings.TimeLimit := TimeLimit; - gGameSettings.GoalLimit := GoalLimit; + gGameSettings.ScoreLimit := ScoreLimit; gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives); gGameSettings.Options := Options; @@ -4805,6 +4819,8 @@ begin g_Game_ClearLoading(); + ClearDebugCvars(); + // Íàñòðîéêè èãðû: gGameSettings.GameType := GT_CLIENT; @@ -4854,12 +4870,6 @@ begin begin if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then begin - if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then - begin - // ignore all download packets, they're processed by separate code - enet_packet_destroy(NetEvent.packet); - continue; - end; Ptr := NetEvent.packet^.data; if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then begin @@ -4882,7 +4892,7 @@ begin gGameSettings.GameMode := InMsg.ReadByte(); gSwitchGameMode := gGameSettings.GameMode; - gGameSettings.GoalLimit := InMsg.ReadWord(); + gGameSettings.ScoreLimit := InMsg.ReadWord(); gGameSettings.TimeLimit := InMsg.ReadWord(); gGameSettings.MaxLives := InMsg.ReadByte(); gGameSettings.Options := InMsg.ReadLongWord(); @@ -4959,8 +4969,7 @@ begin end; end; - ProcessLoading(true); - + ProcessLoading(True); if g_Net_UserRequestExit() then begin State := 0; @@ -5163,6 +5172,11 @@ begin if NetMode = NET_SERVER then begin + // reset full state flags + if NetClients <> nil then + for I := 0 to High(NetClients) do + NetClients[I].FullUpdateSent := False; + MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map); // Ìàñòåðñåðâåð @@ -5762,11 +5776,69 @@ begin e_LogWritefln('usage: %s ', [cmd]) end end + else if cmd = 'g_force_model' then + begin + if Length(p) = 2 then + begin + a := StrToIntDef(p[1], 0); + g_Force_Model_Set(a); + if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then + begin + for a := Low(gPlayers) to High(gPlayers) do + begin + if (gPlayers[a] <> nil) then + begin + if (gPlayers[a].UID = gPlayer1.UID) then + continue + else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then + continue; + gPlayers[a].setModel(g_Forced_Model_GetName()); + end; + end + end + else if (g_Force_Model_Get() = 0) and (gPlayers <> nil) then + begin + for a := Low(gPlayers) to High(gPlayers) do + begin + if (gPlayers[a] <> nil) then + begin + if (gPlayers[a].UID = gPlayer1.UID) then + continue + else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then + continue; + gPlayers[a].setModel(gPlayers[a].FActualModelName); + end; + end + end + end + end + else if cmd = 'g_force_model_name' then + begin + if (Length(P) > 1) then + begin + cmd := b_Text_Unformat(P[1]); + g_Forced_Model_SetName(cmd); + if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then + begin + for a := Low(gPlayers) to High(gPlayers) do + begin + if (gPlayers[a] <> nil) then + begin + if (gPlayers[a].UID = gPlayer1.UID) then + continue + else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then + continue; + gPlayers[a].setModel(g_Forced_Model_GetName()); + end; + end + end + end + end else if cmd = 'g_scorelimit' then begin if Length(P) > 1 then begin - gsGoalLimit := nclamp(StrToIntDef(P[1], gsGoalLimit), 0, $FFFF); + gsScoreLimit := nclamp(StrToIntDef(P[1], gsScoreLimit), 0, $FFFF); if g_Game_IsServer then begin @@ -5780,17 +5852,17 @@ begin b := stat[a].Frags; end else // TDM/CTF - b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals); + b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score); // if someone has a higher score, set it to that instead - gsGoalLimit := max(gsGoalLimit, b); - gGameSettings.GoalLimit := gsGoalLimit; + gsScoreLimit := max(gsScoreLimit, b); + gGameSettings.ScoreLimit := gsScoreLimit; if g_Game_IsNet then MH_SEND_GameSettings; end; end; - g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsGoalLimit)])); + g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsScoreLimit)])); end else if cmd = 'g_timelimit' then begin @@ -6487,6 +6559,7 @@ var nm: Boolean; listen: LongWord; found: Boolean; + t: Byte; begin // Îáùèå êîìàíäû: cmd := LowerCase(P[0]); @@ -6531,7 +6604,7 @@ begin if (pl <> nil) then begin s := g_Net_ClientName_ByID(pl^.ID); - enet_peer_disconnect(pl^.Peer, NET_DISC_KICK); + g_Net_Host_Kick(pl^.ID, NET_DISC_KICK); g_Console_Add(Format(_lc[I_PLAYER_KICK], [s])); MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s); g_Net_Slist_ServerPlayerLeaves(); @@ -6575,7 +6648,7 @@ begin if NetClients[a].Used and (NetClients[a].Peer <> nil) then begin s := g_Net_ClientName_ByID(NetClients[a].ID); - enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK); + g_Net_Host_Kick(NetClients[a].ID, NET_DISC_KICK); g_Console_Add(Format(_lc[I_PLAYER_KICK], [s])); MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s); g_Net_Slist_ServerPlayerLeaves(); @@ -6604,7 +6677,7 @@ begin if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then begin s := g_Net_ClientName_ByID(pl^.ID); - enet_peer_disconnect(pl^.Peer, NET_DISC_KICK); + g_Net_Host_Kick(pl^.ID, NET_DISC_KICK); g_Console_Add(Format(_lc[I_PLAYER_KICK], [s])); MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s); g_Net_Slist_ServerPlayerLeaves(); @@ -6632,7 +6705,7 @@ begin begin s := g_Net_ClientName_ByID(pl^.ID); g_Net_BanHost(pl^.Peer^.address.host, False); - enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN); + g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN); g_Console_Add(Format(_lc[I_PLAYER_BAN], [s])); MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s); g_Net_Slist_ServerPlayerLeaves(); @@ -6662,7 +6735,7 @@ begin begin s := g_Net_ClientName_ByID(NetClients[a].ID); g_Net_BanHost(NetClients[a].Peer^.address.host, False); - enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN); + g_Net_Host_Kick(NetClients[a].ID, NET_DISC_TEMPBAN); g_Console_Add(Format(_lc[I_PLAYER_BAN], [s])); MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s); g_Net_Slist_ServerPlayerLeaves(); @@ -6691,7 +6764,7 @@ begin begin s := g_Net_ClientName_ByID(pl^.ID); g_Net_BanHost(pl^.Peer^.address.host, False); - enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN); + g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN); g_Console_Add(Format(_lc[I_PLAYER_BAN], [s])); MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s); g_Net_Slist_ServerPlayerLeaves(); @@ -6719,7 +6792,7 @@ begin begin s := g_Net_ClientName_ByID(pl^.ID); g_Net_BanHost(pl^.Peer^.address.host); - enet_peer_disconnect(pl^.Peer, NET_DISC_BAN); + g_Net_Host_Kick(pl^.ID, NET_DISC_BAN); g_Net_SaveBanList(); g_Console_Add(Format(_lc[I_PLAYER_BAN], [s])); MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s); @@ -6750,7 +6823,7 @@ begin begin s := g_Net_ClientName_ByID(NetClients[a].ID); g_Net_BanHost(NetClients[a].Peer^.address.host); - enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN); + g_Net_Host_Kick(NetClients[a].ID, NET_DISC_BAN); g_Net_SaveBanList(); g_Console_Add(Format(_lc[I_PLAYER_BAN], [s])); MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s); @@ -6780,7 +6853,7 @@ begin begin s := g_Net_ClientName_ByID(pl^.ID); g_Net_BanHost(pl^.Peer^.address.host); - enet_peer_disconnect(pl^.Peer, NET_DISC_BAN); + g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN); g_Net_SaveBanList(); g_Console_Add(Format(_lc[I_PLAYER_BAN], [s])); MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s); @@ -6918,10 +6991,19 @@ begin begin if Length(P) = 2 then g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1)) - else if Length(P) = 3 then - g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100)) else - g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1)); + begin + if P[2] = 'red' then + t := TEAM_RED + else if P[2] = 'blue' then + t := TEAM_BLUE + else + t := TEAM_NONE; + + if Length(P) = 3 + then g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1)) + else g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[3], 100)); + end; end; end else if cmd = 'bot_removeall' then @@ -7056,7 +7138,7 @@ begin if Length(P) >= 4 then b := StrToIntDef(P[3], 1); g_Game_StartCustom(s, GameMode, TimeLimit, - GoalLimit, MaxLives, Options, b); + ScoreLimit, MaxLives, Options, b); end; end else @@ -7109,7 +7191,7 @@ begin b := 0; if Length(P) >= 6 then b := StrToIntDef(P[5], 0); - g_Game_StartServer(s, GameMode, TimeLimit, GoalLimit, MaxLives, Options, b, listen, prt) + g_Game_StartServer(s, GameMode, TimeLimit, ScoreLimit, MaxLives, Options, b, listen, prt) end end else @@ -7139,6 +7221,10 @@ begin g_Console_Add(_lc[I_MSG_GM_UNAVAIL]) end end + else if not e_IsValidResourceName(P[1]) then + begin + g_Console_Add('wad name must not be absolute or relative'); + end else begin if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then @@ -7266,6 +7352,10 @@ begin g_Console_Add(_lc[I_MSG_GM_UNAVAIL]); end; end + else if not e_IsValidResourceName(P[1]) then + begin + g_Console_Add('wad name must not be absolute or relative'); + end else begin nm := False; @@ -8303,8 +8393,7 @@ begin end; g_ActiveWindow := nil; - - ProcessLoading(true); + ProcessLoading(True); end; procedure g_Game_StepLoading(Value: Integer = -1); @@ -8318,10 +8407,11 @@ begin end else CurValue := Value; + if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then begin ShowCount := 0; - ProcessLoading(); + ProcessLoading(False); end; end; end; @@ -8465,7 +8555,7 @@ begin if LimT < 0 then LimT := 0; - // Goal limit: + // Score limit: s := Find_Param_Value(pars, '-lims'); if (s = '') or (not TryStrToInt(s, LimS)) then LimS := 0; @@ -8608,7 +8698,7 @@ begin conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter'); conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time'); conRegVar('r_showping', @gShowPing, 'show ping', 'show ping'); - conRegVar('r_showscore', @gShowGoals, 'show score', 'show score'); + conRegVar('r_showscore', @gShowScore, 'show score', 'show score'); conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log'); conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives'); conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');