mirror of
https://github.com/fazo96/AIrium.git
synced 2025-01-10 09:34:20 +01:00
fixed a bug with vision and added new vegetable_size setting
This commit is contained in:
parent
c56c24e99d
commit
5c44b30cc6
@ -183,6 +183,7 @@ public class Serializer {
|
|||||||
+ "nMutatedConnections = 0.5\n"
|
+ "nMutatedConnections = 0.5\n"
|
||||||
+ "number_of_creatures = 25.0\n"
|
+ "number_of_creatures = 25.0\n"
|
||||||
+ "draw_sight_lines = 0.0\n"
|
+ "draw_sight_lines = 0.0\n"
|
||||||
|
+ "vegetable_size = 5\n"
|
||||||
+ "creature_max_hp = 100\n"
|
+ "creature_max_hp = 100\n"
|
||||||
+ "creature_fov = 1.5\n"
|
+ "creature_fov = 1.5\n"
|
||||||
+ "creature_hp_decay = 0.5\n"
|
+ "creature_hp_decay = 0.5\n"
|
||||||
|
@ -9,7 +9,7 @@ import com.mygdx.game.Game;
|
|||||||
*/
|
*/
|
||||||
public class Vegetable extends Element {
|
public class Vegetable extends Element {
|
||||||
|
|
||||||
public static final float default_radius = 5;
|
public static float default_radius = 5;
|
||||||
private float decayRate = 0;
|
private float decayRate = 0;
|
||||||
|
|
||||||
public Vegetable(float x, float y) {
|
public Vegetable(float x, float y) {
|
||||||
|
@ -289,6 +289,7 @@ public class World implements Runnable {
|
|||||||
Eye.fov = options.get("creature_fov");
|
Eye.fov = options.get("creature_fov");
|
||||||
Eye.sightRange = options.get("creature_sight_range");
|
Eye.sightRange = options.get("creature_sight_range");
|
||||||
Torso.hpDecay = options.get("creature_hp_decay");
|
Torso.hpDecay = options.get("creature_hp_decay");
|
||||||
|
Vegetable.default_radius = options.get("vegetable_size");
|
||||||
Creature.hpForAttacking = options.get("creature_hp_for_attacking");
|
Creature.hpForAttacking = options.get("creature_hp_for_attacking");
|
||||||
Creature.hpForEatingPlants = options.get("creature_hp_for_eating_plants");
|
Creature.hpForEatingPlants = options.get("creature_hp_for_eating_plants");
|
||||||
Creature.pointsForAttacking = options.get("creature_points_for_attacking");
|
Creature.pointsForAttacking = options.get("creature_points_for_attacking");
|
||||||
|
@ -18,7 +18,8 @@ import logic.Vegetable;
|
|||||||
public class Eye extends BodyPart {
|
public class Eye extends BodyPart {
|
||||||
|
|
||||||
private Sight sights[];
|
private Sight sights[];
|
||||||
private int seen;
|
private int farthest = -1, seen;
|
||||||
|
private float farthestDistance = 0;
|
||||||
public static float fov = 2, sightRange = 30;
|
public static float fov = 2, sightRange = 30;
|
||||||
|
|
||||||
public Eye(int nSights, float angle, Creature creature) {
|
public Eye(int nSights, float angle, Creature creature) {
|
||||||
@ -54,19 +55,32 @@ public class Eye extends BodyPart {
|
|||||||
j += 6;
|
j += 6;
|
||||||
}
|
}
|
||||||
seen = 0;
|
seen = 0;
|
||||||
|
farthest = -1;
|
||||||
|
farthestDistance = 0;
|
||||||
sights = new Sight[sights.length];
|
sights = new Sight[sights.length];
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void interactWithElement(Element e, float distance, float angle) {
|
public void interactWithElement(Element e, float distance, float angle) {
|
||||||
if (e != creature && distance < sightRange && Math.abs(angle) < fov / 2) {
|
if (e != creature && distance < sightRange && (distance < farthestDistance || seen < sights.length) && Math.abs(angle) < fov / 2) {
|
||||||
if (seen < sights.length) {
|
if (seen < sights.length) {
|
||||||
sights[seen] = new Sight(e, distance, angle);
|
sights[seen] = new Sight(e, distance, angle);
|
||||||
Log.log(Log.DEBUG, "Saw " + e.getClass().getName() + " at " + distance + " with relative angle " + angle);
|
Log.log(Log.DEBUG,"Adding Sight number "+seen);
|
||||||
seen++;
|
seen++;
|
||||||
|
} else {
|
||||||
|
Log.log(Log.DEBUG,"Substituting Farthest");
|
||||||
|
sights[farthest] = new Sight(e, distance, angle);
|
||||||
|
farthest = -1;
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < seen; i++) {
|
||||||
|
Sight s = sights[i];
|
||||||
|
if (s.getDistance() > farthestDistance || farthest < 0) {
|
||||||
|
farthestDistance = s.getDistance();
|
||||||
|
farthest = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.log(Log.DEBUG,"Seen " + seen + "/" + sights.length + ". Farthest is now " + farthest + " at " + farthestDistance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user