Simulation von Bürgern
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

citizen.pde 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import processing.net.*;
  2. int i_citizenAmount = 100;
  3. /*
  4. todo
  5. !!!FIX ONE SIDED COLOR TRANSMISSION!!!
  6. steady control over selectedCitizen. right click on house to enter it.
  7. reset view and selectCitizen(0) after long time no input
  8. fix zoom, add zoom level
  9. saarbrücken map
  10. add ui panel for selected citizen in non-debug
  11. enter house
  12. dominanz
  13. wächst mit anzahl der am tag durchgeführten kommunikationen
  14. sinkt mit zeit ohne kommunikation
  15. (durchgeführte kommunikationen nach tag resetten)
  16. beeinflusst wie stark eigene farbe übertragen oder übernommen wird
  17. proportional zur farbintensität? alle grau = weltfrieden though
  18. goTo fast immer haus-spezifisch machen. liste der häuser von citizen mit ähnlicher farbe, werden öfter besucht
  19. ab und zu nach hause gehen
  20. goTo random point on map = spaziergang. passiert vorwiegend sonntags? wochentage?
  21. andere lösung finden ausser teleportieren bei unmöglicher pfadfindung
  22. idee:
  23. processing client - spieler verfolgt einen einzigen citizen
  24. ignore-liste
  25. ziel: möglichst viele zur eigenen farbe bekehren
  26. alte ideen:
  27. //citizen kann "lookat" mit 180° winkel mit bullseye förmigen gradient welches die chance etwas zu bemerken darstellt
  28. //setFocus(entity) durch geräusche auch von objekten ausserhalb des sichtfeldes aufrufbar
  29. //citizen kann "focus", guckt mit den augen in die richtung. 2. augen-vektor! kopf wird mitgedreht je nach "openness"
  30. //citizen kann "take", nimmt gegenstand in die hand. arraylist "holds" - gegenstände in der hand
  31. */
  32. //settings
  33. boolean b_rundgang = true;
  34. boolean b_loadSun = false; //load sun from web-api instead of local json file (local file is adressed to january 4th 2019. might implement a check that downloads today's information only once...
  35. int i_sMapReso = 8; //the higher the smaller the reso, 2 is best quality but takes some time to download
  36. int i_timeTickMS = 200; //milliseconds how long until next minute ticks on clock
  37. float f_walkSpeedMin = 2;
  38. float f_walkSpeedMax = 3;
  39. float f_nodeResolution = 0.1; //defines density of path-finding nodes, multiplied with resolution
  40. int i_pathAlgorithm = 4;
  41. boolean b_cameraLock = false;
  42. boolean b_autoPlay = false;
  43. boolean b_realTime = false;
  44. boolean b_controlEyeWithMouse;
  45. boolean b_housesTexts;
  46. boolean b_debug = false;
  47. boolean b_drawNodes = false;
  48. int i_windowW, i_windowH, i_viewportW, i_viewportH;
  49. PImage img_helptext;
  50. Server server;
  51. Client client;
  52. void setup() {
  53. fullScreen();
  54. //size(700, 600);
  55. i_windowW = width;
  56. i_windowH = height;
  57. server = new Server(this, 5210);
  58. img_map = loadImage(dataPath("map/map2.png"));
  59. img_houses = loadImage(dataPath("map/houses_without_borders2.png"));
  60. pg_map = createGraphics(img_houses.width, img_houses.height);
  61. surface.setResizable(true);
  62. registerMethod("pre", this);
  63. i_mapW = pg_map.width;
  64. i_mapH = pg_map.height;
  65. img_helptext = loadImage("helptext.png");
  66. initTime();
  67. initHouses();
  68. initPathFinding();
  69. initWeather();
  70. initCitizen();
  71. initInteractables();
  72. initUI();
  73. zoomOut();
  74. }
  75. String s_fromClient;
  76. int i_mapLevelTransferC;
  77. int i_makeThemGoC;
  78. int i_idleFrames;
  79. iPVector iv2_mouseBufferIdle = new iPVector(0, 0);
  80. void idleRecord(){
  81. if(mouseX == iv2_mouseBufferIdle.x && mouseY == iv2_mouseBufferIdle.y){
  82. i_idleFrames++;
  83. if(i_idleFrames >= 5000){
  84. buttons[1].click();
  85. }
  86. } else {
  87. i_idleFrames = 0;
  88. }
  89. iv2_mouseBufferIdle.x = mouseX;
  90. iv2_mouseBufferIdle.y = mouseY;
  91. }
  92. void draw() {
  93. background(127);
  94. for (int i = 0; i < i_citizenAmount*3; i++){ //so bad
  95. clientCommunication();
  96. }
  97. time();
  98. if (b_makeThemGo) {
  99. //citizen[i_makeThemGoC].goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)));
  100. citizen[i_makeThemGoC].goToRandom();
  101. i_makeThemGoC ++;
  102. if (i_makeThemGoC >= citizen.length) {
  103. b_makeThemGo = false;
  104. i_makeThemGoC = 0;
  105. }
  106. }
  107. pg_map.beginDraw();
  108. pg_map.background(127);
  109. //pg_map.tint(50,50,200,255);
  110. int nightC = 0;
  111. if (i_flexibleTime > 300 && i_flexibleTime < 550) {
  112. nightC = (int)map(i_flexibleTime, 300, 550, 50, 255);
  113. }
  114. if (i_flexibleTime <= 300 || i_flexibleTime >= 1300) {
  115. nightC = 50;
  116. }
  117. if (i_flexibleTime >= 550 && i_flexibleTime <= 1000) {
  118. nightC = 255;
  119. }
  120. if (i_flexibleTime > 1000 && i_flexibleTime < 1300) {
  121. nightC = (int)map(i_flexibleTime, 1000, 1300, 255, 50);
  122. }
  123. pg_map.tint(nightC, nightC, (int)map(nightC, 50, 255, 150, 255), 255);
  124. i_visionTransparency = (int)map(nightC, 50, 255, 0, 150);
  125. //150-450 //morgen
  126. //1000-1300 //abend
  127. if (b_debug) pg_map.image(img_houses, 0, 0, img_houses.width, img_houses.height);
  128. else pg_map.image(img_map, 0, 0, img_houses.width, img_houses.height);
  129. pg_map.fill(0);
  130. pg_map.textSize(7);
  131. pg_map.textAlign(CENTER);
  132. if (b_debug && b_housesTexts) {
  133. for (House house : houses) {
  134. house.display();
  135. }
  136. }
  137. if (b_drawNodes) drawNodes();
  138. for (int i = 0; i < interactables.length; i++) {
  139. interactables[i].update();
  140. }
  141. for (int i = 0; i < citizen.length; i++) {
  142. if (citizen[i].b_linked) {
  143. citizen[i].update();
  144. if (i != i_selectedCitizen)
  145. citizen[i].display();
  146. if (b_debug)
  147. citizen[i].debug();
  148. }
  149. }
  150. if (b_controlEyeWithMouse) {
  151. citizen[i_selectedCitizen].turnTo(citizen[i_selectedCitizen].f_xPos-(float)constrain(i_mapViewToMap(mouseX, i_mapOffsetX), 0, pg_map.width), citizen[i_selectedCitizen].f_yPos-(float)constrain(i_mapViewToMap(mouseY, i_mapOffsetY), 0, pg_map.height), 0) ;
  152. }
  153. if (i_selectedCitizen != 0) citizen[i_selectedCitizen].display();
  154. pg_map.endDraw();
  155. image(pg_map, i_mapOffsetX, i_mapOffsetY, i_mapW, i_mapH);
  156. drawUI();
  157. idleRecord();
  158. }