-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spy.pas
executable file
·1207 lines (1003 loc) · 40.5 KB
/
Spy.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit Spy;
interface
{$R Spy.res}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, stdCtrls,Types;
const
{MENSAJES DE MATERIAL}
MResCooWood1S = WM_USER + 38; {Recive Coordenadas de Materiales de 1 - 6}
MResCooWood2S = WM_USER + 39;
MResCooMetal1S = WM_USER + 40;
MResCooMetal2S = WM_USER + 41;
MResCooRock1S = WM_USER + 42;
MResCooRock2S = WM_USER + 43;
{MENSAJES DE BASE}
MResCooBaseS = WM_USER + 45; // recibe coo base
MResWood = WM_USER + 56; // recibe madera para construir
MResMetal = WM_USER + 60; // recibe METAL para construir
MResRock = WM_USER + 61; // recibe PIEDRA para construir
MResArmaWood = WM_USER + 452; // RECIBE ARMA DE MADERA
MResArmaRock = WM_USER + 574; // RECIBE ARMA DE PIEDRA
MResArmaMetal = WM_USER + 440; // RECIBE ARMA DE METAL
{MENSAJES DE REFUGIO}
MResCooRS = WM_USER + 52; // recibe coo de Refugio
MWoodResR = WM_USER + 57; // madera aceptada o no por refugio
MMetalResR = WM_USER + 62; // madera aceptada o no por refugio
MRockResR = WM_USER + 63; // madera aceptada o no por refugio
MPuedesRef = WM_USER + 310;
MTodosFuera = WM_USER + 498;
{MENSAJES DE SOLDADO ENEMIGO}
MResCooSolEne = WM_USER + 542; // reecibe coordenadas de sol Ene
MDameTusCoo_SolE = WM_USER + 101; // peticion de coordenadas
MResAtacWood_SolE = WM_USER + 361; // recibe ataque con Madera
MResAtacRock_SolE = WM_USER + 383; // recibe ataque con Piedra
MResAtacMetal_SolE = WM_USER + 254; // Recibe ataque con Metal
MEstasRef = WM_USER + 434; // pregunta si esta refugiado
MEstoyRef_SolE = WM_USER + 474;
{MENSAJES DE BOMBER ENEMIGO}
MResCooBomEne = WM_USER + 293; // recibe coo de bomber enemigo
MGiveMeCoo_BomE = WM_USER + 541; // solicita coordendas
MResAtacWood_BomE = WM_USER + 139; // recibe ataque con madera
MResAtacRock_BomE = WM_USER + 217; // recibe ataque con Piedra
MResAtacMetal_BomE = WM_USER + 114; // recibe ataque con Metal
MEstasRef_BomE = WM_USER + 577; // pregunta si esta refugiado
MEstoyRef_BomE = WM_USER + 428;
MEstoyRef_EspE = WM_USER + 546;
{MENSAJES DE ESPIA ENEMIGO}
MResCooEspEne = WM_USER + 524;
MGiveMeCoo_EspE = WM_USER + 277; // solicita coordendas
MResAtacWood_EspE = WM_USER + 99; // recibe ataque con madera
MResAtacRock_EspE = WM_USER + 162; // recibe ataque con Piedra
MResAtacMetal_EspE = WM_USER + 370; // recibe ataque con Metal
MEstasRef_EspE = WM_USER + 342; // pregunta si esta refugiado
{MENSAJES DE BASE ENEMIGA}
MResCooBasEne = WM_USER + 329;
{MENSAJES DE REFUGIO ENEMIGO}
MResCooRefEne = WM_USER + 219;
type
TSpy = class(TGraphicControl)
private
FColor : TColor;
FBitmap : TBitmap;
FResistencia : Integer;
FVelocidad : Integer;
FAbilitado : Boolean;
FTimer : TTimer;
FCarWood : Integer;
FCarMetal,
FCarRock : Integer;
FEstado : Array[1..6] of string;
FOnToqueBase : TNotifyEvent;
FOnToqueRefugio : TNotifyEvent;
procedure Atacando;
procedure Refugiando;
function GetEstado (Indice: Integer): string;
procedure SetEstado (indice: integer; valor: string);
procedure ResCooWood1S (Var Msg : TMessage); message MResCooWood1S;
procedure ResCooWood2S (Var Msg : TMessage); message MResCooWood2S;
procedure ResCooMetal1S (Var Msg : TMessage); message MResCooMetal1S;
procedure ResCooMetal2S (Var Msg : TMessage); message MResCooMetal2S;
procedure ResCooRock1S (Var Msg : TMessage); message MResCooRock1S;
procedure ResCooRock2S (Var Msg : TMessage); message MResCooRock2S;
procedure ResCooBaseS (Var Msg : TMessage); message MResCooBaseS;
procedure ResCoorRS (Var Msg : TMessage); message MResCooRS;
procedure ResWood (Var Msg: TMessage); message MResWood;
procedure ResMetal (Var Msg: TMessage); message MResMetal;
procedure ResRock (Var Msg: TMessage); message MResRock;
procedure WoodResR (Var Msg: TMessage); message MWoodResR;
procedure MetalResR (Var Msg: TMessage); message MMetalResR;
procedure RockResR (Var Msg: TMessage); message MRockResR;
procedure ResArmaWood (Var Msg: TMessage); message MResArmaWood;
procedure ResArmaRock (Var Msg: TMessage); message MResArmaRock;
procedure ResArmaMetal (Var Msg: TMessage); message MResArmaMetal;
procedure ResCooSolEne (Var Msg: TMessage); message MResCooSolEne;
procedure ResCooBomEne (Var Msg: TMessage); message MResCooBomEne;
procedure ResCooEspEne (Var Msg: TMessage); message MResCooEspEne;
procedure ResCooBasEne (Var Msg: TMessage); message MResCooBasEne;
procedure ResCooRefEne (Var Msg: TMessage); message MResCooRefEne;
procedure DameTusCoo_SolE (Var Msg: TMessage); message MDameTusCoo_SolE;
procedure ResAtacWood_SolE (Var Msg: TMessage); message MResAtacWood_SolE;
procedure ResAtacRock_SolE (Var Msg: TMessage); message MResAtacRock_SolE;
procedure ResAtacMetal_SolE (Var Msg: TMessage); message MResAtacMetal_SolE;
procedure GiveMeCoo_BomE (Var Msg: TMessage); message MGiveMeCoo_BomE;
procedure ResAtacWood_BomE (Var Msg: TMessage); message MResAtacWood_BomE;
procedure ResAtacRock_BomE (Var Msg: TMessage); message MResAtacRock_BomE;
procedure ResAtacMetal_BomE (Var Msg: TMessage); message MResAtacMetal_BomE;
procedure GiveMeCoo_EspE (Var Msg: TMessage); message MGiveMeCoo_EspE;
procedure ResAtacWood_EspE (Var Msg: TMessage); message MResAtacWood_EspE;
procedure ResAtacRock_EspE (Var Msg: TMessage); message MResAtacRock_EspE;
procedure ResAtacMetal_EspE (Var Msg: TMessage); message MResAtacMetal_EspE;
procedure PuedesRef (Var Msg: TMessage); message MPuedesRef;
procedure EstasRef (Var Msg: TMessage); message MEstasRef;
procedure EstasRef_BomE (Var Msg: TMessage); message MEstasRef_BomE;
procedure EstasRef_EspE (Var Msg: TMessage); message MEstasRef_EspE;
procedure EstoyRef_SolE (Var Msg: TMessage); message MEstoyRef_SolE;
procedure EstoyRef_BomE (Var Msg: TMessage); message MEstoyRef_BomE;
procedure EstoyRef_EspE (Var Msg: TMessage); message MEstoyRef_EspE;
procedure TodosFuera (Var Msg : TMessage); message MTodosFuera;
protected
procedure DoToqueBase; virtual;
procedure DoToqueRefugio; virtual;
procedure OnTimer(Sender : TOBject); virtual;
procedure SetColor(AColor: TColor);
procedure SetVelocidad(AVelocidad: Integer);
procedure SetAbilitado(AAbilitado: Boolean);
procedure paint; override;
procedure Trayectoria(xDest,yDest: LongInt);
procedure camina;
procedure cicloMat_Base;
procedure cicloBase_Ref;
public
constructor Create(AOwner : TComponent); override;
destructor destroy; override;
property Resistencia : Integer read FResistencia write FResistencia;
property OnToqueBase : TNotifyEvent read FOnToqueBase write FOnToqueBase;
property OnToqueRefugio : TNotifyEvent read FOnToqueRefugio write FOnToqueRefugio;
procedure IrMaterial(Material : String);
procedure Construir(Refugio, Material: String);
procedure Atacar(objetivo,con_que : string);
procedure desplazate(x,y: LongInt; Vel: Integer);
procedure Refugiarse;
property haciendo : string index 1 read GetEstado write SetEstado;
property armado_con : string index 2 read GetEstado write SetEstado;
property resis : string index 3 read GetEstado write SetEstado;
property cargado_con : string index 4 read GetEstado write SetEstado;
property otros : string index 5 read GetEstado write SetEstado;
property objetivo : string index 6 read GetEstado write SetEstado;
property Estado[indice: integer]: string read GetEstado write SetEstado;
published
property Color : TColor read FColor write SetColor;
property Velocidad : Integer read FVelocidad write SetVelocidad;
property Abilitado : Boolean read FAbilitado write SetAbilitado;
end;
procedure Register;
implementation
var
xi, yi, xf, yf : LongInt;
tarea : string;
FXDest, FYDest : LongInt;
Meta : Boolean;
Direccion : string;
xM,yM, xB, yB,
xR,yR : LongInt; // coordenadas de Material, Base y Refugio
Xs,Ys : LongInt; // coordenadas de Soldado Enemigo
Xbe, Ybe : LongInt; // coordenadas de Base Enemiga
Xee, Yee : LongInt; // coordenadas de espia enemigo
XBomE,YBomE : LongInt; // coordenadas de Bomber enemigo
Xre, Yre : LongInt; // coordenadas de Refugio Enemigo
C : Real;
Mensaje : TMessage;
MatTransportado : string;
TopAnt, TopSig : Integer;
WoodGun : integer;
RockGun : integer;
MetalGun : integer;
RefugioSiNo : integer;
VictRef : integer;
{----------------------------------------------------------------- constructor}
constructor TSpy.Create(AOwner : TComponent);
begin
inherited;
FBitmap := TBitmap.Create;
width := 10;
height := 15;
FColor := clWhite;
FResistencia := 30;
FAbilitado := True;
FVelocidad := 10;
FTimer := TTimer.Create(self);
FTimer.Interval := FVelocidad;
FTimer.OnTimer := OnTimer;
end;
{----------------------------------------------------------------- destructor}
destructor TSpy.destroy;
begin
FBitmap.Free;
inherited;
end;
{------------------------------------------------------------------- color}
procedure TSpy.SetColor(AColor: TColor);
begin
If FColor <> AColor then FColor := AColor;
end;
{----------------------------------------------------------------- paint}
procedure TSpy.paint;
var
rectangulo : TRect;
begin
rectangulo := Rect(0,0,Width,Height);
FBitmap.Width := width;
FBitmap.Height := height;
FBitmap.Canvas.Brush.Color := FColor;
FBitmap.Canvas.FillRect(rectangulo);
FBitmap.Canvas.Pen.Color := clBlack;
FBitmap.Canvas.Brush.Color := clBlack;
FBitmap.Canvas.Ellipse(4,1,8,5);
Fbitmap.Canvas.Brush.Color := clBlue;
FBitmap.Canvas.Pen.Color := clBlue;
FBitmap.Canvas.Polygon([Point(6,5),Point(2,5),Point(2,11),Point(4,11),Point(4,15),Point(8,15),
Point(8,11),Point(10,11),Point(10,5)]);
FBitmap.Canvas.Pen.Color := clYellow;
FBitmap.Canvas.MoveTo(4,5);
FBitmap.Canvas.LineTo(7,5);
FBitmap.Canvas.LineTo(8,6);
FBitmap.Canvas.LineTo(7,7);
FBitmap.Canvas.LineTo(4,7);
FBitmap.Canvas.LineTo(4,5);
FBitmap.Canvas.LineTo(4,10);
canvas.Draw(0,0,FBitmap);
end;
{---------------------------------------------- ACTUALIZA EL ESTADO INTERNO}
function TSpy.GetEstado(indice: integer): string;
begin
case indice of
1: result := FEstado[1];
2: result := FEstado[2];
3: result := FEstado[3];
4: result := FEstado[4];
5: result := FEstado[5];
6: result := FEstado[6];
end;
end;
procedure TSpy.SetEstado(indice: integer; valor: string);
begin
if FEstado[indice] <> valor then
FEstado[indice] := valor;
end;
{---------------------------------------------- Calcula constante de TRAYECTORIA}
procedure TSpy.Trayectoria(xDest, yDest: LongInt);
begin
xi := Left;
yi := Top;
xf := xDest;
yf := yDest;
if xi = xf then xi := xi + 3;
C := (yi - yf) / (xi - xf);
end;
{---------------------------------------------------------- habilita}
procedure TSpy.SetAbilitado(AAbilitado: Boolean);
begin
FAbilitado := AAbilitado;
if csDesigning in ComponentState then Exit;
FTimer.Enabled := FAbilitado;
end;
{---------------------------------------------------------- determina velocidad}
procedure TSpy.SetVelocidad(AVelocidad: Integer);
begin
FVelocidad := AVelocidad;
FTimer.Interval := FVelocidad;
end;
{---------------------------------------------------------- desplazamiento}
procedure TSpy.camina;
begin
TopAnt := Top;
if (FXDest > Left) then
begin
Left := Left + 1;
TopSig := Round((C * Left) - (C*xi ) + yi);
if abs(TopSig - TopAnt) > 2 then
begin
if TopSig > TopAnt then Top := TopAnt + 1;
if TopAnt > TopSig then Top := TopAnt - 1;
end
else Top := Round((C * Left) - (C*xi ) + yi);
if (Left = FXDest) and (Top = FYDest) then Meta := true;
end;
if (FXDest < Left) then
begin
Left := Left - 1;
TopSig := Round((C * Left) - (C*xi ) + yi);
if abs(TopSig - TopAnt) > 2 then
begin
if TopSig > TopAnt then Top := TopAnt + 1;
if TopAnt > TopSig then Top := TopAnt - 1;
end
else Top := Round((C * Left) - (C*xi ) + yi);
if (Left = FXDest) and (Top = FYDest) then Meta := true;
end;
if (FXDest = Left) and (Meta = False) then Left := Left + 2;
end;
{------------------------------------------------------- desplazarse a un lugar}
procedure TSpy.desplazate(x,y: LongInt; Vel: Integer);
begin
FXDest := x;
FYDest := y;
Trayectoria(FXdest,FYDest); {calcula constante de ec.}
Velocidad := Vel;
Estado[1] := 'Desplazandose';
end;
{-------------------------------------------------------- CUANDO TOQUE LA BASE}
procedure TSpy.DoToqueBase;
begin
If (MatTransportado = 'Madera1') or (MatTransportado = 'Madera2') then
begin
Mensaje.Msg := WM_USER + 15;
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
end;
If (MatTransportado = 'Metal1') or (MatTransportado = 'Metal2') then
begin
Mensaje.Msg := WM_USER + 16;
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
end;
If (MatTransportado = 'Piedra1') or (MatTransportado = 'Piedra2') then
begin
Mensaje.Msg := WM_USER + 17;
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
end;
end;
{-------------------------------------------------------- CUANDO TOQUE LA BASE}
procedure TSpy.DoToqueRefugio;
begin
If (MatTransportado = 'Madera1') or (MatTransportado = 'Madera2') then
begin
Mensaje.Msg := WM_USER + 49; {--- "Recibe Madera de Spy' ---}
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
end;
If (MatTransportado = 'Metal1') or (MatTransportado = 'Metal2') then
begin
Mensaje.Msg := WM_USER + 50; {--- "Recibe Metal de Spy' ---}
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
end;
If (MatTransportado = 'Piedra1') or (MatTransportado = 'Piedra2') then
begin
Mensaje.Msg := WM_USER + 51; {--- "Recibe Piedra de Spy' ---}
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
end;
end;
////////////////////////////////////////////////////////////////////////////////
///////////////////// IR POR MATERIAL//////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
procedure TSpy.cicloMat_Base;
begin
TopAnt := Top;
if FEstado[4] = 'Cargando_Madera' then Velocidad := 12;
if FEstado[4] = 'Cargando_Piedra' then Velocidad := 14;
if FEstado[4] = 'Cargando_Metal' then Velocidad := 16;
if (direccion = 'Material') and (Meta = false) then begin
FXDest := xM; FYDest := yM;Trayectoria(FXDest,FYDest);Velocidad := 10;
end;
if (direccion = 'Material') and (Meta = true) then begin
direccion := 'Base'; Meta := false;
end;
if (direccion = 'Base') and (Meta = false) then begin
FXDest := xB; FYDest := yB;Trayectoria(FXDest,FYDest);
end;
if (Direccion = 'Base') and (Meta = true) then begin
DoToqueBase;
direccion := 'Material'; Meta := false;
end;
{MOVIMIENTO -------------------------------------------}
if (FXDest > Left) then
begin
Left := Left + 1;
TopSig := Round((C * Left) - (C*xi ) + yi);
if abs(TopSig - TopAnt) > 2 then
begin
if TopSig > TopAnt then Top := TopAnt + 1;
if TopAnt > TopSig then Top := TopAnt - 1;
end
else Top := Round((C * Left) - (C*xi ) + yi);
if (Left = FXDest) and (Top = FYDest) then Meta := true;
end;
if (FXDest < Left) then
begin
Left := Left - 1;
TopSig := Round((C * Left) - (C*xi ) + yi);
if abs(TopSig - TopAnt) > 2 then
begin
if TopSig > TopAnt then Top := TopAnt + 1;
if TopAnt > TopSig then Top := TopAnt - 1;
end
else Top := Round((C * Left) - (C*xi ) + yi);
if (Left = FXDest) and (Top = FYDest) then Meta := true;
end;
if (FXDest = Left) and (Meta = False) then Left := Left + 2;
end;
{-------------------------------------------------------------}
procedure TSpy.IrMaterial(Material : String);
begin
MatTransportado := Material;
If Material = 'Madera1' then begin Mensaje.Msg := WM_USER + 32; FEstado[4] := 'Cargando_Madera'; end;
If Material = 'Madera2' then begin Mensaje.Msg := WM_USER + 33; FEstado[4] := 'Cargando_Madera'; end;
If Material = 'Metal1' then begin Mensaje.Msg := WM_USER + 34; FEstado[4] := 'Cargando_Metal'; end;
If Material = 'Metal2' then begin Mensaje.Msg := WM_USER + 35; FEstado[4] := 'Cargando_Metal'; end;
If Material = 'Piedra1' then begin Mensaje.Msg := WM_USER + 36; FEstado[4] := 'Cargando_Piedra'; end;
If Material = 'Piedra2' then begin Mensaje.Msg := WM_USER + 37; FEstado[4] := 'Cargando_Piedra'; end;
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
Mensaje.Msg := WM_USER + 44;
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
Estado[1] := 'Trayendo material';
velocidad := 10;
direccion := 'Material';
meta := false;
end;
////////////////////////////////////////////////////////////////////////////////
////////////////////// CONSTRUIR ////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
procedure TSpy.cicloBase_Ref;
begin
TopAnt := Top;
{1. SI VA HACIA LA BASE}
if (direccion = 'Base') and (Meta = false) then
begin
FXDest := xB;
FYDest := yB;
Trayectoria(FXDest,FYDest);
FVelocidad := 10;
end;
{2. UNA VEZ LLEGANDO A LA BASE}
if (direccion = 'Base') and (Meta = true) then
begin {-- enviados a base --}
if MatTransportado = 'Madera' then begin
Mensaje.Msg := WM_USER + 55; { 'Dame Madera'}
Festado[4] := 'Cargando_Madera';
Velocidad := 12;
end;
if MatTransportado = 'Metal' then begin
Mensaje.Msg := WM_USER + 58; { 'Dame Metal'}
FEstado[4] := 'Cargando_Metal';
Velocidad := 14;
end;
if MatTransportado = 'Piedra' then begin
Mensaje.Msg := WM_USER + 59; { 'Dame Piedra'}
FEstado[4] := 'Cargando_Piedra';
Velocidad := 16;
end;
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
if (FEstado[1] = 'Construyendo') and (FEstado[4] = 'Cargando_Madera') then
if FCarWood = 0 then begin direccion := 'Base'; meta := false; end
else begin direccion := 'Refugio'; Meta := false; end;
if (FEstado[1] = 'Construyendo') and (FEstado[4] = 'Cargando_Metal') then
if FCarMetal = 0 then begin direccion := 'Base'; meta := false;end
else begin direccion := 'Refugio'; Meta := false; end;
if (FEstado[1] = 'Construyendo') and (FEstado[4] = 'Cargando_Piedra') then
if FCarRock = 0 then begin direccion := 'Base'; meta := false; end
else begin direccion := 'Refugio'; Meta := false; end;
end;
{SI VA HACIA EL REFUGIO}
if (direccion = 'Refugio') and (Meta = false) then begin
FXDest := xR; FYDest := yR;Trayectoria(FXDest,FYDest);Velocidad := 20;
end;
{CUANDO LLEGA AL REFUGIO}
if (Direccion = 'Refugio') and (Meta = true) then begin {--- enviados de SPy a Refugio ---}
if FEstado[4] = 'Cargando_Madera' then Mensaje.Msg := WM_USER + 49; {'Recibe Madera'}
if FEstado[4] = 'Cargando_Metal' then Mensaje.Msg := WM_USER + 50; {'Recibe Metal'}
if FEstado[4] = 'Cargando_Piedra' then Mensaje.Msg := WM_USER + 51; {'Recibe Piedra'}
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
DoToqueRefugio;
direccion := 'Base'; Meta := false;
end;
{MOVIMIENTO -------------------------------------------}
if (FXDest > Left) then
begin
Left := Left + 1;
TopSig := Round((C * Left) - (C*xi ) + yi);
if abs(TopSig - TopAnt) > 2 then
begin
if TopSig > TopAnt then Top := TopAnt + 1;
if TopAnt > TopSig then Top := TopAnt - 1;
end
else Top := Round((C * Left) - (C*xi ) + yi);
if (Left = FXDest) and (Top = FYDest) then Meta := true;
end;
if (FXDest < Left) then
begin
Left := Left - 1;
TopSig := Round((C * Left) - (C*xi ) + yi);
if abs(TopSig - TopAnt) > 2 then
begin
if TopSig > TopAnt then Top := TopAnt + 1;
if TopAnt > TopSig then Top := TopAnt - 1;
end
else Top := Round((C * Left) - (C*xi ) + yi);
if (Left = FXDest) and (Top = FYDest) then Meta := true;
end;
if (FXDest = Left) and (Meta = False) then Left := Left + 2;
end;
{**************************************************** (2)}
procedure TSpy.Construir(Refugio, Material : String);
begin
MatTransportado := Material;
Mensaje.Msg := WM_USER + 48; //-- Pide coordenadas al refugio el Spia
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
Mensaje.Msg := WM_USER + 44;//--- Pide coordenadas a la base
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
If Material = 'Madera' then FEstado[4] := 'Cargando_Madera';
If Material = 'Metal' then FEstado[4] := 'Cargando_Metal';
If Material = 'Piedra' then FEstado[4] := 'Cargando_Piedra';
FEstado[1] := 'Construyendo';
velocidad := 10;
direccion := 'Base';
meta := false;
tarea := 'Construir';
end;
////////////////////////////////////////////////////////////////////////////////
////////////// ATACANDO ///////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
procedure TSpy.Atacando;
begin
TopAnt := Top;
{1. camina a la base por el arma}
if (Direccion = 'Base') and (Meta = false) then Begin
FEstado[5] := 'Voy por arma';
FXDest := xB; FYdest := yB; Trayectoria(FXDest,FYDest);Velocidad := 10;
end;
{2. pide arma a la base}
if (Direccion = 'Base') and (Meta = True) then begin
if FEstado[2] = 'Madera' then Mensaje.Msg := WM_USER + 138; {pide arma de madera}
if FEstado[2] = 'Metal' then Mensaje.Msg := WM_USER + 358; {pide arma de metal}
if FEstado[2] = 'Piedra' then Mensaje.Msg := WM_USER + 380; {pide arma de Piedra}
Application.MainForm.Broadcast(Mensaje);
if (FEstado[2] = 'Madera') and (WoodGun = 0) then exit;
if (FEstado[2] = 'Piedra') and (RockGun = 0) then exit;
if (FEstado[2] = 'Metal') and (MetalGun = 0) then exit;
FEstado[5] := 'Voy por enemigo';
direccion := 'Victima';
Meta := false;
end;
{3. Una vez armado se dirige a la victima}
if (Direccion = 'Victima') and (Meta = false) then begin
if FEstado[2] = 'Madera' then Velocidad := 12;
if FEstado[2] = 'Piedra' then Velocidad := 14;
if FEstado[2] = 'Metal' then Velocidad := 16;
if FEstado[6] = 'Soldado' then Mensaje.Msg := WM_USER + 405; {pide coo a Soldado Ene}
if FEstado[6] = 'Bomber' then Mensaje.Msg := WM_USER + 375 ; {pide coo a Bomber Ene}
if FEstado[6] = 'Espia' then Mensaje.Msg := WM_USER + 543 ; {pide coo a Espia Ene}
if FEstado[6] = 'Base' then Mensaje.Msg := WM_USER + 319; {pide coo a base enemiga}
if FEstado[6] = 'Refugio' then Mensaje.Msg := WM_USER + 566; {pide coo a refugio enemy}
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
if FEstado[6] = 'Soldado' then begin FXDest := xs; FYDest := ys; end;
if FEstado[6] = 'Bomber' then begin FXDest := XBomE; FYDest := YBomE; end;
if FEstado[6] = 'Espia' then begin FXDest := Xee; FYDest := Yee; end;
if FEstado[6] = 'Base' then begin FXDest := Xbe; FYDest := Ybe; end;
if FEstado[6] = 'Refugio' then begin FXDest := Xre; FYDest := Yre; end;
Trayectoria(FXDest,FYDest);
end;
{4. Una vez alacanzado lo ataca}
if (Direccion = 'Victima') and (Meta = True) then begin
if (FEstado[6] = 'Soldado') Then Mensaje.Msg := WM_USER + 456;
if (FEstado[6] = 'Bomber') Then Mensaje.Msg := WM_USER + 107;
if (FEstado[6] = 'Espia') Then Mensaje.Msg := WM_USER + 527;
Application.MainForm.Broadcast(Mensaje);
if VictRef = 1 then begin Left := Left - 40; Meta := false end; {1 = refugiado; 0 = Libre}
if VictRef = 0 then
begin
{----------------- ataques a SOLDADO ENEMIGO}
if (FEstado[6] = 'Soldado') and (FEstado[2] = 'Madera') then Mensaje.Msg := WM_USER + 587;
if (FEstado[6] = 'Soldado') and (FEstado[2] = 'Piedra') then Mensaje.Msg := WM_USER + 126;
if (FEstado[6] = 'Soldado') and (FEstado[2] = 'Metal') then Mensaje.Msg := WM_USER + 427;
{----------------- ataques a BOMBER ENEMIGO}
if (FEstado[6] = 'Bomber') and (FEstado[2] = 'Madera') then Mensaje.Msg := WM_USER + 306;
if (FEstado[6] = 'Bomber') and (FEstado[2] = 'Piedra') then Mensaje.Msg := WM_USER + 419;
if (FEstado[6] = 'Bomber') and (FEstado[2] = 'Metal') then Mensaje.Msg := WM_USER + 299;
{----------------- ataques a ESPIA ENEMIGO}
if (FEstado[6] = 'Espia') and (FEstado[2] = 'Madera') then Mensaje.Msg := WM_USER + 324;
if (FEstado[6] = 'Espia') and (FEstado[2] = 'Piedra') then Mensaje.Msg := WM_USER + 256;
if (FEstado[6] = 'Espia') and (FEstado[2] = 'Metal') then Mensaje.Msg := WM_USER + 196;
{----------------- ataque a BASE ENEMIGA}
if (FEstado[6] = 'Base') and (FEstado[2] = 'Madera') then Mensaje.Msg := WM_USER + 201;
if (FEstado[6] = 'Base') and (FEstado[2] = 'Piedra') then Mensaje.Msg := WM_USER + 320;
if (FEstado[6] = 'Base') and (FEstado[2] = 'Metal') then Mensaje.Msg := WM_USER + 532;
{----------------- ataque a REFUGIO ENEMIGO}
if (FEstado[6] = 'Refugio') and (FEstado[2] = 'Madera') then Mensaje.Msg := WM_USER + 207;
if (FEstado[6] = 'Refugio') and (FEstado[2] = 'Piedra') then Mensaje.Msg := WM_USER + 484;
if (FEstado[6] = 'Refugio') and (FEstado[2] = 'Metal') then Mensaje.Msg := WM_USER + 495;
Application.MainForm.Broadcast(Mensaje);
Direccion := 'Base';
Meta := false;
end;
end;
{MOVIMIENTO -------------------------------------------}
if (FXDest > Left) then
begin
Left := Left + 1;
TopSig := Round((C * Left) - (C*xi ) + yi);
if abs(TopSig - TopAnt) > 2 then
begin
if TopSig > TopAnt then Top := TopAnt + 1;
if TopAnt > TopSig then Top := TopAnt - 1;
end
else Top := Round((C * Left) - (C*xi ) + yi);
if (Left = FXDest) and (Top = FYDest) then Meta := true;
end;
if (FXDest < Left) then
begin
Left := Left - 1;
TopSig := Round((C * Left) - (C*xi ) + yi);
if abs(TopSig - TopAnt) > 2 then
begin
if TopSig > TopAnt then Top := TopAnt + 1;
if TopAnt > TopSig then Top := TopAnt - 1;
end
else Top := Round((C * Left) - (C*xi ) + yi);
if (Left = FXDest) and (Top = FYDest) then Meta := true;
end;
if (FXDest = Left) and (Meta = False) then Left := Left + 2;
{------------------------------------------------------}
end;
procedure TSpy.Atacar(objetivo, con_que: string);
begin
Direccion := 'Base';
Meta := false;
Mensaje.Msg := WM_USER + 44; {pide a base sus coordenadas}
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
FEstado[1] := 'Atacando'; {activa el ataque con procedure "ATACANDO"}
FEstado[2] := con_que;
FEstado[6] := objetivo;
end;
////////////////////////////////////////////////////////////////////////////////
///////////////////// REFUGIARSE ///////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
procedure TSpy.Refugiando;
begin
TopAnt := Top;
velocidad := 10;
if (Direccion = 'Refugio') and (Meta = false) then begin
FXDest := Xr; FYDest := Yr; Trayectoria(FXDest,FYDest); end; {TRAZO TRAYECTORIA}
if (Direccion = 'Refugio') and (Meta = True) then {PREGUNTO SI ME PUEDE REFUGIAR}
begin
Mensaje.Msg := WM_USER + 127;
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
if RefugioSiNo = 1 then FEstado[1] := 'Refugiado'
else begin FEstado[1] := 'Esperando orden'; Top := Top + 40; Left := Left + 40; end;
end;
{MOVIMIENTO -------------------------------------------}
if (FXDest > Left) then
begin
Left := Left + 1;
TopSig := Round((C * Left) - (C*xi ) + yi);
if abs(TopSig - TopAnt) > 2 then
begin
if TopSig > TopAnt then Top := TopAnt + 1;
if TopAnt > TopSig then Top := TopAnt - 1;
end
else Top := Round((C * Left) - (C*xi ) + yi);
if (Left = FXDest) and (Top = FYDest) then Meta := true;
end;
if (FXDest < Left) then
begin
Left := Left - 1;
TopSig := Round((C * Left) - (C*xi ) + yi);
if abs(TopSig - TopAnt) > 2 then
begin
if TopSig > TopAnt then Top := TopAnt + 1;
if TopAnt > TopSig then Top := TopAnt - 1;
end
else Top := Round((C * Left) - (C*xi ) + yi);
if (Left = FXDest) and (Top = FYDest) then Meta := true;
end;
if (FXDest = Left) and (Meta = False) then Left := Left + 2;
end;
{-------------------------------------------------------------------------------}
procedure TSpy.Refugiarse;
begin
Mensaje.Msg := WM_USER + 48; {PIDO COO DE REFUGIO}
Mensaje.WParam := 0;
Mensaje.LParam := 0;
Mensaje.Result := 0;
Application.MainForm.Broadcast(Mensaje);
FEstado[1]:= 'Llendo a refugiarse';
direccion := 'Refugio';
meta := false;
end;
{---------------------------------------------------------- EJECUCION DE TAREAS}
procedure TSpy.OnTimer(Sender: TObject);
begin
if csDesigning in ComponentState then begin
FTimer.Enabled := False;
Exit;
end;
Hint := FEstado[5];
If FEstado[1] = 'Desplazandose' then camina;
If FEstado[1] = 'Atacando' then Atacando;
if FEstado[1] = 'Trayendo material' then CicloMat_Base;
if FEstado[1] = 'Construyendo' then CicloBase_Ref;
if FEstado[1] = 'Llendo a refugiarse' then Refugiando;
end;
{=========================================================================
==================== Procesamiento de Mensajes ===========================}
procedure TSpy.ResCooWood1S(var Msg : TMessage); {--> Coo de madera1}
begin
xm := Msg.WParam;
ym := Msg.LParam;
end;
procedure TSpy.ResCooWood2S(var Msg : TMessage); {--> Coo de madera2}
begin
xm := Msg.WParam;
ym := Msg.LParam;
end;
procedure TSpy.ResCooMetal1S(var Msg : TMessage);{--> Coo de Metal1}
begin
xm := Msg.WParam;
ym := Msg.LParam;
end;
procedure TSpy.ResCooMetal2S(var Msg : TMessage);{--> Coo de Metal2}
begin
xm := Msg.WParam;
ym := Msg.LParam;
end;
procedure TSpy.ResCooRock1S(var Msg : TMessage); {--> Coo de Piedra 1}
begin
xm := Msg.WParam;
ym := Msg.LParam;
end;
procedure TSpy.ResCooRock2S(var Msg : TMessage);{--> Coo de Piedra 2}
begin
xm := Msg.WParam;
ym := Msg.LParam;
end;
procedure TSpy.ResCoorRS(var Msg : TMessage); {--> Coo de REFUGIO}
begin
xR := Msg.WParam;
yR := Msg.LParam;
end;
////////////////////////////////////////////////////////////////////////////////
////////////////// MENSAJES DE BASE DE CONTROL //////////////////////////////
////////////////////////////////////////////////////////////////////////////////
procedure TSpy.ResCooBaseS(var Msg : TMessage);{--> Coo de BASE}
begin
xb := Msg.WParam;
yb := Msg.LParam;
end;
procedure TSpy.ResWood(var Msg: TMessage); {--> Recibe la Madera para construir}
begin
FCarWood := Msg.WParam;
end;
procedure TSpy.ResMetal(var Msg :TMessage); {--> Recibe Metal para construir}
begin
FCarMetal := Msg.WParam;
end;
procedure TSpy.ResRock(var Msg : TMessage);{--> Recibe Piedra para construir}
begin
FCarRock := Msg.WParam;
end;
procedure TSpy.ResArmaWood(var Msg : TMessage); {RECIBE ARMA DE MADERA}
begin
WoodGun := Msg.WParam;
RockGun := 0;
MetalGun:= 0;
end;
procedure TSpy.ResArmaRock(var Msg : TMessage); {RECIBE ARMA DE PIEDRA}
begin
WoodGun := 0;
RockGun := Msg.WParam;
MetalGun:= 0;
end;
procedure TSpy.ResArmaMetal(var Msg : TMessage); {RECIBE ARMA DE METAL}
begin
WoodGun := 0;
RockGun := 0;
MetalGun:= Msg.WParam;
end;
////////////////////////////////////////////////////////////////////////////////
////////////////// MENSAJES DE REFUGIO ///// //////////////////////////////
////////////////////////////////////////////////////////////////////////////////
procedure TSpy.TodosFuera(var Msg : TMessage);
begin
randomize;
if FEstado[1] = 'Refugiado' then
Desplazate(Random(400),Random(400),10);
end;
procedure TSpy.PuedesRef(var Msg : TMessage);
begin
RefugioSiNo := Msg.WParam;
end;
procedure TSpy.WoodResR(var Msg: TMessage);
begin