Beispiel #1
0
int32_t ai_attackmelee(struct world* world, struct entity* entity, struct aitask* ai) {
	struct ai_attackmelee_data* amd = ai->data;
	entity->ai->lookHelper_speedYaw = 30.;
	entity->ai->lookHelper_speedPitch = 30.;
	entity->ai->lookHelper_x = entity->attacking->x;
	struct boundingbox bb;
	getEntityCollision(entity->attacking, &bb);
	entity->ai->lookHelper_y = entity->attacking->y + ((bb.maxY - bb.minY) * .9); // TODO: real eye height
	entity->ai->lookHelper_z = entity->attacking->z;
	double dist = entity_distsq(entity->attacking, entity);
	amd->delayCounter--;
//TODO: cansee
	if ((amd->longMemory || 1) && amd->delayCounter <= 0 && ((amd->targetX == 0. && amd->targetY == 0. && amd->targetZ == 0.) || entity_distsq_block(entity->attacking, amd->targetX, amd->targetY, amd->targetZ) >= 1. || randFloat() < .05)) {
		amd->targetX = entity->attacking->x;
		amd->targetY = entity->attacking->y;
		amd->targetZ = entity->attacking->z;
		if (dist > 1024.) amd->delayCounter += 10;
		else if (dist > 256.) amd->delayCounter += 5.;
		//TODO: set path
	}
	if (--amd->attackTick <= 0) amd->attackTick = 0;
	struct entity_info* ei = getEntityInfo(entity->type);
	struct entity_info* ei2 = getEntityInfo(entity->attacking->type);
	float reach = ei->width * 2. * ei->width * 2. + ei2->width;
	if (dist <= reach && amd->attackTick <= 0) {
		amd->attackTick = 20;
		swingArm(entity);
		damageEntityWithItem(entity->attacking, entity, -1, NULL);
	}
	return 0;
}
Entity *Entity::getAllCollision(void)
{
   Entity *e = getEntityCollision();
   if (e)
      return e;
   return getPlayerCollision();
}
Beispiel #3
0
void lookHelper_tick(struct entity* entity) {
	if (entity->ai == NULL || entity->ai->lookHelper_speedPitch == 0. || entity->ai->lookHelper_speedYaw == 0.) return;
	double dx = entity->ai->lookHelper_x - entity->x;
	struct boundingbox bb;
	getEntityCollision(entity, &bb);
	double dy = entity->ai->lookHelper_y - entity->y - ((bb.maxY - bb.minY) * .9); // TODO: real eye height
	double dz = entity->ai->lookHelper_z - entity->z;
	double horiz_dist = sqrt(dx * dx + dz * dz);
	float dp = -(atan2(dy, horiz_dist) * 180. / M_PI);
	float dya = (atan2(dz, dx) * 180. / M_PI) - 90.;
	dp = wrapAngle(dp - entity->pitch);
	if (dp > entity->ai->lookHelper_speedPitch) dp = entity->ai->lookHelper_speedPitch;
	if (dp < -entity->ai->lookHelper_speedPitch) dp = -entity->ai->lookHelper_speedPitch;
	entity->pitch += dp;
	dya = wrapAngle(dya - entity->yaw);
	if (dya > entity->ai->lookHelper_speedYaw) dya = entity->ai->lookHelper_speedYaw;
	if (dya < -entity->ai->lookHelper_speedYaw) dya = -entity->ai->lookHelper_speedYaw;
	entity->yaw += dya;
	if (fabs(dp) < 0.5 && fabs(dya) < .5) {
		entity->ai->lookHelper_speedPitch = 0.;
		entity->ai->lookHelper_speedYaw = 0.;
	}
}