Subversion Repositories plumbers

Compare Revisions

Regard whitespace Rev 12 → Rev 11

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