/* * Sub KLASSE Pflanzer * * Pflanzen auf dem terrain zu einem gewissen prozentwert blumen * die blumen können die agenten nur unterhalb einer gewissen höhe des terrains pflanzen, und nicht auf den wegen * sie fühlen sich wohl wenn keine pflanzenfresser in der nähe sind * wenn sie sich wohl fühlen, ensteht ein neuer pflanzer * sie sterben ab, wenn 4 oder mehr pflanzenfresser in ihrer nähe sind * */ class AgentPflanzer extends Agent { int pflanzeSetzen=50; color meineFarbe = #00FF00; int fuehlmichWohl=0; AgentPflanzer(float x, float y,float s, float a, float to) { xPos = x; yPos = y; speed = s; angle = a; torkeln = to; } AgentPflanzer(float x, float y,float s, float a) { xPos = x; yPos = y; speed = s; angle = a; } // Methode - zeichnet den agenten void drawme() { actions(); noStroke(); fill(meineFarbe); ellipse(xPos,yPos,6,6); } // Methode - welche aktionen/überprüfungen ausgeführt werden sollen void actions() { float radian = angle *PI/180; xPos += speed * sin(radian)+random(-torkeln,torkeln); yPos += speed * cos(radian)+random(-torkeln,torkeln); randCollision(); setzeMich(); wiegehtsMir(); } // Methode - kontrolle zustand des pflanzers. absterben (zu viele pflucker in umgebung) oder neu enstehen (am pflanzen). // fuehlt sich wohl wenn keine plfuecker in umgebung sind void wiegehtsMir() { if(findAgent(pflueckerListe)>=4&&pflanzerListe.size()>1) { AgentPflanzer currPflanzer= (AgentPflanzer)pflanzerListe.get(meineID); pflanzerListe.remove(currPflanzer); } if(findAgent(pflanzerListe)>=20&&pflanzerListe.size()>1) { AgentPflanzer currPflanzer= (AgentPflanzer)pflanzerListe.get(meineID); pflanzerListe.remove(currPflanzer); } if(findAgent(pflueckerListe)<1) { fuehlmichWohl+=1; } if(findAgent(pflueckerListe)>=1&&fuehlmichWohl>-400) { fuehlmichWohl-=2; } if(fuehlmichWohl>300) { AgentPflanzer newAgent = new AgentPflanzer(xPos, yPos, speed, random(0,360)); pflanzerListe.add(newAgent); fuehlmichWohl=0; } //println(fuehlmichWohl +" "+ meineID); } // Methode - setzt eine Pflanze am Ort void setzeMich() { int pixx = (int)(xPos/kg); int pixy = (int)(yPos/kg); distance=calcDistance(xPos,yPos); if (FarbenPalette[pixx][pixy]<150 && distance>2*wegBreite) { if(random(0,1000)