- Store index of color instead of its value
- Reset game config when switching pages
--- a/hedgewars/hwLibrary.pas Sat Nov 01 00:23:22 2014 +0300
+++ b/hedgewars/hwLibrary.pas Sat Nov 01 22:51:07 2014 +0300
@@ -151,6 +151,7 @@
registerGUIMessagesCallback,
flibInit,
flibFree,
+ resetGameConfig,
setSeed,
getSeed,
getThemesList,
--- a/hedgewars/uFLGameConfig.pas Sat Nov 01 00:23:22 2014 +0300
+++ b/hedgewars/uFLGameConfig.pas Sat Nov 01 22:51:07 2014 +0300
@@ -97,7 +97,13 @@
end;
procedure resetGameConfig; cdecl;
+var i: Longword;
begin
+ with currentConfig do
+ begin
+ for i:= 0 to 7 do
+ teams[i].hogsNumber:= 0
+ end
end;
procedure setSeed(seed: PChar); cdecl;
@@ -111,7 +117,7 @@
getSeed:= str2PChar(currentConfig.seed)
end;
-function getUnusedColor: shortstring;
+function getUnusedColor: Longword;
var i, c: Longword;
fColorMatched: boolean;
begin
@@ -119,7 +125,7 @@
i:= 0;
repeat
repeat
- fColorMatched:= (currentConfig.teams[i].hogsNumber > 0) and (currentConfig.teams[i].color = colorsSet[c]);
+ fColorMatched:= (currentConfig.teams[i].hogsNumber > 0) and (currentConfig.teams[i].color = c);
inc(i)
until (i >= 8) or (currentConfig.teams[i].hogsNumber = 0) or fColorMatched;
@@ -130,7 +136,7 @@
end;
until not fColorMatched;
- getUnusedColor:= colorsSet[c]
+ getUnusedColor:= c
end;
procedure runQuickGame; cdecl;
@@ -144,9 +150,9 @@
argumentsNumber:= 3;
teams[0]:= createRandomTeam;
- teams[0].color:= colorsSet[0];
+ teams[0].color:= 0;
teams[1]:= createRandomTeam;
- teams[1].color:= colorsSet[1];
+ teams[1].color:= 1;
teams[1].botLevel:= 1;
queueExecution;
@@ -201,7 +207,7 @@
var msg: ansistring;
i, hn, hedgehogsNumber: Longword;
team: PTeam;
- c: shortstring;
+ c: Longword;
begin
with currentConfig do
begin
--- a/hedgewars/uFLTeams.pas Sat Nov 01 00:23:22 2014 +0300
+++ b/hedgewars/uFLTeams.pas Sat Nov 01 22:51:07 2014 +0300
@@ -11,7 +11,7 @@
function teamByName(s: shortstring): PTeam;
implementation
-uses uFLUtils, uFLIPC, uPhysFSLayer;
+uses uFLUtils, uFLIPC, uPhysFSLayer, uFLData;
const MAX_TEAM_NAMES = 128;
var
@@ -47,7 +47,7 @@
begin
with team do
begin
- ipcToEngine('eaddteam <hash> ' + color + ' ' + teamName);
+ ipcToEngine('eaddteam <hash> ' + colorsSet[color] + ' ' + teamName);
for i:= 0 to Pred(hogsNumber) do
begin
ipcToEngine('eaddhh ' + inttostr(botLevel) + ' 100 ' + hedgehogs[i].name);
--- a/hedgewars/uFLTypes.pas Sat Nov 01 00:23:22 2014 +0300
+++ b/hedgewars/uFLTypes.pas Sat Nov 01 22:51:07 2014 +0300
@@ -24,7 +24,7 @@
graveName: shortstring;
fortName: shortstring;
owner: shortstring;
- color: shortstring;
+ color: Longword;
extDriven: boolean;
botLevel: Longword;
hedgehogs: array[0..7] of THedgehog;
--- a/qmlFrontend/flib.h Sat Nov 01 00:23:22 2014 +0300
+++ b/qmlFrontend/flib.h Sat Nov 01 22:51:07 2014 +0300
@@ -31,6 +31,7 @@
typedef void getPreview_t();
typedef void runQuickGame_t();
typedef void runLocalGame_t();
+typedef void resetGameConfig_t();
typedef void setSeed_t(const char * seed);
typedef char *getSeed_t();
typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
--- a/qmlFrontend/hwengine.cpp Sat Nov 01 00:23:22 2014 +0300
+++ b/qmlFrontend/hwengine.cpp Sat Nov 01 22:51:07 2014 +0300
@@ -18,6 +18,7 @@
runLocalGame_t *flibRunLocalGame;
flibInit_t *flibInit;
flibFree_t *flibFree;
+ resetGameConfig_t * flibResetGameConfig;
getThemesList_t *flibGetThemesList;
freeThemesList_t *flibFreeThemesList;
getThemeIcon_t *flibGetThemeIcon;
@@ -53,6 +54,7 @@
flibFreeThemesList = (freeThemesList_t*) hwlib.resolve("freeThemesList");
flibGetThemeIcon = (getThemeIcon_t*) hwlib.resolve("getThemeIcon");
+ flibResetGameConfig = (resetGameConfig_t*) hwlib.resolve("resetGameConfig");
flibGetTeamsList = (getTeamsList_t*) hwlib.resolve("getTeamsList");
flibTryAddTeam = (tryAddTeam_t*) hwlib.resolve("tryAddTeam");
flibTryRemoveTeam = (tryRemoveTeam_t*) hwlib.resolve("tryRemoveTeam");
@@ -183,3 +185,8 @@
{
flibTryRemoveTeam(teamName.toUtf8().constData());
}
+
+void HWEngine::resetGameConfig()
+{
+ flibResetGameConfig();
+}
--- a/qmlFrontend/hwengine.h Sat Nov 01 00:23:22 2014 +0300
+++ b/qmlFrontend/hwengine.h Sat Nov 01 22:51:07 2014 +0300
@@ -23,6 +23,7 @@
Q_INVOKABLE void runLocalGame();
Q_INVOKABLE QString currentSeed();
Q_INVOKABLE void getTeamsList();
+ Q_INVOKABLE void resetGameConfig();
Q_INVOKABLE void tryAddTeam(const QString & teamName);
Q_INVOKABLE void tryRemoveTeam(const QString & teamName);
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml Sat Nov 01 00:23:22 2014 +0300
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml Sat Nov 01 22:51:07 2014 +0300
@@ -173,6 +173,7 @@
}
Component.onCompleted: {
+ HWEngine.resetGameConfig()
HWEngine.getTeamsList()
HWEngine.getPreview()
}