aboutsummaryrefslogtreecommitdiffstats
path: root/Lua/src/lua/ULuaParty.pas
diff options
context:
space:
mode:
authorwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-05-16 18:05:28 +0000
committerwhiteshark0 <whiteshark0@b956fd51-792f-4845-bead-9b4dfca2ff2c>2009-05-16 18:05:28 +0000
commit709665c02cfb5cbaf502e3d28f2d53fbe09477b5 (patch)
treefe1bb5db9d7d42a96c394c7b5d57143e1b6267cf /Lua/src/lua/ULuaParty.pas
parented35a20497939eca68ebd05c18a92b3cf95bebbb (diff)
downloadusdx-709665c02cfb5cbaf502e3d28f2d53fbe09477b5.tar.gz
usdx-709665c02cfb5cbaf502e3d28f2d53fbe09477b5.tar.xz
usdx-709665c02cfb5cbaf502e3d28f2d53fbe09477b5.zip
new party round ranking system
if 3 teams play winner(s) gets 3 points, those who placed second gets 1 point. (third 0 points ;) Usdx.Party.SetWinner renamed to Usdx.Party.SetRoundRanking UParty and ULuaParty adapted to new system git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1740 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to '')
-rw-r--r--Lua/src/lua/ULuaParty.pas52
1 files changed, 43 insertions, 9 deletions
diff --git a/Lua/src/lua/ULuaParty.pas b/Lua/src/lua/ULuaParty.pas
index 76bc02ef..883c3aec 100644
--- a/Lua/src/lua/ULuaParty.pas
+++ b/Lua/src/lua/ULuaParty.pas
@@ -57,10 +57,17 @@ function ULuaParty_Register(L: Plua_State): Integer; cdecl;
of current game were played }
function ULuaParty_GameFinished(L: Plua_State): Integer; cdecl;
-{ Party.SetWinner - sets winner of current party round,
+(* Party.SetRoundRanking - sets ranking of current party round,
+ arguments: Ranking: table
+ ranking of team i is the value (integer from 1 to number of teams) of the
+ table with index [i: number].
+ you may call this function in the following way:
+ Party.SetRoundRanking({3, 1, 2});
+ this means: team 1 is ranked third, team 2 is ranked first and team 3 is
+ ranked second.
if no party game is started or party game is finished
- it will raise an error }
-function ULuaParty_SetWinner(L: Plua_State): Integer; cdecl;
+ it will raise an error *)
+function ULuaParty_SetRoundRanking(L: Plua_State): Integer; cdecl;
{ Party.GetTeams - returns a table with all information and structure as
in the TPartyGame.Teams array }
@@ -74,7 +81,7 @@ const
ULuaParty_Lib_f: array [0..4] of lual_reg = (
(name:'Register'; func:ULuaParty_Register),
(name:'GameFinished'; func:ULuaParty_GameFinished),
- (name:'SetWinner'; func:ULuaParty_SetWinner),
+ (name:'SetRoundRanking'; func:ULuaParty_SetRoundRanking),
(name:'GetTeams'; func:ULuaParty_GetTeams),
(name:'SetTeams'; func:ULuaParty_SetTeams)
);
@@ -171,17 +178,44 @@ begin
Result := 1;
end;
-{ Party.SetWinner - sets winner of current party round,
+{ Party.SetRoundRanking - sets ranking of current party round,
if no party game is started or party game is finished
it will raise an error }
-function ULuaParty_SetWinner(L: Plua_State): Integer; cdecl;
+function ULuaParty_SetRoundRanking(L: Plua_State): Integer; cdecl;
+var
+ R: AParty_TeamRanking;
+ I: Integer;
+ Rank: Integer;
begin
Result := 0;
-
+
luaL_checktype(L, 1, LUA_TTABLE);
- if (not Party.SetWinner(Lua_ToBinInt(L, 1))) then
- luaL_error(L, PChar('cann''t set party winner. Is party started and not finished yet?'));
+ lua_checkstack(L, 1);
+
+ SetLength(R, Length(Party.Teams));
+
+ for I := 0 to High(R) do
+ begin
+ lua_pushInteger(L, I);
+ lua_gettable(L, 1);
+
+ R[I].Rank := Length(R);
+ if (lua_isnumber(L, -1)) then
+ begin
+ Rank := lua_toInteger(L, -1);
+ if (Rank >= 1) and (Rank <= Length(R)) then
+ R[I].Rank := Rank;
+ end;
+
+ lua_pop(L, 1);
+ end;
+
+ // pop table
+ lua_pop(L, 1);
+
+ if (not Party.SetRanking(R)) then
+ luaL_error(L, PChar('cann''t set party round ranking. Is party started and not finished yet?'));
end;
{ Party.GetTeams - returns a table with all information and structure as