⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 g_main.pas

📁 delphi编的不错的贪吃蛇
💻 PAS
📖 第 1 页 / 共 2 页
字号:
//100%
{----------------------------------------------------------------------------}
{                                                                            }
{ File(s): g_local.h (part), g_main.c                                        }
{ Content: Quake2\Game-CTF\ game interface initialization / management       }
{                                                                            }
{ Initial conversion by : Clootie (Alexey Barkovoy) - clootie@reactor.ru     }
{ Initial conversion on : 26-Jan-2002                                        }
{                                                                            }
{ This File contains part of convertion of Quake2 source to ObjectPascal.    }
{ More information about this project can be found at:                       }
{ http://www.sulaco.co.za/quake2/                                            }
{                                                                            }
{ Copyright (C) 1997-2001 Id Software, Inc.                                  }
{                                                                            }
{ This program is free software; you can redistribute it and/or              }
{ modify it under the terms of the GNU General Public License                }
{ as published by the Free Software Foundation; either version 2             }
{ of the License, or (at your option) any later version.                     }
{                                                                            }
{ This program is distributed in the hope that it will be useful,            }
{ but WITHOUT ANY WARRANTY; without even the implied warranty of             }
{ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                       }
{                                                                            }
{ See the GNU General Public License for more details.                       }
{                                                                            }
{----------------------------------------------------------------------------}
{ * Updated:                                                                 }
{ 1) 27-Jan-2002 - Clootie (clootie@reactor.ru)                              }
{    Corrected "strtok" function.                                            }
{ 2) 28-Jan-2002 - Clootie (clootie@reactor.ru)                              }
{    Linked to "g_svcmnds.pas" unit.                                         }
{ 3) 25-Feb-2002 - Clootie (clootie@reactor.ru)                              }
{    Resolved all dependency to G_Local.pas and G_Utils.pas.                 }
{ 4) 3-Mar-2002 - Carl Kenner (carl_kenner@hotmail.com)                      }
{    Made compatible with Capture The Flag and g_save                        }
{    Removed redefinitions of g_local stuff                                  }
{ 5) 14-May-2003 - Scott Price (scott.price@totalise.co.uk)                  }
{    Made pointer dereference alterations, and altered some calls to Round ()}
{    to be Trunc() instead to remain with the previous conventions, and      }
{    fixed a minor conversion bug.  Not compared CTF code, just concentrated }
{    on GAME units sections.                                                 }
{                                                                            }
{----------------------------------------------------------------------------}
{ * Still dependent (to compile correctly) on:                               }
{ -- Implementation: g_phys, p_client, g_spawn                               }
{----------------------------------------------------------------------------}
{ * TODO:                                                                    }
{ Clootie: "GAME_HARD_LINKED" on what project it should be defined ?         }
{----------------------------------------------------------------------------}
{ * NOTES:  --== Clootie ==--                                                }
{           This unit designed to be compatible with both Game and CTF build }
{           targets. By default unit compiles to GAME build target. To build }
{           for CTF one should define "CTF" global conditional define.       }
{----------------------------------------------------------------------------}

unit g_main;

interface

uses
  CPas,
  Q_Shared,
  G_Local,
  GameUnit;

type
  edict_arr = array[0..MaxInt div SizeOf(edict_t) - 1] of edict_t;

var
  game: game_locals_t;
  level: level_locals_t;
  gi: game_import_t;
  globals: game_export_t;
  st: spawn_temp_t;

  sm_meat_index,
  snd_fry,
  meansOfDeath: Integer;


  g_edicts: ^edict_arr;

  deathmatch,
  coop,
  dmflags,
  skill,
  fraglimit,
  timelimit,
  password,
  spectator_password,
  needpass,
  maxclients,
  maxspectators,
  maxentities,
  g_select_empty,
  dedicated,

  filterban,

  sv_maxvelocity,
  sv_gravity,

  sv_rollspeed,
  sv_rollangle,
  gun_x,
  gun_y,
  gun_z,

  run_pitch,
  run_roll,
  bob_up,
  bob_pitch,
  bob_roll,

  sv_cheats,

  flood_msgs,
  flood_persecond,
  flood_waitdelay,

  sv_maplist: cvar_p;


procedure G_RunFrame; cdecl;
function GetGameApi(const import: game_import_t): game_export_p; cdecl;

{$IFNDEF GAME_HARD_LINKED}
// this is only here so the functions in q_shared.c and q_shwin.c can link
procedure Sys_Error(error: PChar; args: array of const); overload;
procedure Sys_Error(error: PChar); overload;
procedure Com_Printf(msg: PChar; args: array of const); overload;
procedure Com_Printf(fmt: PChar); overload;
{$ENDIF}

function world: edict_p;

implementation

uses
  SysUtils,
  Math,
  g_svcmds,
  g_save,
  g_spawn,
  g_utils
{.$IFDEF GAME_HARD_LINKED}
  , g_ai
{$IFDEF CTF}
  , g_ctf
{$ENDIF}
{.$ENDIF}
   , p_client, g_cmds, p_view, p_hud, g_monster, g_phys;

function world: edict_p;
begin
  Result := @g_edicts^[0];
end;

//===================================================================


procedure ShutdownGame; cdecl;
begin
  gi.dprintf('==== ShutdownGame ===='#10);

  gi.FreeTags(TAG_LEVEL);
  gi.FreeTags(TAG_GAME);
end;


(*
=================
GetGameAPI

Returns a pointer to the structure with all entry points
and global variables
=================
*)
function GetGameApi(const import: game_import_t): game_export_p; cdecl;
begin
  gi := import;

  globals.apiversion := GAME_API_VERSION;
  globals.Init := InitGame;
  globals.Shutdown := ShutdownGame;
  globals.SpawnEntities := SpawnEntities;

  globals.WriteGame := WriteGame;
  globals.ReadGame := ReadGame;
  globals.WriteLevel := WriteLevel;
  globals.ReadLevel := ReadLevel;

  globals.ClientThink := ClientThink;
  globals.ClientConnect := ClientConnect;
  globals.ClientUserinfoChanged := ClientUserinfoChanged;
  globals.ClientDisconnect := ClientDisconnect;
  globals.ClientBegin := ClientBegin;
  globals.ClientCommand := ClientCommand;

  globals.RunFrame := G_RunFrame;

  globals.ServerCommand := ServerCommand;

  globals.edict_size := SizeOf(edict_t);

  Result := @globals;
end;

{$IFNDEF GAME_HARD_LINKED}

// this is only here so the functions in q_shared.c and q_shwin.c can link
procedure Sys_Error(error: PChar; args: array of const);
var
  text: array [0..1023] of Char;
begin
  StrFmt(text, error, args);
  //Clootie: code error in C source file - probably it's never compiles
  //         - as Game.dll exist in all Quake-series games
  // gi.error(ERR_FATAL, '%s', [text]);
  gi.error({ERR_FATAL, }'%s', text);
end;

procedure Com_Printf(msg: PChar; args: array of const);
var
  text: array [0..1023] of Char;
begin
  StrFmt(text, msg, args);
  gi.dprintf('%s', text);
end;

procedure Com_Printf(fmt: PChar);
begin
  Com_Printf(fmt, []);
end;

procedure Sys_Error(error: PChar);
begin
  Sys_Error(error, []);
end;

{$ENDIF}

//======================================================================


(*
=================
ClientEndServerFrames
=================
*)
procedure ClientEndServerFrames;
var
  i: Integer;
  ent: edict_p;
begin
  // calc the player views now that all pushing
  // and damage has been added
  for i := 0 to {Round}Trunc(maxclients^.value) - 1 do
  begin
    { ent = g_edicts + 1 + i; }
    ent := @g_edicts^[1 + i];
    if (not ent^.inuse) or (ent^.client = nil) then
      Continue;
    ClientEndServerFrame(ent);
  end;
end;

(*
=================
CreateTargetChangeLevel

Returns the created target changelevel
=================
*)
function CreateTargetChangeLevel(map: PChar): edict_p;
var
  ent: edict_p;
begin
  ent := g_utils.G_Spawn;
  ent^.classname := 'target_changelevel';
  Com_sprintf(level.nextmap, sizeof(level.nextmap), '%s', [map]);
  ent^.map := level.nextmap;
  Result := ent;
end;


(*
=================
EndDMLevel

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -