diff --git a/src/main/java/org/terasology/metalrenegades/ai/system/FactionEnemiesSystem.java b/src/main/java/org/terasology/metalrenegades/ai/system/FactionEnemiesSystem.java index b7928369..b0d89031 100644 --- a/src/main/java/org/terasology/metalrenegades/ai/system/FactionEnemiesSystem.java +++ b/src/main/java/org/terasology/metalrenegades/ai/system/FactionEnemiesSystem.java @@ -1,21 +1,9 @@ -/* - * Copyright 2018 MovingBlocks - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.metalrenegades.ai.system; import com.google.common.collect.Lists; +import org.joml.Vector3f; import org.terasology.entitySystem.entity.EntityManager; import org.terasology.entitySystem.entity.EntityRef; import org.terasology.entitySystem.systems.BaseComponentSystem; @@ -23,7 +11,6 @@ import org.terasology.entitySystem.systems.RegisterSystem; import org.terasology.entitySystem.systems.UpdateSubscriberSystem; import org.terasology.logic.location.LocationComponent; -import org.terasology.math.geom.Vector3f; import org.terasology.metalrenegades.ai.component.CitizenComponent; import org.terasology.metalrenegades.ai.component.FactionAlignmentComponent; import org.terasology.metalrenegades.ai.component.NearbyCitizenEnemiesComponent; @@ -45,9 +32,9 @@ public class FactionEnemiesSystem extends BaseComponentSystem implements UpdateS @Override public void update(float delta) { - counter+=delta; + counter += delta; - if(counter < ENEMY_CHECK_DELAY) { + if (counter < ENEMY_CHECK_DELAY) { return; } @@ -59,19 +46,19 @@ public void update(float delta) { } /** - * Checks for faction enemies nearby a particular citizen. Enemies are defined as follows: - * {@link org.terasology.metalrenegades.ai.system.FactionAlignmentSystem.Alignment#GOOD} citizens are enemies of - * {@link org.terasology.metalrenegades.ai.system.FactionAlignmentSystem.Alignment#BAD} citizens, and vice-versa, - * while {@link org.terasology.metalrenegades.ai.system.FactionAlignmentSystem.Alignment#NEUTRAL} are enemies with - * no other citizens. - * + * Checks for faction enemies nearby a particular citizen. Enemies are defined as follows: {@link + * org.terasology.metalrenegades.ai.system.FactionAlignmentSystem.Alignment#GOOD} citizens are enemies of {@link + * org.terasology.metalrenegades.ai.system.FactionAlignmentSystem.Alignment#BAD} citizens, and vice-versa, while + * {@link org.terasology.metalrenegades.ai.system.FactionAlignmentSystem.Alignment#NEUTRAL} are enemies with no + * other citizens. + *
* Results are stored in {@link NearbyCitizenEnemiesComponent}. * * @param citizen The citizen to check enemies for. */ private void checkForEnemies(EntityRef citizen) { if (!citizen.hasComponent(NearbyCitizenEnemiesComponent.class) - || !citizen.hasComponent(FactionAlignmentComponent.class)) { + || !citizen.hasComponent(FactionAlignmentComponent.class)) { return; } @@ -82,23 +69,23 @@ private void checkForEnemies(EntityRef citizen) { enemiesComponent.closestEnemy = EntityRef.NULL; float minDistance = Float.MAX_VALUE; - Vector3f actorPosition = citizen.getComponent(LocationComponent.class).getWorldPosition(); + Vector3f actorPosition = citizen.getComponent(LocationComponent.class).getWorldPosition(new Vector3f()); for (EntityRef otherCitizen : entityManager.getEntitiesWith(CitizenComponent.class)) { if (!otherCitizen.hasComponent(FactionAlignmentComponent.class) - || otherCitizen.equals(citizen)) { + || otherCitizen.equals(citizen)) { continue; } FactionAlignmentComponent otherAlignmentComponent = otherCitizen.getComponent(FactionAlignmentComponent.class); if (otherAlignmentComponent.alignment.equals(alignmentComponent.alignment) // continue if alignments are - || otherAlignmentComponent.alignment.equals(FactionAlignmentSystem.Alignment.NEUTRAL) // the same, or either alignment - || alignmentComponent.alignment.equals(FactionAlignmentSystem.Alignment.NEUTRAL)) { // is neutral. + || otherAlignmentComponent.alignment.equals(FactionAlignmentSystem.Alignment.NEUTRAL) // the same, or either alignment + || alignmentComponent.alignment.equals(FactionAlignmentSystem.Alignment.NEUTRAL)) { // is neutral. continue; } LocationComponent otherLocationComponent = otherCitizen.getComponent(LocationComponent.class); - float distanceApart = otherLocationComponent.getWorldPosition().distanceSquared(actorPosition); + float distanceApart = otherLocationComponent.getWorldPosition(new Vector3f()).distanceSquared(actorPosition); if (distanceApart > enemiesComponent.searchRadius * enemiesComponent.searchRadius) { continue; @@ -106,7 +93,7 @@ private void checkForEnemies(EntityRef citizen) { if (distanceApart < minDistance) { enemiesComponent.closestEnemy = otherCitizen; - minDistance = otherLocationComponent.getWorldPosition().distanceSquared(actorPosition); + minDistance = distanceApart; } enemiesComponent.enemiesWithinRange.add(otherCitizen);