//============================================================================== // // Name: Debug Utilities // Author: vjeux from sc2mapster.com // //============================================================================== string BoolToString (bool b); string FixedToString (fixed f, int precision); string PointToString (point p); string OrderToString (order o); string UnitToString (unit u); string PlayerToString (int p); void d (string s); // Debug String void dt (text s); // Debug Text void di (int i); // Debug Int void df (fixed f); // Debug Fixed void db (bool b); // Debug Bool void dp (point p); // Debug Point void dpl (int p); // Debug Player void dord(order o); // Debug Order void du (unit u); // Debug Unit void dg (unitgroup g); // Debug UnitGroup void duo (unit u); // Debug Unit Orders void print (int loc, string msg); // Print a Message at an area //============================================================================== // Conversions string BoolToString(bool b) { if (b) { return "true"; } else { return "false"; } } string FixedToString(fixed f, int precision) { string s = ""; int g; if (precision < 0) { precision = 0; } //Negative case if (f < 0) { s = "-"; f = -f; } // "Real" part g = FixedToInt(f); s = s + IntToString(g); f = f - g; if (precision != 0 && f != 0) { s = s + "."; // Decimal part do { f = f * 10; g = FixedToInt(f); s = s + IntToString(g); f = f - g; precision = precision - 1; } while (f != 0 && precision != 0); } return s; } string PointToString(point p) { if (p == null) { return "null"; } return "Point(" + FixedToString(PointX(p), 2) + ", " + FixedToString(PointY(p), 2) + ")"; } string UnitToString(unit u) { if (u == null) { return "null"; } return "Unit(" + UnitGetType(u) + ", " + PlayerToString(UnitGetOwner(u)) + ", " + PointToString(UnitGetPosition(u)) + ", " + IntToString(UnitGetPropertyInt(u, 24, true)) + ")"; } string PlayerToString(int p) { return "Player " + IntToString(p) + " (" // Can't use the following, return text instead of string ... // + PlayerColorName(PlayerGetColorIndex(p, false)) // + ", " + PlayerRace(p) + ")"; } string OrderToString(order o) { string s = ""; int targetType; unit targetUnit; point targetPoint; if (o == null) { return "null"; } s += "Order(" + PlayerToString(OrderGetPlayer(o)) + ", " + AbilityCommandGetAbility(OrderGetAbilityCommand(o)) + ", "; targetType = OrderGetTargetType(o); if (targetType == 1) { s += PointToString(OrderGetTargetPoint(o)); } else if (targetType == 2) { s += UnitToString(OrderGetTargetUnit(o)); } s += ")"; return s; } // Helpers void dt(text s) { TriggerDebugOutput(1, s, false); } void d(string s) { dt(StringToText(s)); } void di(int i) { d(IntToString(i)); } void df(fixed f) { d(FixedToString(f, 10)); } void db(bool b) { d(BoolToString(b)); } void dp(point p) { d(PointToString(p)); } void dord(order o) { d(OrderToString(o)); } void dpl(int p) { d(PlayerToString(p)); } void du(unit u) { d(UnitToString(u)); } void print(int loc, string msg) { UIDisplayMessage(PlayerGroupAll(), loc, StringToText(msg)); } void dg(unitgroup g) { int max = UnitGroupCount(g, 0); int i = 1; if (g == null) { d("(null)"); return; } d("-- UnitGroup --"); while (i <= max) { du(UnitGroupUnit(g, i)); i += 1; } } void duo(unit u) { int i; int count; if (u == null) { d("(null)"); return; } d("-- Unit --"); du(u); i = 0; count = UnitOrderCount(u); while (i < count) { dord(UnitOrder(u, i)); i += 1; } if (count == 0) { d("No Order"); } }