cellmach.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. Uses Graph, CRT;
  2. TYPE
  3. EBis = (NOTHING,BLINK,CREATECHILD,WALK,FIGHT,DYING);
  4. EStages = (CHILD,YOUTH,NORMAL,OLDMAN,DEAD);
  5. ESexes = (MAN,WOMAN);
  6. CONST
  7. DelayNum = 100;
  8. DelaySize = 65535;
  9. XCount = 300;
  10. YCount = 200;
  11. XSize = 600 div XCount;
  12. YSize = 400 div YCount;
  13. FieldSize = XCount * YCount div 8;
  14. TickPerYear = 4;
  15. CurID: longint = 0;
  16. AveLifeTime : array [0..1] of word = (65, 70);
  17. LifeTimeAdd : array [0..9] of word = (5,5,5,10,10,10,10,20,30,50);
  18. DyeAccur = 1000;
  19. DyeChance : array [0..3] of word = (10,5,6,15);
  20. YouthAge = 15;
  21. NormalAge = 21;
  22. OldManAge = 50;
  23. {Sex,Stage,Random}
  24. Moods : array [0..1,0..3,0..9] of EBis =
  25. ((( {MaN}
  26. NOTHING,NOTHING,NOTHING,NOTHING, {Child}
  27. BLINK,BLINK,BLINK,
  28. WALK,WALK,WALK
  29. ),
  30. (
  31. NOTHING,NOTHING,NOTHING, {Youth}
  32. BLINK,BLINK,
  33. WALK,WALK,WALK,WALK,WALK
  34. ),
  35. (
  36. NOTHING,NOTHING,NOTHING,NOTHING,NOTHING,NOTHING, {Normal}
  37. BLINK,
  38. WALK,WALK,WALK
  39. ),
  40. (
  41. NOTHING,NOTHING,NOTHING,NOTHING,NOTHING,NOTHING,NOTHING, {OldMan}
  42. BLINK,
  43. WALK,WALK
  44. )),
  45. (( {Woman}
  46. NOTHING,NOTHING,NOTHING,NOTHING, {Child}
  47. BLINK,BLINK,BLINK,BLINK,
  48. WALK,WALK
  49. ),
  50. (
  51. NOTHING,NOTHING,NOTHING, {Youth}
  52. BLINK,BLINK,
  53. WALK,WALK,WALK,WALK,WALK
  54. ),
  55. (
  56. NOTHING,NOTHING,NOTHING,NOTHING,NOTHING,NOTHING, {Normal}
  57. BLINK,
  58. WALK,WALK,WALK
  59. ),
  60. (
  61. NOTHING,NOTHING,NOTHING,NOTHING,NOTHING,NOTHING,NOTHING, {OldMan}
  62. BLINK,
  63. WALK,WALK
  64. )));
  65. TYPE
  66. TPos = record
  67. x,y : word;
  68. end;
  69. PCell = ^TCell;
  70. TCell = record
  71. ID : longint;
  72. ChildCount : word;
  73. LifeTime : word;
  74. Pos : TPos;
  75. Age : word;
  76. Mood : EBis;
  77. MoodTickLeft : word;
  78. Stage : EStages;
  79. Sex : ESexes;
  80. BlinkStage : boolean;
  81. end;
  82. PList = ^TList;
  83. TList = record
  84. C : PCell;
  85. Next, Prev : PList;
  86. end;
  87. VAR
  88. Field : array [1..FieldSize] of byte;
  89. CellList : PList;
  90. Tick : longint;
  91. Function CreateCell(x,y:word;aSex:ESexes):PCell;
  92. var
  93. ret:PCell;
  94. begin
  95. randomize;
  96. New(Ret);
  97. with ret^ do begin
  98. ID := CurId;
  99. inc(CurId);
  100. Sex := aSex;
  101. Pos.X := x; Pos.Y := y;
  102. Age := 0;
  103. LifeTime := AveLifeTime[Ord(Sex)] +
  104. {random SIGN}(random(1)*2-1) * random(LifeTimeAdd[random(10)]);
  105. ChildCount := 0;
  106. Mood := NOTHING;
  107. MoodTickLeft := 1;
  108. Stage := CHILD;
  109. BlinkStage := false;
  110. end;
  111. CreateCell := ret;
  112. end;{CreateCell}
  113. {------------------------------------------------}
  114. procedure SetPos(x,y : word);
  115. var
  116. Cbyte : longint;
  117. Cbit : byte;
  118. Mask : byte;
  119. begin
  120. CByte := (y*YCount + X) div 8;
  121. CBit := (y*YCount + X) mod 8;
  122. Mask := 1 shl (7-CBit);
  123. Field[Cbyte] := Field[Cbyte] or Mask;
  124. end;{SetPos}
  125. {--------------------------------------------------}
  126. Procedure UnSetPos(x,y : word);
  127. var
  128. Cbyte : longint;
  129. Cbit : byte;
  130. Mask : byte;
  131. begin
  132. CByte := (y*YCount + X) div 8;
  133. CBit := (y*YCount + X) mod 8;
  134. Mask := 255 xor (1 shl (7-CBit));
  135. Field[Cbyte] := Field[Cbyte] and Mask;
  136. end;{UnSetPos}
  137. {------------------------------------------------------}
  138. Function GetPos(x,y:word) : boolean;
  139. var
  140. Cbyte : longint;
  141. Cbit : byte;
  142. Mask : byte;
  143. begin
  144. CByte := (y*YCount + X) div 8;
  145. CBit := (y*YCount + X) mod 8;
  146. Mask := Field[Cbyte] shr (7-Cbit);
  147. if Mask and 1 = 1 then GetPos := true
  148. else GetPos := false;
  149. end;{GetPos}
  150. {------------------------------------------------------}
  151. Procedure NewCell(x,y:word;aSex : ESexes);
  152. var
  153. NNN : PLIST;
  154. NC : PCell;
  155. begin
  156. NC := CreateCell(x,y,aSex);
  157. SetPos(X,Y);
  158. NNN := New(Plist);
  159. NNN^.C := NC;
  160. NNN^.Prev := CellList;
  161. NNN^.Next := nil;
  162. if CellList <> nil then CellList^.Next := NNN;
  163. CellList := NNN;
  164. end;{NewCell}
  165. {------------------------------------------------------}
  166. Procedure DelayBlock(Num,Count : word);
  167. var i:word;
  168. begin
  169. for i:=0 to Num Do Delay(Count);
  170. end;{DelayBlock}
  171. {----------------------------------------------}
  172. Procedure Step;
  173. var
  174. C : PCell;
  175. CL,p : PList;
  176. begin
  177. Cl := CellList;
  178. inc(Tick);
  179. while CL <> nil do begin
  180. C := CL^.C;
  181. with C^ do Begin
  182. Dec(MoodTickLeft);
  183. iF Stage <> DEAD then
  184. begin
  185. if Tick mod TickPerYear = 0 then begin
  186. Inc(Age);
  187. if Age > YouthAge then Stage := YOUTH;
  188. if Age > NormalAge then Stage := NORMAL;
  189. if Age > OldManAge then Stage := OLDMAN;
  190. Mood := NOTHING;
  191. MoodTickLeft := 1;
  192. end;
  193. end else if MoodTickLeft = 0 then begin
  194. UnSetPos(Pos.X,Pos.Y);
  195. P := CL^.Next;
  196. CL^.Next^.Prev := CL^.Prev;
  197. CL^.Prev^.Next := CL^.Next;
  198. Dispose(C);
  199. Dispose(CL);
  200. Cl := P;
  201. end;
  202. end;
  203. Cl := CL^.Prev;
  204. end;
  205. end;{Step}
  206. {-----------------------------------------------}
  207. BEGIN
  208. END.