UMoveToRoom.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. unit UMoveToRoom;
  2. interface
  3. procedure MoveToRoom(LastX,LastZ:Integer);
  4. procedure ChangePlayerSpeed(LastX,LastZ:Integer);
  5. procedure WarpWalls(LastX,LastZ:Integer);
  6. implementation
  7. uses Unit1,UNetwork,SysUtils,Types,Windows,Math,UCadencer;
  8. procedure WarpWalls(LastX,LastZ:Integer);
  9. var Pos:TPoint;
  10. begin
  11. if LastX<>PosX-1 then begin
  12. if nx in Map[PosX,PosZ].Walls
  13. then begin
  14. Map[PosX,PosZ].Walls:=Map[PosX,PosZ].Walls-[nx];
  15. Map[PosX-1,PosZ].Walls:=Map[PosX-1,PosZ].Walls-[px];
  16. end else if nx in Map[PosX,PosZ].UpWalls
  17. then begin
  18. Map[PosX,PosZ].UpWalls:=Map[PosX,PosZ].UpWalls-[nx];
  19. Map[PosX-1,PosZ].UpWalls:=Map[PosX-1,PosZ].UpWalls-[px];
  20. Map[PosX,PosZ].DownWalls:=Map[PosX,PosZ].DownWalls+[nx];
  21. Map[PosX-1,PosZ].DownWalls:=Map[PosX-1,PosZ].DownWalls+[px];
  22. end else if nx in Map[PosX,PosZ].DownWalls
  23. then begin
  24. Map[PosX,PosZ].DownWalls:=Map[PosX,PosZ].DownWalls-[nx];
  25. Map[PosX-1,PosZ].DownWalls:=Map[PosX-1,PosZ].DownWalls-[px];
  26. Map[PosX,PosZ].UpWalls:=Map[PosX,PosZ].UpWalls+[nx];
  27. Map[PosX-1,PosZ].UpWalls:=Map[PosX-1,PosZ].UpWalls+[px];
  28. end else begin
  29. Map[PosX,PosZ].Walls:=Map[PosX,PosZ].Walls+[nx];
  30. Map[PosX-1,PosZ].Walls:=Map[PosX-1,PosZ].Walls+[px];
  31. end;
  32. end;
  33. if LastX<>PosX+1 then begin
  34. if px in Map[PosX,PosZ].Walls
  35. then begin
  36. Map[PosX,PosZ].Walls:=Map[PosX,PosZ].Walls-[px];
  37. Map[PosX+1,PosZ].Walls:=Map[PosX+1,PosZ].Walls-[nx];
  38. end else if px in Map[PosX,PosZ].UpWalls
  39. then begin
  40. Map[PosX,PosZ].UpWalls:=Map[PosX,PosZ].UpWalls-[px];
  41. Map[PosX+1,PosZ].UpWalls:=Map[PosX+1,PosZ].UpWalls-[nx];
  42. Map[PosX,PosZ].DownWalls:=Map[PosX,PosZ].DownWalls+[px];
  43. Map[PosX+1,PosZ].DownWalls:=Map[PosX+1,PosZ].DownWalls+[nx];
  44. end else if px in Map[PosX,PosZ].DownWalls
  45. then begin
  46. Map[PosX,PosZ].DownWalls:=Map[PosX,PosZ].DownWalls-[px];
  47. Map[PosX+1,PosZ].DownWalls:=Map[PosX+1,PosZ].DownWalls-[nx];
  48. Map[PosX,PosZ].UpWalls:=Map[PosX,PosZ].UpWalls+[px];
  49. Map[PosX+1,PosZ].UpWalls:=Map[PosX+1,PosZ].UpWalls+[nx];
  50. end else begin
  51. Map[PosX,PosZ].Walls:=Map[PosX,PosZ].Walls+[px];
  52. Map[PosX+1,PosZ].Walls:=Map[PosX+1,PosZ].Walls+[nx];
  53. end;
  54. end;
  55. if LastZ<>PosZ-1 then begin
  56. if nz in Map[PosX,PosZ].Walls
  57. then begin
  58. Map[PosX,PosZ].Walls:=Map[PosX,PosZ].Walls-[nz];
  59. Map[PosX,PosZ-1].Walls:=Map[PosX,PosZ-1].Walls-[pz];
  60. end else if nz in Map[PosX,PosZ].UpWalls
  61. then begin
  62. Map[PosX,PosZ].UpWalls:=Map[PosX,PosZ].UpWalls-[nz];
  63. Map[PosX,PosZ-1].UpWalls:=Map[PosX,PosZ-1].UpWalls-[pz];
  64. Map[PosX,PosZ].DownWalls:=Map[PosX,PosZ].DownWalls+[nz];
  65. Map[PosX,PosZ-1].DownWalls:=Map[PosX,PosZ-1].DownWalls+[pz];
  66. end else if nz in Map[PosX,PosZ].DownWalls
  67. then begin
  68. Map[PosX,PosZ].DownWalls:=Map[PosX,PosZ].DownWalls-[nz];
  69. Map[PosX,PosZ-1].DownWalls:=Map[PosX,PosZ-1].DownWalls-[pz];
  70. Map[PosX,PosZ].UpWalls:=Map[PosX,PosZ].UpWalls+[nz];
  71. Map[PosX,PosZ-1].UpWalls:=Map[PosX,PosZ-1].UpWalls+[pz];
  72. end else begin
  73. Map[PosX,PosZ].Walls:=Map[PosX,PosZ].Walls+[nz];
  74. Map[PosX,PosZ-1].Walls:=Map[PosX,PosZ-1].Walls+[pz];
  75. end;
  76. end;
  77. if LastZ<>PosZ+1 then begin
  78. if pz in Map[PosX,PosZ].Walls
  79. then begin
  80. Map[PosX,PosZ].Walls:=Map[PosX,PosZ].Walls-[pz];
  81. Map[PosX,PosZ+1].Walls:=Map[PosX,PosZ+1].Walls-[nz];
  82. end else if pz in Map[PosX,PosZ].UpWalls
  83. then begin
  84. Map[PosX,PosZ].UpWalls:=Map[PosX,PosZ].UpWalls-[pz];
  85. Map[PosX,PosZ+1].UpWalls:=Map[PosX,PosZ-1].UpWalls-[nz];
  86. Map[PosX,PosZ].DownWalls:=Map[PosX,PosZ].DownWalls+[pz];
  87. Map[PosX,PosZ+1].DownWalls:=Map[PosX,PosZ+1].DownWalls+[nz];
  88. end else if pz in Map[PosX,PosZ].DownWalls
  89. then begin
  90. Map[PosX,PosZ].DownWalls:=Map[PosX,PosZ].DownWalls-[pz];
  91. Map[PosX,PosZ+1].DownWalls:=Map[PosX,PosZ+1].DownWalls-[nz];
  92. Map[PosX,PosZ].UpWalls:=Map[PosX,PosZ].UpWalls+[pz];
  93. Map[PosX,PosZ+1].UpWalls:=Map[PosX,PosZ+1].UpWalls+[nz];
  94. end else begin
  95. Map[PosX,PosZ].Walls:=Map[PosX,PosZ].Walls+[pz];
  96. Map[PosX,PosZ+1].Walls:=Map[PosX,PosZ+1].Walls+[nz];
  97. end;
  98. end;
  99. Pos.X:=PosX;
  100. Pos.Y:=PosZ;
  101. Form3.SendRaum(Pos);
  102. Pos.X:=PosX+1;
  103. Form3.SendRaum(Pos);
  104. Pos.X:=PosX-1;
  105. Form3.SendRaum(Pos);
  106. Pos.X:=PosX;
  107. Pos.Y:=PosZ+1;
  108. Form3.SendRaum(Pos);
  109. Pos.Y:=PosZ-1;
  110. Form3.SendRaum(Pos);
  111. end;
  112. procedure NormalSpeedLoss(LastX,LastZ:Integer);
  113. begin
  114. if not Won then begin
  115. if (not GetRT(PosX,PosZ).PushPlayer[Up])
  116. and (not GetRT(PosX,PosZ).PushPlayer[Down])
  117. and (not GetRT(LastX,LastZ).PushPlayer[Up])
  118. and (not GetRT(LastX,LastZ).PushPlayer[Down]) then
  119. Form1.ChangeSpeedBy(-0.08);
  120. if ((Camera.Position.X<-8.5) and
  121. (((nx in Map[PosX,PosZ].UpWalls) and players[MyId].CeilWalk)
  122. or ((nx in Map[PosX,PosZ].DownWalls) and not players[MyId].CeilWalk)))
  123. then Form1.ChangeSpeedBy(-1);
  124. if ((Camera.Position.X>8.5) and
  125. (((px in Map[PosX,PosZ].UpWalls) and players[MyId].CeilWalk)
  126. or ((px in Map[PosX,PosZ].DownWalls) and not players[MyId].CeilWalk)))
  127. then Form1.ChangeSpeedBy(-1);
  128. if ((Camera.Position.Z<-8.5) and
  129. (((nz in Map[PosX,PosZ].UpWalls) and players[MyId].CeilWalk)
  130. or ((nz in Map[PosX,PosZ].DownWalls) and not players[MyId].CeilWalk)))
  131. then Form1.ChangeSpeedBy(-1);
  132. if ((Camera.Position.Z>8.5) and
  133. (((pz in Map[PosX,PosZ].UpWalls) and players[MyId].CeilWalk)
  134. or ((pz in Map[PosX,PosZ].DownWalls) and not players[MyId].CeilWalk)))
  135. then Form1.ChangeSpeedBy(-1);
  136. end;
  137. end;
  138. procedure ChangePlayerSpeed(LastX,LastZ:Integer);
  139. label LNormalLoss;
  140. begin
  141. if sqrt(sqr(PosX)+sqr(PosZ))>Spawnradius then begin
  142. if GetRT(PosX,PosZ).SPInvisible
  143. and not Form3.ClientSocket.Active
  144. and not Form3.ServerSocket.Active then begin
  145. NormalSpeedLoss(LastX,LastZ);
  146. Exit;
  147. end;
  148. if GetRT(PosX,PosZ).ChangeSpeedRandom[THeight(Players[MyID].Ceilwalk)]
  149. then begin
  150. if not Won then begin
  151. Form1.ChangeSpeedBy(
  152. GetRT(PosX,PosZ).ChangeSpeedAtArrival*(Random-0.4)/0.6);
  153. end else begin
  154. Form1.ChangeSpeedBy(GetRT(PosX,PosZ).ChangeSpeedAtArrival*Random);
  155. end;
  156. Form1.Panel11.Visible:=true;
  157. Form1.Panel11.Caption:='Speed changed randomly to '
  158. +Floattostr(Round(100*Players[MyID].Speed)/100);
  159. Panel11Seconds:=3;
  160. end else if (GetRT(PosX,PosZ).ChangeSpeedAtArrival<0.0001)
  161. and (GetRT(PosX,PosZ).ChangeSpeedAtArrival>-0.0001) then begin
  162. NormalSpeedLoss(LastX,LastZ)
  163. end else if (GetRT(PosX,PosZ).ChangeSpeedAtArrival<0.0001)
  164. and not Won then begin
  165. Form1.ChangeSpeedBy(GetRT(PosX,PosZ).ChangeSpeedAtArrival);
  166. end else if (GetRT(PosX,PosZ).ChangeSpeedAtArrival>0.0001) then begin
  167. Form1.ChangeSpeedBy(GetRT(PosX,PosZ).ChangeSpeedAtArrival);
  168. end;
  169. end;
  170. end;
  171. procedure MoveToRoom(LastX,LastZ:Integer);
  172. var Pos:TPoint; C1:Integer; OrigHeight:THeight;
  173. label LSPInvisible,LOutOfMaze;
  174. begin
  175. OrigHeight:=THeight(Players[MyID].Ceilwalk);
  176. if PosX<-mapsize+RaumRange+1 then
  177. PosX:=mapsize-RaumRange-1;
  178. if PosX>mapsize-RaumRange-1 then
  179. PosX:=-mapsize+RaumRange+1;
  180. if PosZ<-mapsize+RaumRange+1 then
  181. PosZ:=mapsize-RaumRange-1;
  182. if PosZ>mapsize-RaumRange-1 then
  183. PosZ:=-mapsize+RaumRange+1;
  184. if Players[MyID].OutOfMaze then
  185. goto LOutOfMaze;
  186. ChangePlayerSpeed(LastX,LastZ);
  187. if GetRT(PosX,PosZ).SPInvisible
  188. and not Form3.ClientSocket.Active
  189. and not Form3.ServerSocket.Active then
  190. goto LSPInvisible;
  191. if GetRT(PosX,PosZ).PortPlayerToCenter and not Won then begin
  192. Camera.Up.X:=0;
  193. Camera.Up.Z:=0;
  194. Camera.Position.X:=0;
  195. Camera.Position.Z:=0;
  196. end;
  197. if GetRT(PosX,PosZ).TurnPlayer and not Won then begin
  198. Camera.Direction.X:=0;
  199. Camera.Direction.Y:=0;
  200. Camera.Direction.Z:=0;
  201. if not players[MyId].CeilWalk
  202. then Camera.Up.Y:=1
  203. else Camera.Up.Y:=-1;
  204. Camera.Turn(Random(360));
  205. end;
  206. if GetRT(PosX,PosZ).WinAtArrival then
  207. if not Won then begin
  208. Form1.WinGame(MyID);
  209. Form3.SendWin(MyID);
  210. end;
  211. if not Players[MyID].jumping then begin
  212. Players[MyID].jumptime:=
  213. (100*sqrt(sqr(Form4.JumpStrength(Players[MyID].Speed))-
  214. (981*(-2+PlayerDepth[false]))/50)+100
  215. *Form4.JumpStrength(Players[MyID].Speed))/981
  216. end;
  217. if GetRT(PosX,PosZ).YSNP[THeight(Players[MyID].Ceilwalk)] and (not Won)
  218. then begin
  219. Form1.Panel8.Font.Color:=RGB(150,25,25);
  220. Form1.Panel8.Color:=RGB(38,38,38);
  221. Form1.Panel8.Visible:=true;
  222. Form1.Panel8.Caption:='You Shall not Pass!';
  223. Form1.LoseGame;
  224. end;
  225. if GetRT(PosX,PosZ).OPTanzGegner and (not Won)
  226. then begin
  227. Form1.Panel8.Font.Color:=RGB(202,0,215);
  228. Form1.Panel8.Color:=RGB(127,127,127);
  229. Form1.Panel8.Visible:=true;
  230. Form1.Panel8.Caption:='Overpowered: Muh!';
  231. Form1.LoseGame;
  232. end;
  233. if (Map[PosX,PosZ].Inhalt.Sorte=Integer(RainbowTrap)) and (not Won)
  234. then begin //todo 2:ini
  235. Form1.RichEdit1.Color:=RGB(38,38,38);
  236. Form1.RichEdit1.Visible:=true;
  237. Form1.RichEdit1.Lines.Clear;
  238. Form1.RichEdit1.Lines.Add('');
  239. Form1.RichEdit1.Lines.Add('A Hidden Rainbow!');
  240. Form1.RichEdit1.SelStart:=2;
  241. Form1.RichEdit1.SelLength:=1;
  242. Form1.RichEdit1.SelAttributes.Color := RGB(122,0,255);
  243. Form1.RichEdit1.SelStart:=4;
  244. Form1.RichEdit1.SelLength:=2;
  245. Form1.RichEdit1.SelAttributes.Color := RGB(0,0,255);
  246. Form1.RichEdit1.SelStart:=6;
  247. Form1.RichEdit1.SelLength:=2;
  248. Form1.RichEdit1.SelAttributes.Color := RGB(0,184,0);
  249. Form1.RichEdit1.SelStart:=8;
  250. Form1.RichEdit1.SelLength:=2;
  251. Form1.RichEdit1.SelAttributes.Color := RGB(244,244,0);
  252. Form1.RichEdit1.SelStart:=11;
  253. Form1.RichEdit1.SelLength:=1;
  254. Form1.RichEdit1.SelAttributes.Color := RGB(244,177,0);
  255. Form1.RichEdit1.SelStart:=12;
  256. Form1.RichEdit1.SelLength:=2;
  257. Form1.RichEdit1.SelAttributes.Color := RGB(246,74,0);
  258. Form1.RichEdit1.SelStart:=14;
  259. Form1.RichEdit1.SelLength:=1;
  260. Form1.RichEdit1.SelAttributes.Color := RGB(255,0,0);
  261. Form1.RichEdit1.SelStart:=16;
  262. Form1.RichEdit1.SelLength:=2;
  263. Form1.RichEdit1.SelAttributes.Color := RGB(135,1,0);
  264. Form1.RichEdit1.SelStart:=18;
  265. Form1.RichEdit1.SelLength:=1;
  266. Form1.RichEdit1.SelAttributes.Color := RGB(0,0,0);
  267. RE1Seconds:=3;
  268. end;
  269. if GetRT(PosX,PosZ).ChangeWallsAtArrival and (not Won) then
  270. WarpWalls(LastX,LastZ);
  271. if GetRT(PosX,PosZ).WallCageTrap and (not Won) then begin
  272. Map[PosX,PosZ].Walls:=[pz,px,nx,nz];
  273. Map[PosX,PosZ].UpWalls:=[];
  274. Map[PosX,PosZ].DownWalls:=[];
  275. Map[PosX+1,PosZ].Walls:=Map[PosX+1,PosZ].Walls+[nx];
  276. Map[PosX-1,PosZ].Walls:=Map[PosX+1,PosZ].Walls+[px];
  277. Map[PosX,PosZ+1].Walls:=Map[PosX+1,PosZ].Walls+[nz];
  278. Map[PosX,PosZ-1].Walls:=Map[PosX+1,PosZ].Walls+[pz];
  279. Map[PosX+1,PosZ].UpWalls:=Map[PosX+1,PosZ].UpWalls-[nx];
  280. Map[PosX-1,PosZ].UpWalls:=Map[PosX+1,PosZ].UpWalls-[px];
  281. Map[PosX,PosZ+1].UpWalls:=Map[PosX+1,PosZ].UpWalls-[nz];
  282. Map[PosX,PosZ-1].UpWalls:=Map[PosX+1,PosZ].UpWalls-[pz];
  283. Map[PosX+1,PosZ].DownWalls:=Map[PosX+1,PosZ].DownWalls-[nx];
  284. Map[PosX-1,PosZ].DownWalls:=Map[PosX+1,PosZ].DownWalls-[px];
  285. Map[PosX,PosZ+1].DownWalls:=Map[PosX+1,PosZ].DownWalls-[nz];
  286. Map[PosX,PosZ-1].DownWalls:=Map[PosX+1,PosZ].DownWalls-[pz];
  287. Pos.X:=PosX;
  288. Pos.Y:=PosZ;
  289. Form3.SendRaum(Pos);
  290. Pos.X:=PosX+1;
  291. Form3.SendRaum(Pos);
  292. Pos.X:=PosX-1;
  293. Form3.SendRaum(Pos);
  294. Pos.X:=PosX;
  295. Pos.Y:=PosZ+1;
  296. Form3.SendRaum(Pos);
  297. Pos.Y:=PosZ-1;
  298. Form3.SendRaum(Pos);
  299. end;
  300. if GetRT(PosX,PosZ).Contaminate and (not Won)
  301. then begin
  302. Form1.ChangeSpeedBy(-RandomRange(-50,292)/100);
  303. Form1.Panel11.Font.Color:=RGB(0,0,0);
  304. Form1.Panel11.Color:=RGB(249,245,0);
  305. Form1.Panel11.Visible:=true;
  306. Form1.Panel11.Caption:='Contamination! Speed decreased to '
  307. +Floattostr(Round(100*Players[MyID].Speed)/100);
  308. Panel11Seconds:=3;
  309. if Form3.ClientSocket.Active then
  310. Form3.SendContaminate(PosX,PosZ) else
  311. Form1.SpreadContamination(PosX,PosZ);
  312. end;
  313. if GetRT(PosX,PosZ).InkOthers[THeight(Players[MyID].Ceilwalk)]
  314. then Form3.SendInkTrigger(MyID);
  315. if GetRT(PosX,PosZ).PortTo[Up] and (not Won)
  316. and not players[MyId].CeilWalk
  317. then begin
  318. players[MyId].CeilWalk:=true;
  319. Form3.SendCeilWalk;
  320. Camera.Up.SetVector(0,-1,0);
  321. end else
  322. if GetRT(PosX,PosZ).PortTo[Down] and (not Won)
  323. and players[MyId].CeilWalk
  324. then begin
  325. players[MyId].CeilWalk:=false;
  326. Form3.SendCeilWalk;
  327. Camera.Up.SetVector(0,1,0);
  328. end;
  329. if GetRT(PosX,PosZ).Explode[THeight(Players[MyID].Ceilwalk)]
  330. then begin
  331. Form3.SendExplode(PosX,PosZ);
  332. Form1.Explode(PosX,PosZ);
  333. end else if GetRT(PosX,PosZ).ChangeOtherPlayerSpeed then begin
  334. if Form3.ClientSocket.Active then begin
  335. Form3.ClientSocket.Socket.SendText(
  336. 'Lightning;'
  337. +IntToStr(MyID)+';')
  338. end else if Form3.ServerSocket.Active then begin
  339. Form3.SendSpeedChange(MyID);
  340. end;
  341. end;
  342. if GetRT(PosX,PosZ).ExplodeOtherPlayer[THeight(Players[MyID].Ceilwalk)]
  343. then begin
  344. for C1:=0 to High(Players) do
  345. if (Cardinal(C1)<>MyID)
  346. and not Players[C1].Dead then begin
  347. Form3.SendExplode(Round(Players[C1].X/20),Round(Players[C1].Z/20));
  348. Form1.Explode(Round(Players[C1].X/20),Round(Players[C1].Z/20));
  349. end;
  350. if not Won then begin
  351. Form1.Panel13.Font.Color:=RGB(255,255,255);
  352. Form1.Panel13.Color:=RGB(0,0,0);
  353. Form1.Panel13.Visible:=true;
  354. Form1.Panel13.Caption:='BOOM';
  355. Panel13Seconds:=2;
  356. end;
  357. end;
  358. LSPInvisible:
  359. Form1.GLHUDText1.Text:='Speed: '
  360. +Floattostr(Round(100*Players[MyID].Speed)/100)+' m/s';
  361. if Players[MyID].Speed<0.0001 then
  362. Form1.GLHUDText1.Text:='Speed: 0 m/s';
  363. if GetPC(PosX,PosZ).Text<>'' then
  364. Form1.ShowPanel(Map[PosX,PosZ].Inhalt.Sorte);
  365. if GetRT(PosX,PosZ).ChangeAtArrivalTo[OrigHeight]>=0 then begin
  366. Map[PosX,PosZ].Inhalt.Sorte:=GetRT(PosX,PosZ).ChangeAtArrivalTo[OrigHeight];
  367. if GetRT(PosX,PosZ).TurnRandom[Up]
  368. or GetRT(PosX,PosZ).TurnRandom[Down] then begin
  369. if Assigned(Map[PosX,PosZ].Inhalt.Daten) then
  370. Map[PosX,PosZ].Inhalt.Daten:=@Richtungen[
  371. TRichtung(Random(Integer(High(TRichtung))+1))];
  372. Pos.X:=PosX;
  373. Pos.Y:=PosZ;
  374. Form3.SendRaum(Pos);
  375. end else
  376. Form3.SendRaumSorte(PosX,PosZ);
  377. end;
  378. LOutOfMaze:
  379. if Players[MyID].Ceilwalk then
  380. Form1.GLNavigator1.VirtualUp.SetPoint(0,-1,0)
  381. else
  382. Form1.GLNavigator1.VirtualUp.SetPoint(0,1,0);
  383. if Random<0.2 then
  384. Form1.Memo1.Visible:=false;
  385. Form1.Reload;
  386. end;
  387. end.