123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- import java.lang.Double;
- int i_selectedCitizen;
- int i_femaleCount;
- int i_visionTransparency;
- boolean b_makeThemGo;
- //je nachdem wie hoch der derzeitige fokus ist wird es schwerer, ihn abzulenken.
- //intrinsischer fokus korreliert mit joy/motivation/positive erinnerung an etwas
-
- //zur welt:
- //
-
- //0-100:
- //motivation (bei arbeiter montag ~40, freitag ~80 - 100)
- //7 emotionen?
-
- // berufsfeld: webdesigner, pädagoge, schmuckdesigner, schmied
- // berufsstatus: beamter, selbstständiger, unternehmer, angestellter, grundschüler, gymnasiast, hauptschüler, realschüler, azubi, student, rentner
-
- // identität: gelbhemd, lokal, regional, national, international, fremd,
-
- Citizen[] citizen = new Citizen[i_citizenAmount];
-
- void initCitizen() {
- //namen: ethuriel, nathaniel, loriel, samuel, aluriel, aleriel, thaliel, suriel, kaliel,
- //int[][] claireArray = { { 00, 2 }, { 1, 3} };
-
- citizen[0] = new Citizen(0, 0, "", 0, 0);
- citizen[1] = new Citizen(1, 121, "Matze", 1, 28);
- citizen[2] = new Citizen(2, 18, "Freddy", 1, 28);
- citizen[3] = new Citizen(3, 59, "Korbi", 1, 28);
- citizen[4] = new Citizen(4, 121, "Lotte", 1, 26);
- citizen[5] = new Citizen(5, 18, "Reifi", 1, 26);
- citizen[6] = new Citizen(6, 59, "Grasso", 1, 28);
- citizen[7] = new Citizen(7, 121, "Nico", 1, 29);
- citizen[8] = new Citizen(8, 18, "Victor", 1, 28);
- citizen[9] = new Citizen(9, 59, "Paul", 1, 28);
- for (int i = 10; i < i_citizenAmount; i++) {
- int gender = int(random(0, 2));
- if (gender == 0) i_femaleCount++;
- int age = int(random(0, 100));
- citizen[i] = new Citizen(i, int(random(0, houses.size())), S_citizenNames[gender][int(random(0, S_citizenNames[gender].length))], gender, age);
- }
- for (int i = 1; i < citizen.length; i++) {
- citizen[i].spawn(citizen[i].i_home);
- }
- citizen[0].spawn(-500, -500);
-
- //if (citizen[i].b_randomRun) citizen[i].goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)), 10); //bad
-
- citizen[0].despawn();
- selectCitizen(0);
- }
-
- void selectCitizen(int i) {
- //citizen[i_selectedCitizen].b_randomRun = true;
- //citizen[i_selectedCitizen].b_moving = true;
- citizen[i_selectedCitizen].b_selected = false;
- //if (!b_autoPlayAfterSelect) {
- // citizen[i].b_randomRun = false;
- // citizen[i].b_moving = false;
- //}
- citizen[i].b_selected = true;
- i_selectedCitizen = i;
- }
-
- class Citizen extends Entity {
- int i_gender;
- String s_gender;
- int i_age;
- int i_home;
- String s_currentAction;
-
- int i_maxNodeDistance = 100; //amount of steps to circle around x, y until it finds the nearest node, if none found, breaks path finding. what to do then is defined in rescuePath()
- int i_spreadSteps = 10;
-
- float f_movementSpeed;
- float f_FOV = PI / 4.0;
- int i_visionDistance = 80;
- int i_lookRaySteps = 10;
- int i_id;
-
-
- int i_perceivedCitizen = -1;
- boolean b_perceivesCitizen;
-
- boolean b_randomRun = b_autoPlay;
-
- int i_goHomeHour, i_goHomeMinute;
- int i_goOutHour, i_goOutMinute;
- PVector dot = new PVector(0, 0);
-
-
- GraphNode startNode, endNode;
- int startNodeID, endNodeID;
- GraphNode[] rNodes;
- // ArrayList<GraphNode> rNodesList = new ArrayList<GraphNode>();
- int nextNode;
-
- IGraphSearch pathFinder;
- int pathAlgorithm = i_pathAlgorithm;
-
- Citizen(int id, int home, String name, int gender, int age) {
-
- i_id = id;
- i_home = home;
- s_name = name;
- i_gender = gender;
- s_gender = i_gender == 0 ? "Weiblich" : "Männlich";
- i_age = age;
- i_diameter = 30;
- pathFinder = makePathFinder(gs, pathAlgorithm);
- f_movementSpeed = random(f_walkSpeedMin, f_walkSpeedMax);
- rNodes = pathFinder.getRoute();
- s_currentAction = "current action here";
- c_color = color((int)(random(0, 255)), (int)(random(0, 255)), (int)(random(0, 255)));
- c_initialColor = c_color;
- c_selected = color(128, 50, 50);
- c_stroke = color(255, 255, 255);
- i_goHomeHour = (int)random(18, 21);
- i_goHomeMinute = (int)random(0, 59);
- i_goOutHour = (int)random(6, 9);
- i_goOutMinute = (int)random(0, 59);
- }
-
-
- int i_direction(float f, float v) {
- if (f <= 0-v) return -1;
- else if (f >= 0+v) return 1;
- else return 0;
- }
-
- void update() {
- if (b_turning) {
- turn();
- }
- if (b_moving) {
- move();
- }
- perceive();
- if (b_talking) {
- talk();
- }
-
- if (i_hours == i_goHomeHour && i_minutes == i_goHomeMinute) {
- b_randomRun = false;
- goTo((int)houses.get(i_home).v2_center.x, (int)houses.get(i_home).v2_center.y);
- }
-
- if (i_hours == i_goOutHour && i_minutes == i_goOutMinute) { //wake
- b_randomRun = true;
- i_location = 1;
- //goTo(int(random(0, pg_map.width)), int(random(0, pg_map.height)));
- goToRandom();
- }
-
- if (i_location == 1 && b_moving == false) { //sleep
- float r = red(c_color);
- float g = green(c_color);
- float b = blue(c_color);
-
- float r_new = (99*r + red(c_initialColor)) / 99.6666;
- float g_new = (99*g + green(c_initialColor)) / 99.6666;
- float b_new = (99*b + blue(c_initialColor)) / 99.6666;
-
- c_color = color(r_new, g_new, b_new);
- }
- }
-
- void display() {
-
- //if (b_selected) {
- pg_map.stroke(150, 150, 150, i_visionTransparency);
- pg_map.noFill();
- //pg_map.fill(127, 127, 127, i_visionTransparency);
- if (i_location == 1)
- pg_map.arc(f_xPos, f_yPos, i_visionDistance*2, i_visionDistance*2, f_angle+HALF_PI*1.5, f_angle+PI/2*2.5, PIE);
- //}
- //pg_map.stroke(c_stroke);
- pg_map.stroke(c_initialColor);
- pg_map.strokeWeight(1);
- if (b_selected) {
- pg_map.stroke(c_selected);
- pg_map.strokeWeight(3);
- }
- pg_map.fill(c_color);
- pg_map.ellipse(f_xPos, f_yPos, i_diameter, i_diameter);
- pg_map.fill(c_stroke);
- //pg_map.fill(c_initialColor);
- pg_map.textAlign(CENTER);
- pg_map.textSize(i_nameSize);
- int namePos = -i_diameter/3*2;
- if (b_talking) {
- pg_map.text("\"Hallo " + citizen[i_lastCitizenTalked].s_name + "\"", f_xPos, f_yPos-i_diameter/3*2);
- namePos = -i_diameter/3*2*2;
- }
- pg_map.text(s_name, f_xPos, f_yPos + namePos);
- pg_map.stroke(c_stroke);
- pg_map.strokeWeight(1);
- if (b_talking) {
-
- pg_map.line(f_xPos, f_yPos, citizen[i_lastCitizenTalked].f_xPos, citizen[i_lastCitizenTalked].f_yPos);
- }
- }
-
- void perceive() {
- b_perceivesCitizen = false;
- i_perceivedCitizen = -1;
- // if (!b_talking) {
- for (int i = -5; i < 6; i++) { //10 rays
- float f_rayAngle = (f_angle) + i/TWO_PI;
- for (int j = 0; j < 10; j++) { //10 steps of collision detection per ray
- for (int k = 1; k < i_lookRaySteps; k ++) {
- dot.x = f_xPos-k*((cos(f_rayAngle)*i_visionDistance)/i_lookRaySteps);
- dot.y = f_yPos-k*((sin(f_rayAngle)*i_visionDistance)/i_lookRaySteps);
- //if (b_debug)pg_map.point(dot.x, dot.y);
- for (int l = 0; l < citizen.length; l++) {
- if (dot.x > citizen[l].i_collBoundX && dot.x < citizen[l].i_collBoundX + citizen[l].i_collBoundW
- && dot.y > citizen[l].i_collBoundY && dot.y < citizen[l].i_collBoundY + citizen[l].i_collBoundH) {
- if (l != i_id && !b_perceivesCitizen && citizen[l].i_location == 1 && i_location == 1) {
- b_perceivesCitizen = true;
- i_perceivedCitizen = l;
- if (i_lastCitizenTalked != l && citizen[l].i_lastCitizenTalked != i_id) {
- turnTo(f_xPos-citizen[l].f_xPos, f_yPos-citizen[l].f_yPos, 2);
-
- if (citizen[l].i_perceivedCitizen == i_id) { //if perceived citizen perceives me and din't talk to me last time
- talkTo(citizen[l]);
- citizen[l].talkTo(this);
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- boolean b_talking;
- boolean b_movingBeforeTalk;
- int i_talkTimeStart;
- int i_talkTime = 5; //how long talk in seconds
- int i_lastCitizenTalked = -1;
-
- void talkTo(Citizen citizen) { //replace passing whole entity with passing id
- b_talking = true;
- //i_talkTimeStart = second();
- i_talkTimeStart = frameCount;
- b_movingBeforeTalk = b_moving;
- b_moving = false;
- i_lastCitizenTalked = citizen.i_id;
- }
-
- void talk() { //means: exchange colors
- float r = red(c_color);
- float g = green(c_color);
- float b = blue(c_color);
-
-
- float r_new = (19*r + red(citizen[i_lastCitizenTalked].c_color)) / 20;
- float g_new = (19*g + green(citizen[i_lastCitizenTalked].c_color)) / 20;
- float b_new = (19*b + blue(citizen[i_lastCitizenTalked].c_color)) / 20;
-
- c_color = color(r_new, g_new, b_new);
-
- //if (second() > (i_talkTimeStart + i_talkTime < 60 ? i_talkTimeStart + i_talkTime : i_talkTimeStart - 60 + i_talkTime)) {
- if (frameCount > i_talkTimeStart + i_talkTime * frameRate) {
-
- //c_color = (c_color + citizen[i_lastCitizenTalked].c_color) / 2;
- b_talking = false;
- //b_moving = b_movingBeforeTalk;
- b_moving = true;
- //prevent talking to the same person right after
- }
- }
-
- void goToRandom() {
- int randomNodeId = (int)random(0, gNodes.length);
- preparePath((int)gNodes[randomNodeId].x(), (int)gNodes[randomNodeId].y());
- getPath();
- }
-
- void goTo(int x, int y) {
- preparePath(x, y);
- getPath();
- }
-
- void goTo(House house) {
- preparePath((int)house.v2_center.x, (int)house.v2_center.y);
- getPath();
- }
-
-
- void move() {
- i_collBoundX = (int)f_xPos - (i_diameter/2);
- i_collBoundY = (int)f_yPos - (i_diameter/2);
- i_collBoundW = i_diameter;
- i_collBoundH = i_diameter;
- if (rNodes.length > nextNode) {
- float f_xPosNext = rNodes[nextNode].xf();
- float f_yPosNext = rNodes[nextNode].yf();
- float f_movementVelo = f_movementSpeed;
-
- if ((int)rNodes[nextNode].xf() != (int)f_xPos && int(rNodes[nextNode].yf()) != (int)f_yPos) f_movementVelo = f_movementVelo / 1.41; //slow down movement velocity if moving diagnoally
- f_xPos += i_direction(f_xPosNext-f_xPos, f_movementVelo) * f_movementVelo;
- f_yPos += i_direction(f_yPosNext-f_yPos, f_movementVelo) * f_movementVelo;
-
- turnTo(f_xPos-f_xPosNext, f_yPos-f_yPosNext, map(nextNode, 0, rNodes.length, 4, 1)); //lets them turn faster when they start their journey (looks like more motivation)
-
- if (abs(f_yPos - f_yPosNext) < f_movementVelo && abs(f_xPos - f_xPosNext) < f_movementVelo) {
- f_yPos = f_yPosNext;
- f_xPos = f_xPosNext;
- nextNode++;
- }
- } else {
-
-
- b_moving = false;
- nextNode = 0;
- if (!b_randomRun) {
- //check if standing on an other citizens position?
- } else {
- //goTo((int)random(0, pg_map.width), (int)random(0, pg_map.height));
- goToRandom();
- }
- }
- }
-
- void debug() {
- //draw Route
- if (rNodes.length >= 2) {
- pg_map.pushStyle();
- pg_map.stroke(color(100, 100, 200));
- pg_map.strokeWeight(1);
- pg_map.noFill();
- for (int i = 1; i < rNodes.length; i++)
- pg_map.line(rNodes[i-1].xf(), rNodes[i-1].yf(), rNodes[i].xf(), rNodes[i].yf());
- //draw destination
- pg_map.stroke(160, 0, 0);
- if (b_selected) pg_map.fill(255, 0, 0);
- else pg_map.fill(0);
- pg_map.ellipse(rNodes[rNodes.length-1].xf(), rNodes[rNodes.length-1].yf(), nodeSize, nodeSize);
- pg_map.popStyle();
- }
- }
-
- //moved this all the way down, extracted from old goTo(), hoping to never see again
- boolean b_pathFindKaputt;
- float nodeDistance;
- void getNodeDistance(float x, float y) { //circles around x, y until it finds the nearest node
- nodeDistance = 1.0f;
- while (gs.getNodeAt(x, y, 0, nodeDistance) == null && nodeDistance < i_maxNodeDistance) {
- nodeDistance++;
- }
- if (nodeDistance >= i_maxNodeDistance) {
- b_pathFindKaputt = true;
- }
- }
- void preparePath(int x, int y) { //tests if paths are available (to prevent failing on encapsuled areas)
- int spread = 0;
- boolean works = false;
- while (!works && !b_pathFindKaputt) {
- works = true;
- getNodeDistance(f_xPos, f_yPos);
- if (b_pathFindKaputt) break;
- startNodeID = gs.getNodeAt(f_xPos, f_yPos, 0, nodeDistance).id();
- getNodeDistance(x, y);
- if (b_pathFindKaputt) break;
- endNodeID = gs.getNodeAt(x, y, 0, nodeDistance).id();
- if (pathFinder.search(startNodeID, endNodeID, true) == null) {
- works = false;
- spread += i_spreadSteps;
- x+= spread;
- y+= spread;
- }
- if (spread >= i_spreadSteps * i_maxNodeDistance) b_pathFindKaputt = true;
- }
- }
-
- void getPath() {
- if (!b_pathFindKaputt) {
- pathFinder.search(startNodeID, endNodeID, true);
- rNodes = pathFinder.getRoute(); //this is the array i want here
- nextNode = 0; //necessary for move()
- b_moving = true;
- } else {
- rescuePath();
- }
- }
- void rescuePath() {
- b_pathFindKaputt = false;
- //teleport somewhere and go home - needs better solution!!! maybe give a little push?
- int randomNodeId = (int)random(0, gNodes.length);
- f_xPos = (int)gNodes[randomNodeId].x();
- f_yPos = (int)gNodes[randomNodeId].y();
- //goTo((int)houses.get(i_home).v2_center.x, (int)houses.get(i_home).v2_center.y);
- goToRandom();
- }
- }
-
-
-
- String[][] S_citizenNames = { { "Marie", "Mari", "Sophie", "Maria", "Sophia", "Sofia", "Emilia", "Emma", "Hannah", "Hanna", "Anna", "Luisa", "Louisa", "Mia", "Emma", "Sophia", "Sofia", "Hanna", "Hannah", "Emilia",
- "Mia", "Anna", "Lina", "Mila", "Klara", "Clara", "Marie", "Lea", "Leah", "Lena", "Henri", "Luisa", "Ella", "Leni", "Sophie", "Sofie", "Marie", "Maria", "Luise", "Louise", "Sophia", "Sofia",
- "Elisabeth", "Katharina", "Catharina", "Charlotte", "Johanna", "Emilia", "Anna", "Luisa", "Louisa", "Victoria", "Viktoria", "Josefine", "Josephine", "Mathilda", "Matilda", "Layla", "Leyla", "Elif", "Nur", "Amira", "Aliyah", "Amina" },
- { "Maximilian", "Alexander", "Paul", "Elias", "Ben", "Noah", "Noa", "Leon", "Léon", "Louis", "Luis", "Jonas", "Felix", "Ben", "Paul", "Noah", "Noa", "Leon", "Léon", "Jonas", "Felix",
- "Elias", "Louis", "Luis", "Lukas", "Lucas", "Maximilian", "Finn", "Henry", "Emil", "Luca", "Luka", "Jakob", "Jacob", "Alexander", "Maximilian", "Elias", "Paul", "Michael", "Karl", "Carl",
- "Johannes", "Nico", "Luka", "Johann", "Stefan", "Louis", "Luis", "Christian", "Kristian", "Anton", "Andreas", "David", "Mohammed", "Ali", "Malik", "Emir", "Yusuf", "Ilyas" } };
|