Skip to content

Commit e725984

Browse files
ADD: Waypoint preview for Air and Ground units
1 parent 3919219 commit e725984

File tree

6 files changed

+412
-90
lines changed

6 files changed

+412
-90
lines changed

client/uctd.pas

Lines changed: 82 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,7 +3268,8 @@
32683268
Else Begin
32693269
// Der Server hat die Datei schon, dann ist eh alles I.O. :-)
32703270
End;
3271-
cbBE(self, true);
3271+
If assigned(cbBE) Then
3272+
cbBE(self, true);
32723273
End;
32733274
miFilesToTransmitCount: Begin
32743275
m := TMemorystream.create;
@@ -3358,10 +3359,13 @@
33583359
fmap.CreateDamageClassTextures;
33593360
fmap.EditTerrain := false;
33603361
If GetValue('Global', 'ShowOppoentsPathOnWaveStart', '1') = '1' Then Begin
3361-
fmap.CreateWavePreviewPath(PlayerIndex);
3362+
fmap.CreateWavePreviewPath(fAktualWave, PlayerIndex);
3363+
fmap.CreateAirWavePreviewPath(fAktualWave, PlayerIndex);
3364+
fmap.CalculateWavePreviewOffsets;
33623365
End
33633366
Else Begin
3364-
setlength(fmap.WaypointPreviewDirections, 0);
3367+
setlength(fmap.WaypointPreview.Points, 0);
3368+
setlength(fmap.AirWaypointPreview.Points, 0);
33653369
End;
33663370
For i := 0 To high(fPlayerInfos) Do Begin
33673371
fPlayerInfos[i].KillsOnWaveStart := fPlayerInfos[i].Kills + fPlayerInfos[i].BonusFinisher;
@@ -3893,15 +3897,71 @@
38933897
Begin
38943898
result := 0;
38953899
// Die Hauptrichtungen
3896-
If wpdLeftToRight In directions Then result := 0;
3897-
If wpdRightToLeft In directions Then result := 2;
3898-
If wpdTopToBottom In directions Then result := 3;
3899-
If wpdBottomToTop In directions Then result := 1;
3900+
If wpdRightToLeft In directions Then result := 0;
3901+
If wpdLeftToRight In directions Then result := 1;
3902+
If wpdTopToBottom In directions Then result := 2;
3903+
If wpdBottomToTop In directions Then result := 3;
39003904
// Nun Kommen die Diagonalen
3901-
If (wpdLeftToRight In directions) And (wpdTopToBottom In directions) Then result := 7;
3902-
If (wpdLeftToRight In directions) And (wpdBottomToTop In directions) Then result := 4;
3905+
If (wpdRightToLeft In directions) And (wpdBottomToTop In directions) Then result := 4;
3906+
If (wpdLeftToRight In directions) And (wpdBottomToTop In directions) Then result := 5;
39033907
If (wpdRightToLeft In directions) And (wpdTopToBottom In directions) Then result := 6;
3904-
If (wpdRightToLeft In directions) And (wpdBottomToTop In directions) Then result := 5;
3908+
If (wpdLeftToRight In directions) And (wpdTopToBottom In directions) Then result := 7;
3909+
End;
3910+
3911+
Procedure RenderWayPointPreview(Const WayPointPreview: TWaypointPreview; Offset: integer);
3912+
Const
3913+
DirectionsRotated: Array[0..7] Of Tpoint = (// Alle Einträge von Directions gedreht um 90° gegen den Uhrzeigersinn
3914+
(x: 0; y: - 1),
3915+
(x: 0; y: + 1),
3916+
(x: + 1; y: 0),
3917+
(x: - 1; y: 0),
3918+
(x: + 1; y: - 1),
3919+
(x: + 1; y: + 1),
3920+
(x: - 1; y: - 1),
3921+
(x: - 1; y: + 1)
3922+
);
3923+
Var
3924+
c, x, y, i, DirectionIndex: integer;
3925+
gi: TGraphikItem;
3926+
OffsetP: TPoint;
3927+
Begin
3928+
c := 0;
3929+
For i := 0 To high(WaypointPreview.Points) Do Begin
3930+
DirectionIndex := WaypointDirectionsToIndex(WaypointPreview.Points[i].Directions);
3931+
glPushMatrix;
3932+
x := WaypointPreview.Points[i].Location.x;
3933+
y := WaypointPreview.Points[i].Location.y;
3934+
OffsetP := point(0, 0);
3935+
If WaypointPreview.Points[i].Offsetted Then Begin
3936+
OffsetP := DirectionsRotated[DirectionIndex] * Offset;
3937+
End;
3938+
glTranslatef(x * MapBlockSize - fsx + fMapL, y * MapBlockSize - fsy + fMapT, ctd_Buy_Preview_Layer);
3939+
glTranslatef(0, 0, ctd_EPSILON);
3940+
glScalef(MapBlockSize / 10, MapBlockSize / 10, 1);
3941+
glTranslatef(OffsetP.x, OffsetP.Y, 0);
3942+
glColor4f(1, 1, 1, 1);
3943+
If i Mod 2 = 0 Then Begin // Nur jeden 2. Rendern, sieht gleich viel besser aus ;)
3944+
// Die Pfeile sind kleiner
3945+
glTranslatef(2.5, 2.5, 0);
3946+
glScalef(0.5, 0.5, 1);
3947+
RenderAlphaTiledQuad(0, 0, DirectionIndex, 8, 1, fWaypointDirectionTexs);
3948+
End
3949+
Else Begin
3950+
// Die Klassen genau eine Kachel Groß
3951+
glTranslatef(0, 0, ctd_EPSILON);
3952+
c := c Mod length(WayPointPreview.DamageClasses);
3953+
gi := fMap.OpenGLArrowDamageClassTex[WayPointPreview.DamageClasses[c]];
3954+
glScalef(10 / gi.OrigWidth, 10 / gi.OrigHeight, 1);
3955+
If gi.IsAlphaImage Then Begin
3956+
RenderAlphaQuad(0, 0, gi);
3957+
End
3958+
Else Begin
3959+
RenderQuad(0, 0, gi);
3960+
End;
3961+
inc(c);
3962+
End;
3963+
glPopMatrix;
3964+
End;
39053965
End;
39063966

39073967
Var
@@ -3933,7 +3993,6 @@
39333993
fkeyRepeatTimeStamp := t;
39343994
FOnKeyPress();
39353995
End;
3936-
39373996
Case fgameState Of
39383997
gs_WaitForJoin: Begin
39393998
glColor4f(1, 1, 1, 1);
@@ -3970,19 +4029,8 @@
39704029
CenterTextOut(w, h, 'The game has been paused.');
39714030
End;
39724031
// Anzeigen des Weg Previews
3973-
For i := 0 To high(fMap.WaypointPreviewDirections) Do Begin
3974-
If i Mod 2 = 1 Then Begin // Nur jeden 2. Rendern, sieht gleich viel besser aus ;)
3975-
glPushMatrix;
3976-
x := fMap.WaypointPreviewDirections[i].Location.x;
3977-
y := fMap.WaypointPreviewDirections[i].Location.y;
3978-
glTranslatef(x * MapBlockSize - fsx + fMapL, y * MapBlockSize - fsy + fMapT, ctd_Buy_Preview_Layer);
3979-
glTranslatef(0, 0, ctd_EPSILON);
3980-
glScalef(MapBlockSize / 10, MapBlockSize / 10, 1);
3981-
glColor4f(1, 1, 1, 1);
3982-
RenderAlphaTiledQuad(0, 0, WaypointDirectionsToIndex(fMap.WaypointPreviewDirections[i].Directions), 8, 1, fWaypointDirectionTexs);
3983-
glPopMatrix;
3984-
End;
3985-
End;
4032+
RenderWayPointPreview(fMap.WaypointPreview, -5);
4033+
RenderWayPointPreview(fMap.AirWaypointPreview, 5);
39864034
// Anzeigen des zu kaufenden Objekts
39874035
If assigned(FBuyingObject) Then Begin
39884036
x := (fsx + fCursorPos.x - fMapL) Div MapBlockSize;
@@ -4614,7 +4662,14 @@
46144662
b := TBuilding.create();
46154663
b.LoadFromFile(MapFolder + MapName + PathDelim + Name);
46164664
b.Owner := Owner;
4617-
If Not fMap.AddBuilding(x, y, b) Then Begin
4665+
If fMap.AddBuilding(x, y, b) Then Begin
4666+
// Neu Berechnen der Wegpunkt Previes, diese könnten sich ja geändert haben ;)
4667+
If Assigned(fMap.WaypointPreview.Points) Then Begin
4668+
fmap.CreateWavePreviewPath(fAktualWave, PlayerIndex);
4669+
fmap.CalculateWavePreviewOffsets;
4670+
End;
4671+
End
4672+
Else Begin
46184673
(*
46194674
* Eigentlich hat der Server alles Geprüft, das Gebäude muss hier immer Akzeptiert werden
46204675
* Wenn aber doch nicht, dann geben wir es wenigstens frei ...
@@ -4918,7 +4973,8 @@
49184973
End
49194974
Else Begin
49204975
// Wir sollen eine Datei senden die es gar nicht gibt -> Fehler
4921-
Callback(self, false);
4976+
If assigned(Callback) Then
4977+
Callback(self, false);
49224978
End;
49234979
LogLeave;
49244980
End;

client/unit4.pas

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@
724724
End;
725725

726726
Procedure TForm4.Button13Click(Sender: TObject);
727+
Var
728+
s: String;
727729
Begin
728730
// Set Damageclass 1
729731
If OpenPictureDialog1.Execute Then Begin
@@ -734,10 +736,17 @@
734736
fTransferFilename := OpenPictureDialog1.FileName;
735737
fOnTransferFileDoneReason := frDC1Tex;
736738
ctd.TransferFile(fTransferFilename, 'dc1.png', @OnTransferFileDone);
739+
// Gibt es eine "Arrow" Textur, wird diese automatisch nachgeladen
740+
s := ExtractFileNameWithoutExt(fTransferFilename) + '_arrow' + ExtractFileExt(fTransferFilename);
741+
If FileExistsUTF8(s) Then Begin
742+
ctd.TransferFile(s, 'dc1_arrow.png', Nil);
743+
End;
737744
End;
738745
End;
739746

740747
Procedure TForm4.Button14Click(Sender: TObject);
748+
Var
749+
s: String;
741750
Begin
742751
// Set Damageclass 2
743752
If OpenPictureDialog1.Execute Then Begin
@@ -748,10 +757,17 @@
748757
fTransferFilename := OpenPictureDialog1.FileName;
749758
fOnTransferFileDoneReason := frDC2Tex;
750759
ctd.TransferFile(fTransferFilename, 'dc2.png', @OnTransferFileDone);
760+
// Gibt es eine "Arrow" Textur, wird diese automatisch nachgeladen
761+
s := ExtractFileNameWithoutExt(fTransferFilename) + '_arrow' + ExtractFileExt(fTransferFilename);
762+
If FileExistsUTF8(s) Then Begin
763+
ctd.TransferFile(s, 'dc2_arrow.png', Nil);
764+
End;
751765
End;
752766
End;
753767

754768
Procedure TForm4.Button15Click(Sender: TObject);
769+
Var
770+
s: String;
755771
Begin
756772
// Set Damageclass 3
757773
If OpenPictureDialog1.Execute Then Begin
@@ -762,10 +778,17 @@
762778
fTransferFilename := OpenPictureDialog1.FileName;
763779
fOnTransferFileDoneReason := frDC3Tex;
764780
ctd.TransferFile(fTransferFilename, 'dc3.png', @OnTransferFileDone);
781+
// Gibt es eine "Arrow" Textur, wird diese automatisch nachgeladen
782+
s := ExtractFileNameWithoutExt(fTransferFilename) + '_arrow' + ExtractFileExt(fTransferFilename);
783+
If FileExistsUTF8(s) Then Begin
784+
ctd.TransferFile(s, 'dc3_arrow.png', Nil);
785+
End;
765786
End;
766787
End;
767788

768789
Procedure TForm4.Button16Click(Sender: TObject);
790+
Var
791+
s: String;
769792
Begin
770793
// Set Damageclass 4
771794
If OpenPictureDialog1.Execute Then Begin
@@ -776,6 +799,11 @@
776799
fTransferFilename := OpenPictureDialog1.FileName;
777800
fOnTransferFileDoneReason := frDC4Tex;
778801
ctd.TransferFile(fTransferFilename, 'dc4.png', @OnTransferFileDone);
802+
// Gibt es eine "Arrow" Textur, wird diese automatisch nachgeladen
803+
s := ExtractFileNameWithoutExt(fTransferFilename) + '_arrow' + ExtractFileExt(fTransferFilename);
804+
If FileExistsUTF8(s) Then Begin
805+
ctd.TransferFile(s, 'dc4_arrow.png', Nil);
806+
End;
779807
End;
780808
End;
781809

textures/waydirections.png

-2 Bytes
Loading

units/uctd_common.pas

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,18 @@
315315
*)
316316
ctd_Tipp_Layer = 0.9; // Die ToolTipps und teile des Sidemenüs
317317

318+
Const
319+
Directions: Array[0..7] Of Tpoint = (
320+
(x: - 1; y: 0),
321+
(x: + 1; y: 0),
322+
(x: 0; y: - 1),
323+
(x: 0; y: + 1),
324+
(x: - 1; y: - 1),
325+
(x: + 1; y: - 1),
326+
(x: - 1; y: + 1),
327+
(x: + 1; y: + 1)
328+
);
329+
318330
Type
319331

320332
TLogLevel = (llTrace, lldebug, llInfo, llWarning, llError, llCritical, llFatal);

0 commit comments

Comments
 (0)