Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Human and NightElf Build #5

Open
wants to merge 6 commits into
base: experimental
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class CUnitType {
private final String legacyName;
private final War3ID typeId;
private final int maxLife;
private final float lifeRegeneration;
private final int manaInitial;
private final int manaMaximum;
private final int speed;
Expand Down Expand Up @@ -76,29 +75,29 @@ public class CUnitType {
private final int properNamesCount;
private final boolean canFlee;
private final int priority;

public CUnitType(final String name, final String legacyName, final War3ID typeId, final int maxLife, final float lifeRegeneration,
final int manaInitial, final int manaMaximum, final int speed, final int defense, final String abilityList,
final boolean isBldg, final MovementType movementType, final float defaultFlyingHeight,
final float collisionSize, final EnumSet<CUnitClassification> classifications,
final List<CUnitAttack> attacks, final String armorType, final boolean raise, final boolean decay,
final CDefenseType defenseType, final float impactZ, final BufferedImage buildingPathingPixelMap,
final float deathTime, final EnumSet<CTargetType> targetedAs, final float defaultAcquisitionRange,
final float minimumAttackRange, final List<War3ID> structuresBuilt, final List<War3ID> unitsTrained,
final List<War3ID> researchesAvailable, final CUnitRace unitRace, final int goldCost, final int lumberCost,
final int foodUsed, final int foodMade, final int buildTime,
final EnumSet<CBuildingPathingType> preventedPathingTypes,
final EnumSet<CBuildingPathingType> requiredPathingTypes, final float propWindow, final float turnRate,
final List<CUnitTypeRequirement> requirements, final int level, final boolean hero, final int strength,
final float strengthPerLevel, final int agility, final float agilityPerLevel, final int intelligence,
final float intelligencePerLevel, final CPrimaryAttribute primaryAttribute,
final List<War3ID> heroAbilityList, final List<String> heroProperNames, final int properNamesCount,
final boolean canFlee, final int priority) {
private final boolean revivesHeroes;

public CUnitType(final String name, final String legacyName, final War3ID typeId, final int maxLife,
final int manaInitial, final int manaMaximum, final int speed, final int defense, final String abilityList,
final boolean isBldg, final MovementType movementType, final float defaultFlyingHeight,
final float collisionSize, final EnumSet<CUnitClassification> classifications,
final List<CUnitAttack> attacks, final String armorType, final boolean raise, final boolean decay,
final CDefenseType defenseType, final float impactZ, final BufferedImage buildingPathingPixelMap,
final float deathTime, final EnumSet<CTargetType> targetedAs, final float defaultAcquisitionRange,
final float minimumAttackRange, final List<War3ID> structuresBuilt, final List<War3ID> unitsTrained,
final List<War3ID> researchesAvailable, final CUnitRace unitRace, final int goldCost, final int lumberCost,
final int foodUsed, final int foodMade, final int buildTime,
final EnumSet<CBuildingPathingType> preventedPathingTypes,
final EnumSet<CBuildingPathingType> requiredPathingTypes, final float propWindow, final float turnRate,
final List<CUnitTypeRequirement> requirements, final int level, final boolean hero, final int strength,
final float strengthPerLevel, final int agility, final float agilityPerLevel, final int intelligence,
final float intelligencePerLevel, final CPrimaryAttribute primaryAttribute,
final List<War3ID> heroAbilityList, final List<String> heroProperNames, final int properNamesCount,
final boolean canFlee, final int priority, final boolean revivesHeroes) {
this.name = name;
this.legacyName = legacyName;
this.typeId = typeId;
this.maxLife = maxLife;
this.lifeRegeneration = lifeRegeneration;
this.manaInitial = manaInitial;
this.manaMaximum = manaMaximum;
this.speed = speed;
Expand Down Expand Up @@ -148,6 +147,7 @@ public CUnitType(final String name, final String legacyName, final War3ID typeId
this.properNamesCount = properNamesCount;
this.canFlee = canFlee;
this.priority = priority;
this.revivesHeroes = revivesHeroes;
}

public String getName() {
Expand All @@ -166,10 +166,6 @@ public int getMaxLife() {
return this.maxLife;
}

public float getLifeRegeneration() {
return this.lifeRegeneration;
}

public int getManaInitial() {
return this.manaInitial;
}
Expand Down Expand Up @@ -365,4 +361,8 @@ public boolean isCanFlee() {
public int getPriority() {
return this.priority;
}
}

public boolean isRevivesHeroes() {
return this.revivesHeroes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.CAbilityVisitor;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.targeting.AbilityPointTarget;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.CBehavior;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.build.CBehaviorNightElfBuild;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.build.CBehaviorOrcBuild;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.orders.OrderIds;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayer;

public class CAbilityNightElfBuild extends AbstractCAbilityBuild {
private CBehaviorOrcBuild buildBehavior;
private CBehaviorNightElfBuild buildBehavior;

public CAbilityNightElfBuild(final int handleId, final List<War3ID> structuresBuilt) {
super(handleId, structuresBuilt);
Expand All @@ -29,7 +30,7 @@ public <T> T visit(final CAbilityVisitor<T> visitor) {

@Override
public void onAdd(final CSimulation game, final CUnit unit) {
this.buildBehavior = new CBehaviorOrcBuild(unit);
this.buildBehavior = new CBehaviorNightElfBuild(unit);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.build;

public class CBehaviorHumanBuild {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.build;

import com.etheller.warsmash.util.WarsmashConstants;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CSimulation;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnit;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.CUnitType;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.CAbility;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.abilities.build.CAbilityBuildInProgress;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.CBehavior;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.pathing.CBuildingPathingType;
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayer;

import java.awt.image.BufferedImage;
import java.util.EnumSet;

public class CBehaviorNightElfBuild extends CBehaviorOrcBuild{
public CBehaviorNightElfBuild(CUnit unit) {
super(unit);
}

@Override
protected CBehavior update(final CSimulation simulation, final boolean withinFacingWindow) {
if (!this.unitCreated) {
this.unitCreated = true;
final CUnitType unitTypeToCreate = simulation.getUnitData().getUnitType(this.orderId);
final BufferedImage buildingPathingPixelMap = unitTypeToCreate.getBuildingPathingPixelMap();
boolean buildLocationObstructed = false;
if (buildingPathingPixelMap != null) {
final EnumSet<CBuildingPathingType> preventedPathingTypes = unitTypeToCreate.getPreventedPathingTypes();
final EnumSet<CBuildingPathingType> requiredPathingTypes = unitTypeToCreate.getRequiredPathingTypes();

if (!simulation.getPathingGrid().checkPathingTexture(this.target.getX(), this.target.getY(),
(int) simulation.getGameplayConstants().getBuildingAngle(), buildingPathingPixelMap,
preventedPathingTypes, requiredPathingTypes, simulation.getWorldCollision(), this.unit)) {
buildLocationObstructed = true;
}
}
final int playerIndex = this.unit.getPlayerIndex();
if (!buildLocationObstructed) {
final CUnit constructedStructure = simulation.createUnit(this.orderId, playerIndex, this.target.getX(),
this.target.getY(), simulation.getGameplayConstants().getBuildingAngle());
constructedStructure.setConstructing(true);
constructedStructure.setWorkerInside(this.unit);
constructedStructure.setLife(simulation,
constructedStructure.getMaximumLife() * WarsmashConstants.BUILDING_CONSTRUCT_START_LIFE);
constructedStructure.setFoodUsed(unitTypeToCreate.getFoodUsed());
constructedStructure.add(simulation,
new CAbilityBuildInProgress(simulation.getHandleIdAllocator().createId()));
for (final CAbility ability : constructedStructure.getAbilities()) {
ability.visit(AbilityDisableWhileUnderConstructionVisitor.INSTANCE);
}
this.unit.setHidden(true);
this.unit.setPaused(true);
this.unit.setInvulnerable(true);
constructedStructure.setConstuctionProcessType(ConstructionFlag.CONSUME_WORKER);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if instead of setting the construction progress type in this large copy of the Orc Build code, we have the orc style build base class for the behavior call some function here, maybe called applyConstructionProgressType(constructedStructure) that is abstract and implemented by the subclass, so that Night Elf build will make this call to tell the unit to have CONSUME_WORKER flag, and orc build will do nothing. That way, a year from now when someone needs to change all of this other code for how orc build works in the "update" method, that person in the future won't have to change two copies of this?

This comment is just a stylistic suggestion more than anything, in case someone has time to play with that whenever one of us handles the merge conflicts. (My "experimental" branch does not have Night Elf build yet at the time of writing, so thinking about this isn't wasted effort, although just getting your change as written into there would be great too.) Looks like what you have should still work fine, and there are plenty of non-ideal stylstic choices in my code with worse code duplication than this sitting around. So, just a suggestion here that occurred to me while reviewing.

simulation.unitConstructedEvent(this.unit, constructedStructure);
}
else {
final CPlayer player = simulation.getPlayer(playerIndex);
refund(player, unitTypeToCreate);
simulation.getCommandErrorListener(playerIndex).showCantPlaceError();
}
}
return this.unit.pollNextOrderBehavior(simulation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayer;

public class CBehaviorOrcBuild extends CAbstractRangedBehavior {
private int highlightOrderId;
private War3ID orderId;
private boolean unitCreated = false;
protected int highlightOrderId;
protected War3ID orderId;
protected boolean unitCreated = false;

public CBehaviorOrcBuild(final CUnit unit) {
super(unit);
Expand Down Expand Up @@ -118,7 +118,7 @@ public void end(final CSimulation game, final boolean interrupted) {
}
}

private void refund(final CPlayer player, final CUnitType unitTypeToCreate) {
protected void refund(final CPlayer player, final CUnitType unitTypeToCreate) {
player.setFoodUsed(player.getFoodUsed() - unitTypeToCreate.getFoodUsed());
player.refundFor(unitTypeToCreate);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.etheller.warsmash.viewer5.handlers.w3x.simulation.behaviors.build;

public enum ConstructionFlag {
NONE, CONSUME_WORKER, REQURIE_REPAIR;
}
Loading