Subversion Repositories plumbers

Compare Revisions

Regard whitespace Rev 11 → Rev 12

/trunk/FileFormat/C/plumbers.h
6,6 → 6,9
#define SCENEID_PREVDECISION 32767
#define SCENEID_ENDGAME -1
 
#define SEGMENT_BEGINNING 0
#define SEGMENT_DECISION 1
 
#pragma pack(push, 1)
 
struct _coord {
15,7 → 18,7
 
struct _actionDef {
int32_t scoreDelta;
int16_t nextSceneID; // will jump to the scene with the name "SC<nextSceneID>"
int16_t nextSceneID; // will jump to the scene with the name "SCxx", where xx stands for nextSceneID (2 digits at least)
// 7FFF (32767) = end game
// FFFF ( -1) = go back to the last decision
int16_t sceneSegment; // 0 = scene from beginning, 1 = decision page
/trunk/FileFormat/Delphi/GameBinStruct.pas
8,6 → 8,9
SCENEID_PREVDECISION = -1;
SCENEID_ENDGAME = 32767;
 
SEGMENT_BEGINNING = 0;
SEGMENT_DECISION = 1;
 
type
PCoord = ^TCoord;
TCoord = packed record
18,7 → 21,8
PActionDef = ^TActionDef;
TActionDef = packed record
scoreDelta: Integer;
nextSceneID: SmallInt; // will jump to the scene with the name "SC<nextSceneID>"
nextSceneID: SmallInt; // will jump to the scene with the name "SCxx",
// where xx stands for nextSceneID (2 digits at least)
// 7FFF (32767) = end game
// FFFF ( -1) = go back to the last decision
sceneSegment: SmallInt; // 0 = scene from beginning, 1 = decision page
59,6 → 63,8
class function MaxPictureCount: integer; static;
 
function AddSceneAtEnd(SceneID: integer): PSceneDef;
function FindScene(SceneID: integer): PSceneDef;
function FindSceneIndex(SceneID: integer): integer;
procedure DeleteScene(SceneIndex: integer);
procedure SwapScene(IndexA, IndexB: integer);
procedure DeletePicture(PictureIndex: integer);
83,6 → 89,8
StrPLCopy(x^, s, Length(x^));
end;
 
{ TGameBinFile }
 
function TGameBinFile.BiggestUsedPictureIndex: integer;
var
iScene, candidate: integer;
95,11 → 103,16
end;
end;
 
resourcestring
S_INVALID_SCENE_ID = 'Invalid scene ID';
 
function TGameBinFile.AddSceneAtEnd(SceneID: integer): PSceneDef;
resourcestring
S_SCENE_FULL = 'Not enough space for another scene';
begin
if Self.numScenes >= Length(Self.scenes) then raise Exception.Create('Not enough space for another scene');
if SceneID < 0 then raise Exception.Create('Invalid scene ID');
if sceneID >= Length(Self.scenes) then raise Exception.Create('SceneID is too large.'); // TODO: I think this is not correct. This is the scene *ID*
if Self.numScenes >= Length(Self.scenes) then raise Exception.Create(S_SCENE_FULL);
if SceneID = $7FFF {Terminate program} then raise Exception.Create(S_INVALID_SCENE_ID);
if SceneID = $FFFF {Previous decision} then raise Exception.Create(S_INVALID_SCENE_ID);
result := @Self.scenes[Self.numScenes];
ZeroMemory(result, SizeOf(TSceneDef));
_WriteStringToFilename(@result.szSceneFolder, AnsiString(Format('SC%.2d', [sceneID])));
106,9 → 119,39
Inc(Self.numScenes);
end;
 
function TGameBinFile.FindSceneIndex(SceneID: integer): integer;
var
i: integer;
begin
if SceneID = $7FFF {Terminate program} then raise Exception.Create(S_INVALID_SCENE_ID);
if SceneID = $FFFF {Previous decision} then raise Exception.Create(S_INVALID_SCENE_ID);
for i := 0 to Self.numScenes - 1 do
begin
if Self.scenes[i].szSceneFolder = Format('SC%.2d', [SceneID]) then
begin
result := i;
exit;
end;
end;
result := -1;
end;
 
function TGameBinFile.FindScene(SceneID: integer): PSceneDef;
var
idx: integer;
begin
idx := FindSceneIndex(SceneID);
if idx >= 0 then
result := @Self.scenes[idx]
else
result := nil;
end;
 
procedure TGameBinFile.DeleteScene(SceneIndex: integer);
resourcestring
S_INVALID_SC_IDX = 'Invalid scene index';
begin
if ((SceneIndex < 0) or (SceneIndex >= Length(Self.scenes))) then raise Exception.Create('Invalid scene index');
if ((SceneIndex < 0) or (SceneIndex >= Length(Self.scenes))) then raise Exception.Create(S_INVALID_SC_IDX);
If SceneIndex < Length(Self.scenes)-1 then
begin
CopyMemory(@Self.scenes[SceneIndex], @Self.scenes[SceneIndex+1], (Length(Self.scenes)-SceneIndex-1)*SizeOf(TSceneDef));
277,16 → 320,20
result := false;
end;
 
resourcestring
S_INVALID_PIC_IDX = 'Invalid picture index';
S_PIC_FULL_DEFRAG = 'Not enough space for another picture. Please defrag to fill the gaps first.';
S_PIC_FULL = 'Not enough space for another picture. Maximum limit reached.';
var
iScene: integer;
begin
if ((Index < 0) or (Index >= Length(Self.pictures))) then raise Exception.Create('Invalid picture index');
if ((Index < 0) or (Index >= Length(Self.pictures))) then raise Exception.Create(S_INVALID_PIC_IDX);
 
if (BiggestUsedPictureIndex = MaxPictureCount-1) and Defrag(true) then
raise Exception.Create('Not enough space for another picture. Please defrag to fill the gaps first.');
raise Exception.Create(S_PIC_FULL_DEFRAG);
 
if Self.numPics >= MaxPictureCount then
raise Exception.Create('Not enough space for another picture. Maximum limit reached.');
raise Exception.Create(S_PIC_FULL);
 
if assignToUpperScene then
begin
/trunk/SceneEditor/Unit1.dfm
309,7 → 309,9
Height = 25
ColoredButtons = []
VisibleButtons = [btPlay]
DoubleBuffered = True
Visible = False
ParentDoubleBuffered = False
TabOrder = 14
end
object GroupBox2: TGroupBox
450,7 → 452,7
Top = 68
Width = 185
Height = 141
ActivePage = TabSheet6
ActivePage = TabSheet7
TabOrder = 17
object TabSheet6: TTabSheet
Caption = 'Scene length'
494,7 → 496,7
Caption = 'SceneIndex:'
end
object Label35: TLabel
Left = 98
Left = 90
Top = 16
Width = 12
Height = 13
508,7 → 510,7
Caption = 'PictureCount:'
end
object Label33: TLabel
Left = 98
Left = 90
Top = 35
Width = 12
Height = 13
522,7 → 524,7
Caption = 'PictureIndex:'
end
object Label31: TLabel
Left = 98
Left = 90
Top = 54
Width = 12
Height = 13
536,7 → 538,7
Caption = 'ActionCount:'
end
object Label37: TLabel
Left = 98
Left = 90
Top = 73
Width = 12
Height = 13
715,7 → 717,6
Width = 145
Height = 21
Style = csDropDownList
ItemHeight = 13
TabOrder = 0
OnChange = ActionTargetChange
end
750,7 → 751,6
Width = 145
Height = 21
Style = csDropDownList
ItemHeight = 13
TabOrder = 0
OnChange = ActionTargetChange
end
840,7 → 840,6
Width = 145
Height = 21
Style = csDropDownList
ItemHeight = 13
TabOrder = 0
OnChange = ActionTargetChange
end
/trunk/SceneEditor/Unit1.pas
204,7 → 204,6
procedure Load;
procedure Save;
procedure ReloadActionSceneLists;
function FindSceneIndex(sceneID: integer): integer;
function GetGreatestSceneID: integer;
function SearchSceneIDGapFromTop: integer;
procedure RedrawDecisionBitmap;
239,12 → 238,14
DEFAULT_FILENAME = 'DUMMY.BMP';
 
function GetSceneIDFromName(sceneName: string): Integer;
resourcestring
S_SCENENAME_INVALID = 'Scene name invalid';
var
sSceneID: string;
begin
if Copy(sceneName, 1, 2) <> 'SC' then raise Exception.Create('Scene name invalid');
if Copy(sceneName, 1, 2) <> 'SC' then raise Exception.Create(S_SCENENAME_INVALID);
sSceneID := Copy(sceneName, 3, 2);
if not TryStrToInt(sSceneID, result) then raise Exception.Create('Scene name invalid');
if not TryStrToInt(sSceneID, result) then raise Exception.Create(S_SCENENAME_INVALID);
end;
 
procedure SelectFilenameBase(Edit: TEdit);
334,10 → 335,11
Label29.Visible := false;
end;
 
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
resourcestring
S_COORDS = 'Coords: [%d, %d]';
begin
label10.Caption := Format('Coords: [%d, %d]', [Round(Image1.Picture.Width*(X/Image1.Width)),
label10.Caption := Format(S_COORDS, [Round(Image1.Picture.Width*(X/Image1.Width)),
Round(Image1.Picture.Height*(Y/Image1.Height))]);
end;
 
357,9 → 359,11
end;
 
procedure TForm1.Button10Click(Sender: TObject);
resourcestring
S_NOTFOUND = 'GAME.BIN saved; ShowTime32.exe not found.';
begin
Save;
if not FileExists('ShowTime32.exe') then raise Exception.Create('GAME.BIN saved; ShowTime32.exe not found.');
if not FileExists('ShowTime32.exe') then raise Exception.Create(S_NOTFOUND);
ShellExecute(Application.Handle, 'open', 'ShowTime32.exe', '', '', SW_NORMAL);
end;
 
615,8 → 619,10
end;
 
procedure TForm1.Button19Click(Sender: TObject);
resourcestring
S_DISCARD = 'Are you sure you want to discard all changes?';
begin
if MessageDlg('Are you sure you want to discard all changes?', mtConfirmation, mbYesNoCancel, 0) = mrYes then
if MessageDlg(S_DISCARD, mtConfirmation, mbYesNoCancel, 0) = mrYes then
begin
CopyMemory(@Game, @GameBak, SizeOf(Game));
SetupGUIAfterLoad;
624,6 → 630,8
end;
 
procedure TForm1.NewScene;
resourcestring
S_SCENE_FULL = 'No more space for another scene';
var
sceneID: integer;
newScene: PSceneDef;
630,7 → 638,7
begin
if ListBox1.Items.Count = 100 then
begin
raise Exception.Create('No more space for another scene');
raise Exception.Create(S_SCENE_FULL);
end;
 
sceneID := GetGreatestSceneID+1;
658,6 → 666,12
end;
 
procedure TForm1.Button2Click(Sender: TObject);
resourcestring
S_CONFLICT = 'Can''t delete this scene. There are following dependencies:'+#13#10#13#10+'%s';
S_SCENEID = 'Scene %s, action #%d';
// S_ONLYONE = 'Can''t delete the scene if there is only one.';
S_REALLY_DEL = 'Do you really want to delete scene %s?';
S_NEW_INTRO = 'Attention: This will make %s to your new intro sequence. Is that OK?';
var
iScene, iAction, sceneID: integer;
conflicts: TStringList;
669,7 → 683,7
(*
if ListBox1.Count = 1 then
begin
raise Exception.Create('Can''t delete the scene if there is only one.');
raise Exception.Create(S_ONLYONE);
end;
*)
 
682,21 → 696,21
begin
if Game.scenes[iScene].actions[iAction].nextSceneID = sceneID then
begin
conflicts.Add(Format('Scene %s, action #%d', [Game.scenes[iScene].szSceneFolder, iAction+1]));
conflicts.Add(Format(S_SCENEID, [Game.scenes[iScene].szSceneFolder, iAction+1]));
end;
end;
end;
if conflicts.Count > 0 then
begin
raise Exception.Create('Can''t delete this scene. There are following dependencies:'+#13#10#13#10+conflicts.Text);
raise Exception.CreateFmt(S_CONFLICT, [conflicts.Text]);
end;
finally
FreeAndNil(conflicts);
end;
 
sWarning := Format('Do you really want to delete scene %s?', [CurScene^.szSceneFolder]);
sWarning := Format(S_REALLY_DEL, [CurScene^.szSceneFolder]);
if (ListBox1.ItemIndex = 0) and (ListBox1.Count >= 2) then
sWarning := Format('Attention: This will make %s to your new intro sequence. Is that OK?', [ListBox1.Items[ListBox1.ItemIndex+1]]);
sWarning := Format(S_NEW_INTRO, [ListBox1.Items[ListBox1.ItemIndex+1]]);
if (MessageDlg(sWarning, mtConfirmation, mbYesNoCancel, 0) <> mrYes) then
begin
Exit;
811,6 → 825,8
end;
 
procedure TForm1.ActionTargetChange(Sender: TObject);
resourcestring
S_ASSERT_SENDER = 'Unexpected sender for ActionTargetChange()';
var
actionIdx: integer;
itemIdx: Integer;
818,7 → 834,7
if Sender = ComboBox1 then actionIdx := 0
else if Sender = ComboBox2 then actionIdx := 1
else if Sender = ComboBox3 then actionIdx := 2
else raise Exception.Create('Unexpected sender for ActionTargetChange()');
else raise Exception.Create(S_ASSERT_SENDER);
 
itemIdx := TComboBox(Sender).ItemIndex;
if itemIdx = 0 then
871,10 → 887,12
end;
 
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
resourcestring
S_SAVE_CHANGES = 'Do you want to save the changes?';
begin
if not CompareMem(@Game, @GameBak, SizeOf(Game)) then
begin
case MessageDlg('Do you want to save the changes?', mtConfirmation, mbYesNoCancel, 0) of
case MessageDlg(S_SAVE_CHANGES, mtConfirmation, mbYesNoCancel, 0) of
mrYes:
begin
Save;
911,9 → 929,12
end;
 
function TForm1.CurScene: PSceneDef;
resourcestring
S_NO_SCENE_AVAILABLE = 'No scenes available. Please create one.';
S_NO_SCENE_SELECTED = 'No scene selected. Please select one.';
begin
if ListBox1.Count = 0 then raise Exception.Create('No scene available. Please create one.');
if ListBox1.ItemIndex = -1 then raise Exception.Create('No scene selected. Please select one.');
if ListBox1.Count = 0 then raise Exception.Create(S_NO_SCENE_AVAILABLE);
if ListBox1.ItemIndex = -1 then raise Exception.Create(S_NO_SCENE_SELECTED);
result := @Game.scenes[ListBox1.ItemIndex];
end;
 
938,9 → 959,12
end;
 
function TForm1.CurPicture: PPictureDef;
resourcestring
S_NO_PICTURE_AVAILABLE = 'No pictures available. Please create one.';
S_NO_PICTURE_SELECTED = 'No picture selected. Please select one.';
begin
if ListBox2.Count = 0 then raise Exception.Create('No pictures available. Please create one.');
if ListBox2.ItemIndex = -1 then raise Exception.Create('No pictures selected. Please select one.');
if ListBox2.Count = 0 then raise Exception.Create(S_NO_PICTURE_AVAILABLE);
if ListBox2.ItemIndex = -1 then raise Exception.Create(S_NO_PICTURE_SELECTED);
result := @Game.pictures[CurScene^.pictureIndex + ListBox2.ItemIndex]
end;
 
1103,6 → 1127,8
end;
 
procedure TForm1.Load;
resourcestring
S_CORRECTED_PICTURE_COUNT = 'Picture count was wrong. Value was corrected.';
var
fs: TFileStream;
begin
1117,7 → 1143,7
 
if Game.RealPictureCount <> Game.numPics then
begin
MessageDlg('Picture count was wrong. Value was corrected.', mtInformation, [mbOk], 0);
MessageDlg(S_CORRECTED_PICTURE_COUNT, mtInformation, [mbOk], 0);
Game.numPics := Game.RealPictureCount;
end;
 
1124,23 → 1150,6
SetupGUIAfterLoad;
end;
 
function TForm1.FindSceneIndex(sceneID: integer): integer;
var
i: Integer;
sSceneID: string;
begin
sSceneID := Format('SC%.2d', [sceneID]);
for i := 0 to ListBox1.Count - 1 do
begin
if ListBox1.Items.Strings[i] = sSceneID then
begin
result := i;
exit;
end;
end;
result := -1;
end;
 
procedure TForm1.RecalcSlideshowLength;
var
i: integer;
1203,6 → 1212,8
procedure TForm1.RecalcSoundtrackLength;
var
FileName: string;
resourcestring
S_NA = 'n/a';
begin
if MediaPlayer1.Mode = mpPlaying then exit;
 
1209,7 → 1220,7
FileName := IncludeTrailingPathDelimiter(CurScene^.szSceneFolder) + CurScene^.szDialogWav;
if not FileExists(FileName) then
begin
Label23.Caption := 'n/a';
Label23.Caption := S_NA;
exit;
end;
MediaPlayer1.FileName := FileName;
1231,7 → 1242,7
ComboBox.ItemIndex := 1
else
begin
idx := FindSceneIndex(sceneID);
idx := Game.FindSceneIndex(sceneID);
if idx = -1 then
ComboBox.ItemIndex := -1
else
1321,6 → 1332,9
procedure TForm1.ReloadActionSceneLists;
 
procedure _ReloadActionSceneLists(ComboBox: TComboBox);
resourcestring
S_TERMINATE = 'Terminate program';
S_PREV_DEC = 'Previous decision';
var
prevSelection: string;
i: Integer;
1328,8 → 1342,8
prevSelection := ComboBox.Text;
try
ComboBox.Items.Clear;
ComboBox.Items.Add('Terminate program');
ComboBox.Items.Add('Previous decision');
ComboBox.Items.Add(S_TERMINATE);
ComboBox.Items.Add(S_PREV_DEC);
ComboBox.Items.AddStrings(ListBox1.Items);
finally
ComboBox.ItemIndex := 0;
/trunk/Win32_Player/Game.pas
41,7 → 41,6
procedure PrevDecisionScene;
protected
GameData: TGameBinFile;
function FindScene(ASceneID: integer): PSceneDef;
procedure Wait(AMilliseconds: integer);
procedure PlayScene(scene: PSceneDef; goToDecision: boolean);
public
83,21 → 82,6
end;
end;
 
function TGame.FindScene(ASceneID: integer): PSceneDef;
var
i: integer;
begin
for i := 0 to GameData.numScenes - 1 do
begin
if GameData.scenes[i].szSceneFolder = Format('SC%.2d', [ASceneID]) then
begin
result := @GameData.scenes[i];
exit;
end;
end;
result := nil;
end;
 
procedure TGame.TryExit;
begin
if Assigned(ExitCallback) then ExitCallback(Self);
119,9 → 103,9
TryExit
else
begin
nextScene := FindScene(action^.nextSceneID);
nextScene := GameData.FindScene(action^.nextSceneID);
if Assigned(nextScene) then
PlayScene(nextScene, action^.sceneSegment=1)
PlayScene(nextScene, action^.sceneSegment=SEGMENT_DECISION)
(*
else
raise Exception.CreateFmt('Scene %d was not found in GAME.BIN', [action^.nextSceneID]);
/trunk/Win32_Player/Main.pas
92,7 → 92,7
Temp := '';
for I := 1 to L2 do
begin
Temp := ThousandSeparator + Copy (S, LS - 3 * I + 1, 3) + Temp;
Temp := {$IF not Declared(ThousandSeparator)}FormatSettings.{$IFEND}ThousandSeparator + Copy (S, LS - 3 * I + 1, 3) + Temp;
end;
Result := Copy (S, N, (LS - 1) mod 3 + 1) + Temp;
if N > 1 then Result := '-' + Result;
101,6 → 101,8
{ TMainForm }
 
procedure TMainForm.cbPictureShow(ASender: TGame; AFilename: string; AType: TPictureType);
resourcestring
S_YOUR_SCORE = 'Your score is: %s';
begin
if FileExists(AFilename) then
begin
146,7 → 148,7
End;
end;
 
Panel1.Caption := Format('Your score is: %s', [AddThouSeps(IntToStr(ASender.Score))]);
Panel1.Caption := Format(S_YOUR_SCORE, [AddThouSeps(IntToStr(ASender.Score))]);
Panel1.Left := 8;
Panel1.Top := Min(ClientHeight, Screen.Height) - Panel1.Height - 8;
Panel1.Visible := AType = ptDecision;