# HG changeset patch
# User Maikel de Vries
# Date 1257437952 -3600
# Node ID c9a5b191a703327a00885a5da1663f112a61f34f
# Parent  d0076dbf91e497faa4f2bda91cf46f0768bdd048
System.c4g: GetTaggedPlayerName from engine to C4Script + some translations.

diff -r d0076dbf91e4 -r c9a5b191a703 planet/System.c4g/Commits.c
--- a/planet/System.c4g/Commits.c	Wed Nov 04 23:11:21 2009 +0100
+++ b/planet/System.c4g/Commits.c	Thu Nov 05 17:19:12 2009 +0100
@@ -2,52 +2,51 @@
 
 /*-- flgr --*/
 
-// Liefert das Offset zur gewünschten Landscape-X-Position zurück
+// Returns the offset to x.
 global func AbsX(int x) { return x - GetX(); }
 
-// Liefert das Offset zur gewünschten Landscape-Y-Position zurück
+// Returns the offset to y.
 global func AbsY(int y) { return y - GetY(); }
 
-// Unterstützt negative Werte und kann Zufallszahlen zwischen 2 Werten liefern
-
+// Supports negative values, and can deliver random values between two bounds.
 global func RandomX(int iStart, int iEnd) {
   var iSwap;
-  // Werte vertauscht: trotzdem richtig rechnen
+  // Values swapped: reswap them.
   if(iStart > iEnd) { iSwap=iStart; iStart=iEnd; iEnd=iSwap; }
-  // Zufälligen Faktor bestimmen (Differenz plus die null) und iStart aufrechnen
+  // Return random factor.
   return Random(iEnd-iStart+1)+iStart;
 }
 
-// Setzt die Fertigstellung von this auf iNewCon
+// Sets the completion of this to iNewCon. 
 global func SetCon(int new_con) {
   return DoCon(new_con - GetCon());
 }
 
-// Setzt X- und Y-Dir eines Objektes
+// Does not set the speed of an object. But you can set two components of the velocity vector with this function.
 global func SetSpeed(int x_dir, int y_dir, int prec) {
   SetXDir(x_dir, prec);
   SetYDir(y_dir, prec);
 }
 
-// Setzt X- und Y-Koordinate eines Vertices zugleich
+// Sets both the X and Y-coordinate of one vertex.
 global func SetVertexXY(int index, int x, int y) {
-  // Vertices setzen
+  // Set vertices
   SetVertex(index, VTX_X, x);
   SetVertex(index, VTX_Y, y);
 }
 
-// Liefert die Anzahl aller feststeckenden Vertices von this zurück
+// Returns the number of stuck vertices. (of this) 
 global func VerticesStuck() {
   var vertices;
   var x_offset;
   var y_offset;
 
-  // Vertices durchgehen
+  // Loop through vertices
   for (var i = -1; i < GetVertexNum(); i++) {
-    // solid?
+    // Solid?
     if (GBackSolid(x_offset + GetVertex(i, VTX_X),
                    y_offset + GetVertex(i, VTX_Y)))
-      // hochzählen
+      // Count vertices
       vertices++;
   }
   return vertices;
@@ -55,7 +54,7 @@
 
 /*-- Joern --*/
 
-//Fügt zum Konto des genannten Spielers iValue Gold hinzu
+// Adds iValue to the account of iPlayer.
 global func DoWealth(int iPlayer, int iValue)
 {
   return SetWealth(iPlayer, iValue + GetWealth(iPlayer));
@@ -64,12 +63,13 @@
 /*-- Tyron --*/
 
 
-// Prüft ob die angegebene Definition vorhanden ist
+// Checks whether the indicated definition is available.
 global func FindDefinition(id idDef) {
  if(GetDefCoreVal("id","DefCore",idDef)) return true;
 }
 
-// Erzeugt amount viele Objekte des Typs id im angegebenen Zielrechteck (optional) im angegeben Material. Gibt die Anzahl der Iterationen zurück, oder -1 wenn die Erzeugung fehlschlägt
+// Creates amount objects of type id inside the indicated rectangle(optional) in the indicated material. 
+// Returns the number of iterations needed, or -1 when the placement failed.
 global func PlaceObjects(id id,int amount,string strmat,int x,int y,int wdt,int hgt,bool onsf,bool nostuck) {
   var i,j;
   var rndx,rndy,obj;
@@ -163,18 +163,18 @@
   var iVisible = this["Visibility"];
   if (GetType(iVisible) == C4V_Array) iVisible = iVisible[0];
 
-  // garnicht sichtbar
+  // Not visible at all
   if(iVisible == VIS_None) return false;
-  // für jeden sichtbar
+  // Visible for all
   if(iVisible == VIS_All) return true;
 
-  // Objekt gehört dem anggb. Spieler
+  // Object is owned by the indicated player
   if(GetOwner() == iPlr)
     { if(iVisible & VIS_Owner) return true; }
-  // Objekt gehört einem Spieler, der iPlr feindlich gesonnen ist
+  // Object belongs to a player, hostile to iPlr
   else if(Hostile(GetOwner(),iPlr))
     { if(iVisible & VIS_Enemies) return true; }
-  // Objekt gehört einem Spieler, der iPlr freundlich gesonnen ist
+  // Object belongs to a player, friendly to iPlr
   else
     { if(iVisible & VIS_Allies) return true; }
 
@@ -185,18 +185,3 @@
   return false;
 }
 
-/*-- timi --*/
-
-global func GetPlayerByName(string strPlrName)
-{
-  // Alle Spieler durchgehen
-  var i = GetPlayerCount();
-  while (i--)
-    // Passt der Spielername mit dem gesuchten überein?
-    if (WildcardMatch(GetPlayerName(GetPlayerByIndex(i)), strPlrName))
-      // Wenn ja, Spielernummer zurückgeben!
-      return GetPlayerByIndex(i);
-    
-  // Es gibt keinen Spieler, der so heißt!
-  return -1;
-}
diff -r d0076dbf91e4 -r c9a5b191a703 planet/System.c4g/Player.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/planet/System.c4g/Player.c	Thu Nov 05 17:19:12 2009 +0100
@@ -0,0 +1,76 @@
+/*-- Player related functions --*/
+
+#strict 2
+
+// Returns the player number of szPlrName, or none if there is no such player. (written by timi for CR/CE/CP)
+global func GetPlayerByName(string szPlrName)
+{
+	// Loop through all players.
+	var i = GetPlayerCount();
+	while (i--)
+		// Does the player's name match the one searched for?
+		if (WildcardMatch(GetPlayerName(GetPlayerByIndex(i)), szPlrName))
+			// It does -> return player number.
+			return GetPlayerByIndex(i); 
+	// There is no player with that name.
+	return NO_OWNER;
+}
+
+// Returns the team number of szTeamName, or none if there is no such team.
+global func GetTeamByName(string szTeamName)
+{
+	// Loop through all teams.
+	var i = GetTeamCount();
+	while (i--)
+		// Does the team's name match the one searched for?
+		if (WildcardMatch(GetTeamName(GetTeamByIndex(i)), szTeamName))
+			// It does -> return team number.
+			return GetTeamByIndex(i); 
+	// There is no team with that name.
+	return NO_OWNER;
+}
+
+// Returns the name of a player, including color markup using the player color.
+global func GetTaggedPlayerName(int iPlr)
+{
+	var szPlrName = GetPlayerName(iPlr);
+	if (!szPlrName) 
+		return;
+	var iPlrColor = MakeColorReadable(GetPlrColor(iPlr));
+	var szTaggedPlrName = Format("<c %x>%s</c>", iPlrColor, szPlrName);
+	return szTaggedPlrName;
+}
+
+// Returns the name of a team, including color markup using the team color.
+global func GetTaggedTeamName(int iTeam)
+{
+	var szTeamName = GetTeamName(iTeam);
+	if (!szTeamName) 
+		return;
+	var iTeamColor = MakeColorReadable(GetTeamColor(iTeam));
+	var szTaggedTeamName = Format("<c %x>%s</c>", iTeamColor, szTeamName);
+	return szTaggedTeamName;
+}
+
+// Brightens dark colors, to be readable on dark backgrounds.
+global func MakeColorReadable(int dwColor)
+{
+	// Determine alpha.
+	var a = ((dwColor >> 24 & 255) << 24);
+	// Strip alpha.
+	dwColor = dwColor & 16777215;
+	// Calculate brightness: 50% red, 87% green, 27% blue (Max 164 * 255).
+	var r = (dwColor >> 16 & 255), g = (dwColor >> 8 & 255), b = (dwColor & 255);
+	var iLightness = r*50 + g*87 + b*27;
+	// Above 55/164 (*255) is okay.
+	if (iLightness < 14025) 
+	{
+		// Brighten up.
+		var inc = (14025 - iLightness) / 164;
+		dwColor = (Min(r+inc, 255)<<16) | (Min(g+inc, 255)<<8) | (Min(b+inc, 255));
+		
+	}
+	// Add alpha. not needed at the moment.
+	// dwColor = dwColor | a;
+	return dwColor;
+}
\ No newline at end of file
diff -r d0076dbf91e4 -r c9a5b191a703 src/game/script/C4Script.cpp
--- a/src/game/script/C4Script.cpp	Wed Nov 04 23:11:21 2009 +0100
+++ b/src/game/script/C4Script.cpp	Thu Nov 05 17:19:12 2009 +0100
@@ -1051,14 +1051,6 @@
 	return String(::Players.Get(iPlayer)->GetName());
 }
 
-static C4String *FnGetTaggedPlayerName(C4AulContext *cthr, long iPlayer)
-{
-	C4Player *pPlr = ::Players.Get(iPlayer);
-	if (!pPlr) return NULL;
-	DWORD dwClr = pPlr->ColorDw; C4GUI::MakeColorReadableOnBlack(dwClr);
-	return String(FormatString("<c %x>%s</c>", dwClr&0xffffff, pPlr->GetName()).getData());
-}
-
 static long FnGetPlayerType(C4AulContext *cthr, long iPlayer)
 {
 	C4Player *pPlr = ::Players.Get(iPlayer);
@@ -5657,7 +5649,6 @@
 	AddFunc(pEngine, "SetName", FnSetName);
 	AddFunc(pEngine, "GetDesc", FnGetDesc);
 	AddFunc(pEngine, "GetPlayerName", FnGetPlayerName);
-	AddFunc(pEngine, "GetTaggedPlayerName", FnGetTaggedPlayerName);
 	AddFunc(pEngine, "GetPlayerType", FnGetPlayerType);
 	AddFunc(pEngine, "SetXDir", FnSetXDir);
 	AddFunc(pEngine, "SetYDir", FnSetYDir);
