2010-09-13 15:27:48 +00:00
|
|
|
/*--
|
2010-03-30 17:16:26 +00:00
|
|
|
Player.c
|
2012-04-03 01:12:44 +00:00
|
|
|
Authors: timi, Maikel, Joern, Zapper, Randrian
|
2009-12-29 13:44:16 +00:00
|
|
|
|
2010-03-30 13:33:21 +00:00
|
|
|
Player and team related functions.
|
|
|
|
--*/
|
2009-12-29 13:44:16 +00:00
|
|
|
|
2010-03-30 13:33:21 +00:00
|
|
|
|
|
|
|
// Returns the player number of plr_name, or none if there is no such player. (written by timi for CR/CE/CP)
|
|
|
|
global func GetPlayerByName(string plr_name)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
|
|
|
// Loop through all players.
|
|
|
|
var i = GetPlayerCount();
|
|
|
|
while (i--)
|
|
|
|
// Does the player's name match the one searched for?
|
2010-03-30 13:33:21 +00:00
|
|
|
if (WildcardMatch(GetPlayerName(GetPlayerByIndex(i)), plr_name))
|
2009-12-29 13:44:16 +00:00
|
|
|
// It does -> return player number.
|
2010-09-13 15:27:48 +00:00
|
|
|
return GetPlayerByIndex(i);
|
2009-12-29 13:44:16 +00:00
|
|
|
// There is no player with that name.
|
|
|
|
return NO_OWNER;
|
|
|
|
}
|
|
|
|
|
2010-03-30 13:33:21 +00:00
|
|
|
// Returns the team number of team_name, or none if there is no such team.
|
|
|
|
global func GetTeamByName(string team_name)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
|
|
|
// Loop through all teams.
|
|
|
|
var i = GetTeamCount();
|
|
|
|
while (i--)
|
|
|
|
// Does the team's name match the one searched for?
|
2010-03-30 13:33:21 +00:00
|
|
|
if (WildcardMatch(GetTeamName(GetTeamByIndex(i)), team_name))
|
2009-12-29 13:44:16 +00:00
|
|
|
// It does -> return team number.
|
2010-09-13 15:27:48 +00:00
|
|
|
return GetTeamByIndex(i);
|
2009-12-29 13:44:16 +00:00
|
|
|
// There is no team with that name.
|
|
|
|
return NO_OWNER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the name of a player, including color markup using the player color.
|
2010-03-30 13:33:21 +00:00
|
|
|
global func GetTaggedPlayerName(int plr)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-03-30 13:33:21 +00:00
|
|
|
var plr_name = GetPlayerName(plr);
|
2010-09-13 15:27:48 +00:00
|
|
|
if (!plr_name)
|
2009-12-29 13:44:16 +00:00
|
|
|
return;
|
2010-04-18 10:27:44 +00:00
|
|
|
var plr_color = MakeColorReadable(GetPlayerColor(plr));
|
2010-03-30 13:33:21 +00:00
|
|
|
var tagged_plr_name = Format("<c %x>%s</c>", plr_color, plr_name);
|
|
|
|
return tagged_plr_name;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the name of a team, including color markup using the team color.
|
2010-03-30 13:33:21 +00:00
|
|
|
global func GetTaggedTeamName(int team)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2010-03-30 13:33:21 +00:00
|
|
|
var team_name = GetTeamName(team);
|
2010-09-13 15:27:48 +00:00
|
|
|
if (!team_name)
|
2009-12-29 13:44:16 +00:00
|
|
|
return;
|
2010-03-30 13:33:21 +00:00
|
|
|
var team_color = MakeColorReadable(GetTeamColor(team));
|
|
|
|
var tagged_team_name = Format("<c %x>%s</c>", team_color, team_name);
|
|
|
|
return tagged_team_name;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Brightens dark colors, to be readable on dark backgrounds.
|
2010-03-30 13:33:21 +00:00
|
|
|
global func MakeColorReadable(int color)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
2012-02-20 11:58:58 +00:00
|
|
|
// Determine alpha. Not needed at the moment
|
|
|
|
//var a = ((color >> 24 & 255) << 24);
|
2009-12-29 13:44:16 +00:00
|
|
|
// Strip alpha.
|
2010-03-30 13:33:21 +00:00
|
|
|
color = color & 16777215;
|
2009-12-29 13:44:16 +00:00
|
|
|
// Calculate brightness: 50% red, 87% green, 27% blue (Max 164 * 255).
|
2010-03-30 13:33:21 +00:00
|
|
|
var r = (color >> 16 & 255), g = (color >> 8 & 255), b = (color & 255);
|
|
|
|
var lightness = r * 50 + g * 87 + b * 27;
|
|
|
|
// Above 55 / 164 (*255) is okay.
|
2010-09-13 15:27:48 +00:00
|
|
|
if (lightness < 14025)
|
2009-12-29 13:44:16 +00:00
|
|
|
{
|
|
|
|
// Brighten up.
|
2010-03-30 13:33:21 +00:00
|
|
|
var inc = (14025 - lightness) / 164;
|
|
|
|
color = (Min(r + inc, 255) << 16) | (Min(g + inc, 255) << 8) | (Min(b + inc, 255));
|
2009-12-29 13:44:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
// Add alpha. not needed at the moment.
|
2010-03-30 13:33:21 +00:00
|
|
|
// color = color | a;
|
|
|
|
return color;
|
2009-12-29 13:44:16 +00:00
|
|
|
}
|
2012-04-03 00:55:55 +00:00
|
|
|
|
|
|
|
// Adds value to the account of iPlayer.
|
|
|
|
global func DoWealth(int plr, int value)
|
|
|
|
{
|
|
|
|
return SetWealth(plr, value + GetWealth(plr));
|
|
|
|
}
|
|
|
|
|
2012-06-05 20:51:09 +00:00
|
|
|
// checks whether two players are allied - that means they are not hostile and neither of them is NO_OWNER
|
|
|
|
global func IsAllied(int plr1, int plr2, bool check_one_way_only /* whether to check the hostility only in one direction */)
|
2012-04-03 00:55:55 +00:00
|
|
|
{
|
|
|
|
if(plr1 == NO_OWNER) return false;
|
|
|
|
if(plr2 == NO_OWNER) return false;
|
|
|
|
return !Hostile(plr1, plr2, check_one_way_only);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shows a message window to player for_plr.
|
|
|
|
global func MessageWindow(string msg, int for_plr, id icon, string caption)
|
|
|
|
{
|
|
|
|
// Get icon.
|
|
|
|
if (!icon)
|
|
|
|
icon = GetID();
|
|
|
|
// Get caption.
|
|
|
|
if (!caption)
|
|
|
|
caption = GetName();
|
2014-08-21 17:55:32 +00:00
|
|
|
// Create msg window as regular text
|
|
|
|
CustomMessage(Format("<c ffff00>%s</c>: %s", caption, msg), nil, for_plr, 0,150, nil, GUI_MenuDeco, icon, MSG_HCenter);
|
2012-04-03 00:55:55 +00:00
|
|
|
return true;
|
2012-04-03 01:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find a base of the given player. Use index to search through all bases.
|
|
|
|
global func FindBase (int iPlr, int iIndex)
|
|
|
|
{
|
|
|
|
return FindObjects(Find_Owner(iPlr), Find_Func("IsBase"))[iIndex];
|
2012-06-05 20:51:09 +00:00
|
|
|
}
|