Add material-aware ant pickup with carry strength check
This commit is contained in:
parent
94b0393abb
commit
43d3e56aee
1 changed files with 28 additions and 7 deletions
|
|
@ -14,7 +14,9 @@ uniform sampler2D tLastExtState;
|
|||
uniform sampler2D tWorld;
|
||||
uniform sampler2D tPresence;
|
||||
uniform float uForagerRatio;
|
||||
uniform sampler2D uMaterialProps;
|
||||
|
||||
const float ANT_CARRY_STRENGTH = 1.0;
|
||||
const float sampleDistance = 20.;
|
||||
const float cellSize = 1. / WORLD_SIZE;
|
||||
|
||||
|
|
@ -88,7 +90,7 @@ void main() {
|
|||
bool wasObstacle = isObstacle(pos);
|
||||
|
||||
float personality = lastExtState.r;
|
||||
float cargoQuality = lastExtState.g;
|
||||
float cargoMaterialId = lastExtState.g;
|
||||
float pathIntDx = lastExtState.b;
|
||||
float pathIntDy = lastExtState.a;
|
||||
|
||||
|
|
@ -116,7 +118,7 @@ void main() {
|
|||
isCarrying = 0.;
|
||||
storage = 0.;
|
||||
personality = rand(vUv * 42069.); // 0.0 = pure follower, 1.0 = pure explorer
|
||||
cargoQuality = 0.;
|
||||
cargoMaterialId = 0.;
|
||||
pathIntDx = 0.;
|
||||
pathIntDy = 0.;
|
||||
}
|
||||
|
|
@ -210,10 +212,28 @@ void main() {
|
|||
angle += PI * (noise - 0.5);
|
||||
}
|
||||
|
||||
if (tryGetFood(pos) && isCarrying == 0.) {
|
||||
isCarrying = 1.;
|
||||
angle += PI;
|
||||
storage = getMaxScentStorage(vUv);
|
||||
if (isCarrying == 0.) {
|
||||
float cellMatId = texture(tWorld, roundUvToCellCenter(pos)).x;
|
||||
int cellMatInt = int(cellMatId);
|
||||
|
||||
if (cellMatInt == MAT_FOOD) {
|
||||
// food pickup (existing foraging behavior)
|
||||
isCarrying = 1.;
|
||||
cargoMaterialId = cellMatId;
|
||||
angle += PI;
|
||||
storage = getMaxScentStorage(vUv);
|
||||
} else if (cellMatInt != MAT_AIR && cellMatInt != MAT_HOME) {
|
||||
// check if diggable powder material
|
||||
vec4 props = texelFetch(uMaterialProps, ivec2(cellMatInt, 0), 0);
|
||||
float behavior = props.r;
|
||||
float hardness = props.b;
|
||||
if (behavior == BEHAVIOR_POWDER && hardness <= ANT_CARRY_STRENGTH) {
|
||||
isCarrying = 1.;
|
||||
cargoMaterialId = cellMatId;
|
||||
angle += PI;
|
||||
storage = getMaxScentStorage(vUv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tryDropFood(pos)) {
|
||||
|
|
@ -221,6 +241,7 @@ void main() {
|
|||
|
||||
if (isCarrying == 1.) {
|
||||
isCarrying = 0.;
|
||||
cargoMaterialId = 0.;
|
||||
angle += PI;
|
||||
}
|
||||
}
|
||||
|
|
@ -231,5 +252,5 @@ void main() {
|
|||
angle,
|
||||
float((uint(max(storage - SCENT_PER_MARKER, 0.)) << 1) + uint(isCarrying))
|
||||
);
|
||||
FragColorExt = vec4(personality, cargoQuality, pathIntDx, pathIntDy);
|
||||
FragColorExt = vec4(personality, cargoMaterialId, pathIntDx, pathIntDy);
|
||||
}
|
||||
Loading…
Reference in a new issue