summaryrefslogtreecommitdiffstats
path: root/TemplePushing.c4s/Locals.c4d/Cannon.c4d/Script.c
blob: c77c034d85051ed528dbf7fd0955cb29c5024c79 (plain)
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
/*-- Haubitze --*/

#strict
local WpID;

/* Initialisierung */

protected func Initialize()
{
  WpID = [FLNT,EFLN,SFLN,TFLN];
  AddEffect("CreateCon",this(),100,150,this());
  SetAction("Ready");
  SetPhase(10);
}

/* Steuerung */

protected func ControlConf(int conf)
{
  if(AimStdConf(conf))
    Sound("CatapultSet");
}

public func ControlUp(object clonk)     // Zielen: hoch (klassisch)
{
  [$TxtAimup$|Image=CAN1:2]
  AimUp(clonk, 4, "ControlConf");
}

public func ControlDig(object clonk)    // Zielen: runter (klassisch)
{
  [$TxtAimdown$|Method=Classic|Image=CAN1:0]
  AimDown(clonk, 4, "ControlConf");
}

public func ControlDown()
{
  [$TxtAimdown$|Method=JumpAndRun|Image=CAN1:0] // Beschreibung fuer JnR
}

public func ControlUpdate(object clonk, int comdir) // Zielen: JnR
{
  AimUpdate(clonk, comdir, 4, "ControlConf");
}

public func ControlDownSingle() // Sicht zurücksetzen
{
  [$TxtResetview$|Method=None]
}

public func ControlThrow(pClonk)    // Feuern / Inhalt
{
  [$TxtFire$|Image=CAN1:1]
  // Der Clonk will doch bestimmt nur etwas nachladen: nicht vorzeitig abfeuern
  var pThing;
  if (pThing = pClonk->Contents())
    if (AllowLoad(GetID(pThing)))
      return(0);
  // Abfeuern wenn möglich, sonst Objekt herausnehmen
  return(Fire());
}

public func ControlCommand(string szCommand,object pTarget,int iX,int iY)
{
  // Feuern
  if(szCommand eq "MoveTo")
    if(Distance(GetX(),GetY(),iX,iY)>50)
    {
      HaltPushers();
      return(FireAt(iX,iY));
    }
}

/* Prozesse */

private func HaltPushers()
{
  var pClonk;
  // Alle Clonks die die Haubitze anfassen, sollen stoppen
  while(pClonk=FindObject(0,0,0,0,0,0,"Push",this(),0,pClonk))
    SetComDir(COMD_Stop(),pClonk);
}

public func Fire(bool fAuto)
{
  var pProjectile=FindOtherContents(GUNP);
  // Ich brauch kein Schießpulver!
  // Projektil fehlt
  if (!pProjectile) 
  {
    Sound("Click");
    return(0);
  }

  // Austritt berechnen
  var iX = (GetPhase()+3)*(GetDir()*2-1);
  var iY = GetPhase()-14;
  var iAngle = BoundBy(GetPhase()*5-5,0,90);
  var iXDir = Sin(iAngle,32*(GetDir()*2-1));
  var iYDir = Cos(iAngle,-18);

  // Projektil abfeuern
  Exit(pProjectile,iX,iY,Random(360),iXDir,iYDir,+30);

  // Sicht verfolgen (wenn kein automatischer Schuss)
  if(!fAuto)
    if(GetPlrViewMode(GetController())!=2)
      SetPlrView(GetController(),pProjectile);
  // Sound
  Sound("Blast2");
  // Rauch
  for (var i = 0; i < 6; ++i) 
    Smoke(iX+RandomX(-5,+5),iY+RandomX(-5,+5),RandomX(5,12));
  // Erfolgreich geschossen
  return(1);
}

/* Zielfunktionen */

public func FireAt(int iX,int iY,int fAuto)
{
  var iAngle;
  // Zielwinkel
  iAngle = Angle(GetX(),GetY(),iX,iY);
  // Bei größerer Distanz höher zielen
  if(Inside(iX-GetX(),+1,+300))
     iAngle -= Abs(iX-GetX())/12;
  if(Inside(iX-GetX(),-300,-1))
     iAngle += Abs(iX-GetX())/12;
  // Zielen
  AimToAngle(iAngle);
  // Feuern
  return(Fire(fAuto));
}

public func AimToAngle(int iAngle)
{
  // Winkel anpassen
  while(iAngle > 180) iAngle-=360;
  // Richtung
  if(iAngle > 0) SetDir(DIR_Right());
  if(iAngle < 0) SetDir(DIR_Left());
  // Zielrichtung
  SetPhase(BoundBy( 19*Abs(iAngle)/90, 0,18));
}
    
/* Laden */

protected func Collection() { Sound("Connect"); }

protected func RejectCollect(id idObj, object pObj)
{
  return(!AllowLoad(idObj));
}

private func AllowLoad(id idObj)
{
  // Noch jede Menge Platz
  if (ContentsCount() < 9) return(1);
  // Niemals mehr als 10 Objekte laden: Wird gebraucht, wenn aus ControlThrow aufgerufen!
  if (ContentsCount() >= 10) return(0);
  // Nicht mehr als 9 Projektile laden, wenn noch Platz für Pulver gebraucht wird
  // Laden o.k.
  return(1);
}

/* Forschung */

public func GetResearchBase() { return(CATA); }

func FxCreateConTimer()
{
 if (ContentsCount() < 10)
 CreateContents(WpID[Random(5)]);
 return(1);
 }