summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 249437f)
raw | patch | inline | side by side (parent: 249437f)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 5 Oct 2018 19:40:50 +0000 (22:40 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 5 Oct 2018 19:40:50 +0000 (22:40 +0300) |
src/game/g_menu.pas | patch | blob | history | |
src/game/g_options.pas | patch | blob | history | |
src/shared/envvars.pas | patch | blob | history |
diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas
index ef79a7665b7e0ec795998727247fbf30003f36c6..23fbf2e947c3f77ac7a455db154a71b120ad6c97 100644 (file)
--- a/src/game/g_menu.pas
+++ b/src/game/g_menu.pas
gPlayer2Settings.Color := Model.Color;
end;
- if gPlayer1Settings.Name = '' then gPlayer1Settings.Name := 'Player1';
- if gPlayer2Settings.Name = '' then gPlayer2Settings.Name := 'Player2';
+ if gPlayer1Settings.Name = '' then gPlayer1Settings.Name := GenPlayerName(1);
+ if gPlayer2Settings.Name = '' then gPlayer2Settings.Name := GenPlayerName(2);
if g_Game_IsServer then
begin
diff --git a/src/game/g_options.pas b/src/game/g_options.pas
index 86761de063a688abc621149e2b2adc531c906755..506fc186424753429b21151925830bb1a0b6376d 100644 (file)
--- a/src/game/g_options.pas
+++ b/src/game/g_options.pas
P2Control: TPlayerControl;
end;
+function GenPlayerName (n: Integer): String;
+
procedure g_Options_SetDefault();
procedure g_Options_Read(FileName: String);
procedure g_Options_Write(FileName: String);
{$INCLUDE ../nogl/noGLuses.inc}
e_log, e_input, g_window, g_sound, g_gfx, g_player, Math,
g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture,
- g_items, wadreader, e_graphics, g_touch, SDL2;
+ g_items, wadreader, e_graphics, g_touch, SDL2, envvars;
+
+ var
+ machine: Integer;
+
+ function GenPlayerName (n: Integer): String;
+ begin
+ ASSERT(n >= 1);
+ Result := GetUserName;
+ if Result = '' then Result := 'Player' + IntToStr(machine MOD 10000);
+ if n > 1 then Result := Copy(Result, 1, 10) + (' ' + IntToStr(n))
+ end;
procedure g_Options_SetDefaultVideo;
var
with gPlayer1Settings do
begin
- Name := 'Player1';
+ Name := GenPlayerName(1);
Model := STD_PLAYER_MODEL;
Color.R := PLAYER1_DEF_COLOR.R;
Color.G := PLAYER1_DEF_COLOR.G;
with gPlayer2Settings do
begin
- Name := 'Player2';
+ Name := GenPlayerName(2);
Model := STD_PLAYER_MODEL;
Color.R := PLAYER2_DEF_COLOR.R;
Color.G := PLAYER2_DEF_COLOR.G;
config.Free();
end;
+initialization
+ machine := Random(10000)
end.
diff --git a/src/shared/envvars.pas b/src/shared/envvars.pas
index 941b8e0b78d548ef5b90cc1f71341e6c001f4853..3774eab2fe277edbd168c160de436c954d3c5007 100644 (file)
--- a/src/shared/envvars.pas
+++ b/src/shared/envvars.pas
interface
-uses SysUtils, CTypes;
+ uses SysUtils, CTypes;
-function SetEnvVar(const VarName: AnsiString; const VarVal: AnsiString): Boolean;
+ function SetEnvVar(const VarName: AnsiString; const VarVal: AnsiString): Boolean;
+ function GetUserName: String;
implementation
Result := (setenv(PChar(VarName), PChar(VarVal), 1) = 0);
end;
+ function GetUserName: String;
+ begin
+ {$IF DEFINED(WINDOWS)}
+ Result := SysUtils.GetEnvironmentVariable('USERNAME')
+ {$ELSEIF DEFINED(UNIX)}
+ Result := SysUtils.GetEnvironmentVariable('USER')
+ {$ELSE}
+ Result := ''
+ {$ENDIF}
+ end;
+
end.