From fc9c7fb6e1552e1acd00b9cc6b5e396a2cbfb633 Mon Sep 17 00:00:00 2001 From: Retera Date: Sat, 16 Oct 2021 13:47:12 -0400 Subject: [PATCH] Fix some missing script API functions --- .../warsmash/WarsmashGdxMenuScreen.java | 19 ++++---- .../etheller/warsmash/parsers/jass/Jass2.java | 43 +++++++++++++++++-- .../warsmash/util/WarsmashConstants.java | 4 +- .../handlers/w3x/simulation/CSimulation.java | 12 +++++- 4 files changed, 61 insertions(+), 17 deletions(-) diff --git a/core/src/com/etheller/warsmash/WarsmashGdxMenuScreen.java b/core/src/com/etheller/warsmash/WarsmashGdxMenuScreen.java index d411785..a4b721a 100644 --- a/core/src/com/etheller/warsmash/WarsmashGdxMenuScreen.java +++ b/core/src/com/etheller/warsmash/WarsmashGdxMenuScreen.java @@ -205,7 +205,8 @@ public class WarsmashGdxMenuScreen implements InputProcessor, Screen, SingleMode musicPath = musicSLK.get(musicPath).getField("FileNames"); } final String[] moreSplitMusics = musicPath.split(","); - final String finalMusicPath = moreSplitMusics[(int) (Math.random() * musics.length)]; + final String finalMusicPath = moreSplitMusics[(int) (Math.random() + * moreSplitMusics.length)]; final Music music = Gdx.audio.newMusic(new DataSourceFileHandle( WarsmashGdxMenuScreen.this.viewer.dataSource, finalMusicPath)); // music.setVolume(0.2f); @@ -266,8 +267,8 @@ public class WarsmashGdxMenuScreen implements InputProcessor, Screen, SingleMode final float yScale = worldHeight / getMinWorldHeight(); final float uiSceneWidth = 0.8f * xScale; final float uiSceneHeight = 0.6f * yScale; - final float uiSceneX = ((0.8f - uiSceneWidth) / 2); - final float uiSceneY = ((0.6f - uiSceneHeight) / 2); + final float uiSceneX = (0.8f - uiSceneWidth) / 2; + final float uiSceneY = (0.6f - uiSceneHeight) / 2; this.uiScene.camera.ortho(uiSceneX, uiSceneWidth + uiSceneX, uiSceneY, uiSceneHeight + uiSceneY, -1024f, 1024); } @@ -399,7 +400,7 @@ public class WarsmashGdxMenuScreen implements InputProcessor, Screen, SingleMode effectInstance.setSequenceLoopMode(SequenceLoopMode.ALWAYS_LOOP); effectInstance.localLocation.x = (float) Math.cos(angle) * 256; effectInstance.localLocation.y = (float) Math.sin(angle) * 256; - effectInstance.localRotation.setFromAxisRad(0, 0, 1, (float) (angle)); + effectInstance.localRotation.setFromAxisRad(0, 0, 1, (float) angle); } final MdxModel mineModel = (MdxModel) this.viewer.load("buildings\\undead\\hauntedmine\\hauntedmine.mdx", @@ -463,7 +464,7 @@ public class WarsmashGdxMenuScreen implements InputProcessor, Screen, SingleMode effectInstance.setSequenceLoopMode(SequenceLoopMode.ALWAYS_LOOP); effectInstance.localLocation.x = (float) Math.cos(angle) * 256; effectInstance.localLocation.y = (float) Math.sin(angle) * 256; - effectInstance.localRotation.setFromAxisRad(0, 0, 1, (float) (angle)); + effectInstance.localRotation.setFromAxisRad(0, 0, 1, (float) angle); } final MdxModel mineModel = (MdxModel) this.viewer.load("units\\orc\\spiritwolf\\spiritwolf.mdx", @@ -502,8 +503,8 @@ public class WarsmashGdxMenuScreen implements InputProcessor, Screen, SingleMode private void makeFourHundred(final Scene scene, final MdxModel model2) { for (int i = 0; i < 400; i++) { final MdxComplexInstance instance3 = (MdxComplexInstance) model2.addInstance(0); - instance3.localLocation.x = (((i % 20) - 10) * 128); - instance3.localLocation.y = (((i / 20) - 10) * 128); + instance3.localLocation.x = ((i % 20) - 10) * 128; + instance3.localLocation.y = ((i / 20) - 10) * 128; instance3.setScene(scene); @@ -518,8 +519,8 @@ public class WarsmashGdxMenuScreen implements InputProcessor, Screen, SingleMode final int n2 = n * n; for (int i = 0; i < n2; i++) { final MdxComplexInstance instance3 = (MdxComplexInstance) model2.addInstance(0); - instance3.localLocation.x = (((i % n) - (n / 2)) * 128); - instance3.localLocation.y = (((i / n) - (n / 2)) * 128); + instance3.localLocation.x = ((i % n) - (n / 2)) * 128; + instance3.localLocation.y = ((i / n) - (n / 2)) * 128; instance3.setScene(scene); diff --git a/core/src/com/etheller/warsmash/parsers/jass/Jass2.java b/core/src/com/etheller/warsmash/parsers/jass/Jass2.java index 2a5f678..e36df66 100644 --- a/core/src/com/etheller/warsmash/parsers/jass/Jass2.java +++ b/core/src/com/etheller/warsmash/parsers/jass/Jass2.java @@ -98,6 +98,7 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayerGame import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayerJass; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayerScore; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayerState; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayerUnitOrderExecutor; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CRace; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CRacePreference; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CStartLocPrio; @@ -132,7 +133,9 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.trigger.enumtypes.C import com.etheller.warsmash.viewer5.handlers.w3x.simulation.trigger.enumtypes.CVersion; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.trigger.enumtypes.CWeaponSoundTypeJass; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.unit.CUnitTypeJass; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.BooleanAbilityActivationReceiver; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.CHashtable; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.util.PointAbilityTargetCheckReceiver; import com.etheller.warsmash.viewer5.handlers.w3x.ui.MeleeUI; public class Jass2 { @@ -1368,11 +1371,11 @@ public class Jass2 { final List group = arguments.get(0).visit(ObjectJassValueVisitor.>getInstance()); final CPlayerJass player = arguments.get(1) .visit(ObjectJassValueVisitor.getInstance()); - final TriggerBooleanExpression filter = arguments.get(2) - .visit(ObjectJassValueVisitor.getInstance()); + final TriggerBooleanExpression filter = nullable(arguments, 2, + ObjectJassValueVisitor.getInstance()); for (final CUnit unit : simulation.getUnits()) { if (unit.getPlayerIndex() == player.getId()) { - if (filter.evaluate(globalScope, + if ((filter == null) || filter.evaluate(globalScope, CommonTriggerExecutionScope.filterScope(triggerScope, unit))) { // TODO the trigger scope for evaluation here might need to be a clean one? group.add(unit); @@ -1382,6 +1385,38 @@ public class Jass2 { return null; } }); + jassProgramVisitor.getJassNativeManager().createNative("IssuePointOrderLoc", new JassFunction() { + @Override + public JassValue call(final List arguments, final GlobalScope globalScope, + final TriggerExecutionScope triggerScope) { + final CUnit whichUnit = arguments.get(0).visit(ObjectJassValueVisitor.getInstance()); + final String orderString = arguments.get(1).visit(StringJassValueVisitor.getInstance()); + final Point2D.Double whichLocation = arguments.get(2) + .visit(ObjectJassValueVisitor.getInstance()); + final CPlayerUnitOrderExecutor defaultPlayerUnitOrderExecutor = simulation + .getDefaultPlayerUnitOrderExecutor(whichUnit.getPlayerIndex()); + final BooleanAbilityActivationReceiver activationReceiver = BooleanAbilityActivationReceiver.INSTANCE; + final int orderId = OrderIdUtils.getOrderId(orderString); + int abilityHandleId = 0; + AbilityPointTarget targetAsPoint = new AbilityPointTarget((float) whichLocation.x, + (float) whichLocation.y); + for (final CAbility ability : whichUnit.getAbilities()) { + ability.checkCanUse(simulation, whichUnit, orderId, activationReceiver); + if (activationReceiver.isOk()) { + final PointAbilityTargetCheckReceiver targetReceiver = PointAbilityTargetCheckReceiver.INSTANCE; + ability.checkCanTarget(simulation, whichUnit, orderId, targetAsPoint, + targetReceiver.reset()); + if (targetReceiver.getTarget() != null) { + targetAsPoint = targetReceiver.getTarget(); + abilityHandleId = ability.getHandleId(); + } + } + } + defaultPlayerUnitOrderExecutor.issuePointOrder(whichUnit.getHandleId(), abilityHandleId, orderId, + targetAsPoint.x, targetAsPoint.y, false); + return BooleanJassValue.of(abilityHandleId != 0); + } + }); jassProgramVisitor.getJassNativeManager().createNative("GroupEnumUnitsOfTypeCounted", new JassFunction() { @Override public JassValue call(final List arguments, final GlobalScope globalScope, @@ -3225,7 +3260,7 @@ public class Jass2 { final int lowBound = arguments.get(0).visit(IntegerJassValueVisitor.getInstance()); final int highBound = arguments.get(1).visit(IntegerJassValueVisitor.getInstance()); return new IntegerJassValue( - (simulation.getSeededRandom().nextInt((highBound - lowBound) + 1)) + lowBound); + simulation.getSeededRandom().nextInt((highBound - lowBound) + 1) + lowBound); } }); jassProgramVisitor.getJassNativeManager().createNative("GetWidgetX", new JassFunction() { diff --git a/core/src/com/etheller/warsmash/util/WarsmashConstants.java b/core/src/com/etheller/warsmash/util/WarsmashConstants.java index 766bd1d..438ed6a 100644 --- a/core/src/com/etheller/warsmash/util/WarsmashConstants.java +++ b/core/src/com/etheller/warsmash/util/WarsmashConstants.java @@ -6,7 +6,7 @@ public class WarsmashConstants { * With version, we use 0 for RoC, 1 for TFT emulation, and probably 2+ or * whatever for custom mods and other stuff */ - public static int GAME_VERSION = 1; + public static int GAME_VERSION = 0; public static final int REPLACEABLE_TEXTURE_LIMIT = 64; public static final float SIMULATION_STEP_TIME = 1 / 20f; public static final int PORT_NUMBER = 6115; @@ -25,7 +25,7 @@ public class WarsmashConstants { // find it yet so I used this public static final String DEFAULT_STRING = "Default string"; - public static final boolean CATCH_CURSOR = false; + public static final boolean CATCH_CURSOR = true; public static final boolean VERBOSE_LOGGING = true; public static final boolean ENABLE_DEBUG = false; public static final char SPECIAL_ESCAPE_KEYCODE = 0x7E; diff --git a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CSimulation.java b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CSimulation.java index f27e09f..0822b08 100644 --- a/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CSimulation.java +++ b/core/src/com/etheller/warsmash/viewer5/handlers/w3x/simulation/CSimulation.java @@ -42,6 +42,7 @@ import com.etheller.warsmash.viewer5.handlers.w3x.simulation.pathing.CPathfindin import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CAllianceType; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayer; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayerJass; +import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CPlayerUnitOrderExecutor; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.players.CRace; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.region.CRegionManager; import com.etheller.warsmash.viewer5.handlers.w3x.simulation.timers.CTimer; @@ -62,6 +63,7 @@ public class CSimulation implements CPlayerAPI { private final List destructables; private final List items; private final List players; + private final List defaultPlayerUnitOrderExecutors; private final List projectiles; private final List newProjectiles; private final HandleIdAllocator handleIdAllocator; @@ -115,6 +117,7 @@ public class CSimulation implements CPlayerAPI { } this.seededRandom = seededRandom; this.players = new ArrayList<>(); + this.defaultPlayerUnitOrderExecutors = new ArrayList<>(); for (int i = 0; i < WarsmashConstants.MAX_PLAYERS; i++) { final CBasePlayer configPlayer = config.getPlayer(i); final War3MapConfigStartLoc startLoc = config.getStartLoc(configPlayer.getStartLocationIndex()); @@ -127,6 +130,7 @@ public class CSimulation implements CPlayerAPI { } } this.players.add(newPlayer); + this.defaultPlayerUnitOrderExecutors.add(new CPlayerUnitOrderExecutor(this, i)); } this.players.get(this.players.size() - 4).setName(miscData.getLocalizedString("WESTRING_PLAYER_NA")); this.players.get(this.players.size() - 3).setName(miscData.getLocalizedString("WESTRING_PLAYER_NV")); @@ -330,14 +334,14 @@ public class CSimulation implements CPlayerAPI { this.daytime = (timeOfDayAfter >= this.gameplayConstants.getDawnTimeGameHours()) && (timeOfDayAfter < this.gameplayConstants.getDuskTimeGameHours()); for (final CTimer timer : this.addedTimers) { - internalRegisterTimer(timer); + this.internalRegisterTimer(timer); } this.addedTimers.clear(); while (!this.activeTimers.isEmpty() && (this.activeTimers.peek().getEngineFireTick() <= this.gameTurnTick)) { this.activeTimers.pop().fire(this); } for (final CTimer timer : this.removedTimers) { - internalUnregisterTimer(timer); + this.internalUnregisterTimer(timer); } this.removedTimers.clear(); for (final TimeOfDayVariableEvent timeOfDayEvent : this.timeOfDayVariableEvents) { @@ -420,6 +424,10 @@ public class CSimulation implements CPlayerAPI { return this.players.get(index); } + public CPlayerUnitOrderExecutor getDefaultPlayerUnitOrderExecutor(final int index) { + return this.defaultPlayerUnitOrderExecutors.get(index); + } + public CommandErrorListener getCommandErrorListener(final int playerIndex) { return this.commandErrorListener; }