Add material-aware ant pickup with carry strength check

This commit is contained in:
Jared Miller 2026-03-11 15:23:03 -04:00
parent 94b0393abb
commit 43d3e56aee
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -14,7 +14,9 @@ uniform sampler2D tLastExtState;
uniform sampler2D tWorld; uniform sampler2D tWorld;
uniform sampler2D tPresence; uniform sampler2D tPresence;
uniform float uForagerRatio; uniform float uForagerRatio;
uniform sampler2D uMaterialProps;
const float ANT_CARRY_STRENGTH = 1.0;
const float sampleDistance = 20.; const float sampleDistance = 20.;
const float cellSize = 1. / WORLD_SIZE; const float cellSize = 1. / WORLD_SIZE;
@ -88,7 +90,7 @@ void main() {
bool wasObstacle = isObstacle(pos); bool wasObstacle = isObstacle(pos);
float personality = lastExtState.r; float personality = lastExtState.r;
float cargoQuality = lastExtState.g; float cargoMaterialId = lastExtState.g;
float pathIntDx = lastExtState.b; float pathIntDx = lastExtState.b;
float pathIntDy = lastExtState.a; float pathIntDy = lastExtState.a;
@ -116,7 +118,7 @@ void main() {
isCarrying = 0.; isCarrying = 0.;
storage = 0.; storage = 0.;
personality = rand(vUv * 42069.); // 0.0 = pure follower, 1.0 = pure explorer personality = rand(vUv * 42069.); // 0.0 = pure follower, 1.0 = pure explorer
cargoQuality = 0.; cargoMaterialId = 0.;
pathIntDx = 0.; pathIntDx = 0.;
pathIntDy = 0.; pathIntDy = 0.;
} }
@ -210,10 +212,28 @@ void main() {
angle += PI * (noise - 0.5); angle += PI * (noise - 0.5);
} }
if (tryGetFood(pos) && isCarrying == 0.) { 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.; isCarrying = 1.;
cargoMaterialId = cellMatId;
angle += PI; angle += PI;
storage = getMaxScentStorage(vUv); 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)) { if (tryDropFood(pos)) {
@ -221,6 +241,7 @@ void main() {
if (isCarrying == 1.) { if (isCarrying == 1.) {
isCarrying = 0.; isCarrying = 0.;
cargoMaterialId = 0.;
angle += PI; angle += PI;
} }
} }
@ -231,5 +252,5 @@ void main() {
angle, angle,
float((uint(max(storage - SCENT_PER_MARKER, 0.)) << 1) + uint(isCarrying)) float((uint(max(storage - SCENT_PER_MARKER, 0.)) << 1) + uint(isCarrying))
); );
FragColorExt = vec4(personality, cargoQuality, pathIntDx, pathIntDy); FragColorExt = vec4(personality, cargoMaterialId, pathIntDx, pathIntDy);
} }