From be608b998d10bb07b6230eeb01f9b4e3c1b568b5 Mon Sep 17 00:00:00 2001 From: James Farris Date: Sat, 15 Jul 2023 21:29:11 -0700 Subject: [PATCH] Revert "Develop (#582)" This reverts commit 6166078564ae5b6951a8ad464d47da5095a21519. --- _build/dependencies/WurstCore | 2 +- wurst/Camp/Headquarters.wurst | 110 -------- wurst/Camp/Wisp.wurst | 7 - wurst/Compile/TlsUnitIds.wurst | 8 - .../UndeadTargetingComponent.wurst | 122 +++------ wurst/Debug/DebugCommands.wurst | 25 -- wurst/Game/GameInstance.wurst | 34 +-- wurst/Game/GameSetup.wurst | 3 - wurst/Lootables/Lootables.wurst | 32 --- wurst/Players/HumanPlayerComponent.wurst | 20 +- wurst/Players/PlayerTeam.wurst | 236 ------------------ wurst/Undead/Elites.wurst | 18 +- .../Undead/UndeadTargetServiceDebugger.wurst | 6 +- wurst/World/Bases.wurst | 30 +-- wurst/World/DestructableSpawner.wurst | 28 --- wurst/World/MapEvents.wurst | 179 ++++++++++++- wurst/World/MapEvents/Chickens.wurst | 1 - wurst/World/MapEvents/Frogs.wurst | 1 - wurst/World/MapEvents/RaiderCamp.wurst | 1 - wurst/World/UnitSpawner.wurst | 132 ---------- wurst/World/WorldObject.wurst | 15 -- 21 files changed, 220 insertions(+), 790 deletions(-) delete mode 100644 wurst/Players/PlayerTeam.wurst delete mode 100644 wurst/World/DestructableSpawner.wurst delete mode 100644 wurst/World/UnitSpawner.wurst delete mode 100644 wurst/World/WorldObject.wurst diff --git a/_build/dependencies/WurstCore b/_build/dependencies/WurstCore index 888b41a4..7232902e 160000 --- a/_build/dependencies/WurstCore +++ b/_build/dependencies/WurstCore @@ -1 +1 @@ -Subproject commit 888b41a49d3420cf9142dc1d8fa2380ae81476b5 +Subproject commit 7232902e35e614bf7788ab83532370b4050d9a18 diff --git a/wurst/Camp/Headquarters.wurst b/wurst/Camp/Headquarters.wurst index 2302eea0..49db7f7c 100644 --- a/wurst/Camp/Headquarters.wurst +++ b/wurst/Camp/Headquarters.wurst @@ -15,8 +15,6 @@ import ItemType import ChannelAbilityPreset import GameConstants import Buildings -import Bases -import HumanPlayerComponent import UnitMetadata public TlsBuildingDefinition g_headquarters1Definition @@ -35,80 +33,8 @@ public constant string HEADQUARTERS3_ICON = "ReplaceableTextures\\CommandButtons public constant string HEADQUARTERS4_ICON = "ReplaceableTextures\\CommandButtons\\BTNGenericHumanBuilding.blp" public constant string HEADQUARTERS5_ICON = "ReplaceableTextures\\CommandButtons\\BTNGenericHumanBuilding1.blp" -constant int BASE_ABIL_ID_UNKNOWN = compiletime(ABIL_ID_GEN.next()) -constant int BASE_ABIL_ID_EASY = compiletime(ABIL_ID_GEN.next()) -constant int BASE_ABIL_ID_MEDIUM = compiletime(ABIL_ID_GEN.next()) -constant int BASE_ABIL_ID_HARD = compiletime(ABIL_ID_GEN.next()) - bool g_hasWisp = false -// ============================================================================ -public class HeadquartersComponent extends UnitComponent - - private Base m_base - - // -------------------------------------------------------------------------- - construct (IUnitMetadata owner) - super(owner) - - // -------------------------------------------------------------------------- - function setBase(Base base) - if (m_base != base) - m_base = base - updateBase() - - // -------------------------------------------------------------------------- - function getBase() returns Base - return m_base - - // -------------------------------------------------------------------------- - private function updateBase() - - let ownerUnit = getOwnerUnit() - - let playerComp = ownerUnit.getOwnerHumanPlayerComponent() - if (playerComp != null) - playerComp.setBase(m_base) - - ownerUnit.removeAbility(BASE_ABIL_ID_EASY) - ownerUnit.removeAbility(BASE_ABIL_ID_MEDIUM) - ownerUnit.removeAbility(BASE_ABIL_ID_HARD) - - if (m_base == null) - ownerUnit.addAbility(BASE_ABIL_ID_UNKNOWN) - return - - switch (m_base.getDifficulty()) - case BaseDifficulty.EASY - ownerUnit.addAbility(BASE_ABIL_ID_EASY) - case BaseDifficulty.MEDIUM - ownerUnit.addAbility(BASE_ABIL_ID_MEDIUM) - case BaseDifficulty.HARD - ownerUnit.addAbility(BASE_ABIL_ID_HARD) - default - skip - -// ============================================================================ -public function IUnitMetadata.getHeadquartersComponent() returns HeadquartersComponent - return this.getComponent(HeadquartersComponent.typeId) castTo HeadquartersComponent - -// ============================================================================ -public function IUnitMetadata.getOrAddHeadquartersComponent() returns HeadquartersComponent - var component = this.getHeadquartersComponent() - if (component == null) - component = this.addComponent(new HeadquartersComponent(this)) castTo HeadquartersComponent - return component - -// ============================================================================ -public function unit.getHeadquartersComponent() returns HeadquartersComponent - let metadata = this.getMetadata() - return metadata != null ? metadata.getHeadquartersComponent() : null - -// ============================================================================ -public function unit.getOrAddHeadquartersComponent() returns HeadquartersComponent - let metadata = this.getMetadata() - return metadata != null ? metadata.getOrAddHeadquartersComponent() : null - // ============================================================================ function createBaseHeadquartersDefinition(int newId) returns TlsBuildingDefinition return new TlsBuildingDefinition(newId, UnitIds.townhall) @@ -310,17 +236,6 @@ function onConstructCanceled() // remove so it can't be revived since it's a hero structure.remove() -// ============================================================================ -function onConstructFinished() - let structure = GetTriggerUnit() - if (not structure.isHeadquarters()) - return - - let closestBase = Bases.getClosestBase(structure.getPos()) - let hqComp = structure.getMetadata().getOrAddHeadquartersComponent() - if (hqComp != null) - hqComp.setBase(closestBase) - // ============================================================================ function onUpgradeFinished() let structure = GetTriggerUnit() @@ -451,30 +366,6 @@ function onSpellCast() createHeadquartersItemBuildUnit(TlsUnitIds.BuildItemUnits.headquarters2, g_headquarters2ItemDefinition) createHeadquartersItemBuildUnit(TlsUnitIds.BuildItemUnits.headquarters3, g_headquarters3ItemDefinition) - new AbilityDefinition(BASE_ABIL_ID_EASY, 'Ahan') - ..presetTooltipNormal(lvl -> "Easy Base") - ..presetTooltipNormalExtended(lvl -> "You've built your Headquarters in an Easy base.|n|n+1x score multiplier|") - ..setButtonPositionNormalX(3) - ..setButtonPositionNormalY(1) - - new AbilityDefinition(BASE_ABIL_ID_MEDIUM, 'Ahan') - ..presetTooltipNormal(lvl -> "Medium Base") - ..presetTooltipNormalExtended(lvl -> "You've built your Headquarters in an Medium base.|n|n+2x score multiplier") - ..setButtonPositionNormalX(3) - ..setButtonPositionNormalY(1) - - new AbilityDefinition(BASE_ABIL_ID_HARD, 'Ahan') - ..presetTooltipNormal(lvl -> "Hard Base") - ..presetTooltipNormalExtended(lvl -> "You've built your Headquarters in an Hard base.|n|n+3x score multiplier") - ..setButtonPositionNormalX(3) - ..setButtonPositionNormalY(1) - - new AbilityDefinition(BASE_ABIL_ID_UNKNOWN, 'Ahan') - ..presetTooltipNormal(lvl -> "Wild Base") - ..presetTooltipNormalExtended(lvl -> "I have no idea where you built your Headquarters.") - ..setButtonPositionNormalX(3) - ..setButtonPositionNormalY(1) - // ============================================================================ init if (g_headquarters1Definition == null) @@ -487,6 +378,5 @@ init registerPlayerUnitEvent(EVENT_PLAYER_UNIT_TRAIN_FINISH, function onUnitTrained) registerPlayerUnitEvent(EVENT_PLAYER_UNIT_CONSTRUCT_START, function onConstructStarted) registerPlayerUnitEvent(EVENT_PLAYER_UNIT_CONSTRUCT_CANCEL, function onConstructCanceled) - registerPlayerUnitEvent(EVENT_PLAYER_UNIT_CONSTRUCT_FINISH, function onConstructFinished) registerPlayerUnitEvent(EVENT_PLAYER_UNIT_UPGRADE_FINISH, function onUpgradeFinished) registerPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST, function onSpellCast) \ No newline at end of file diff --git a/wurst/Camp/Wisp.wurst b/wurst/Camp/Wisp.wurst index 690cde4e..18728754 100644 --- a/wurst/Camp/Wisp.wurst +++ b/wurst/Camp/Wisp.wurst @@ -14,7 +14,6 @@ import StringBuilder import ColorUtility import Icons import TlsUpgradeDefinition -import TlsMMD // ============================================================================ @compiletime function createObjectDefinitions() @@ -295,20 +294,16 @@ function onSpellCast() let abilityId = GetSpellAbilityId() int heroTypeId - string heroId switch (abilityId) case TlsAbilityIds.selectHero_scout heroTypeId = TlsUnitIds.heroScout - heroId = "Scout" case TlsAbilityIds.selectHero_soldier heroTypeId = TlsUnitIds.heroCaptain - heroId = "Captain" case TlsAbilityIds.selectHero_tinkerer heroTypeId = TlsUnitIds.heroTinker - heroId = "Tinker" default return @@ -320,8 +315,6 @@ function onSpellCast() castingUnit.remove() - TlsMMD.setHeroSelected(castingPlayer, heroId) - // ============================================================================ init diff --git a/wurst/Compile/TlsUnitIds.wurst b/wurst/Compile/TlsUnitIds.wurst index 780aa9bb..dc5f8e42 100644 --- a/wurst/Compile/TlsUnitIds.wurst +++ b/wurst/Compile/TlsUnitIds.wurst @@ -35,14 +35,6 @@ public class TlsUnitIds static constant int headquarters4 = compiletime(UNIT_ID_GEN.next()) static constant int headquarters5 = compiletime(UNIT_ID_GEN.next()) - static constant int array headquarters = [ - headquarters1, - headquarters2, - headquarters3, - headquarters4, - headquarters5 - ] - static constant int shelter1 = compiletime(UNIT_ID_GEN.next()) static constant int shelter2 = compiletime(UNIT_ID_GEN.next()) static constant int shelter3 = compiletime(UNIT_ID_GEN.next()) diff --git a/wurst/Composition/UndeadTargetingComponent.wurst b/wurst/Composition/UndeadTargetingComponent.wurst index 3c02a3b2..53248530 100644 --- a/wurst/Composition/UndeadTargetingComponent.wurst +++ b/wurst/Composition/UndeadTargetingComponent.wurst @@ -21,8 +21,6 @@ import GroupUtils import TlsUnitIds import HumanPlayerComponent import HashList -import HashMap -import PlayerTeam public bool UTC_ENABLED = true @@ -44,7 +42,6 @@ constant real UPDATE_INTERVAL = 0.2 public group g_dealDOTGroup = CreateGroup() public group g_awaitingOrderGroup = CreateGroup() CallbackPeriodic g_issueOrderTimer -int g_utpId = 1 /* @@ -668,8 +665,6 @@ public function UndeadTargetProviderPriority.toString() returns string return "unknown" UndeadTargetProvider array g_playerData -HashMap g_utpByTeam = new HashMap() -LinkedList g_undeadTargetProviders = new LinkedList() int g_playerDataUpdateIndex = -1 group array g_targetedUnitToUTCMap // int array g_targetUnitScore @@ -694,27 +689,16 @@ public function getNumberOfRegisteredAttackers(unit target) returns int // ============================================================================ public class UndeadTargetProvider extends TargetProvider - private int m_id - private PlayerTeam m_playerTeam = null private force m_players = CreateForce() private group m_structureTargets = CreateGroup() private group m_organicTargets = CreateGroup() private group array[UNDEAD_TARGET_PROVIDER_PRI_COUNT] m_targetsByPriority private bool m_preferOrganicTargets = false private Event m_preferOrganicTargetsChanged = null + private _handle array[24] m_hpcPropertyChangedEventHandlers // -------------------------------------------------------------------------- - construct(PlayerTeam playerTeam) - - m_playerTeam = playerTeam - - m_id = g_utpId - g_utpId++ - - Log.info("Created UTP {0}".format(m_id.toString())) - - g_undeadTargetProviders.add(this) - + construct() registerHumanForceTargetCollection(this) for i = 0 to UNDEAD_TARGET_PROVIDER_PRI_COUNT - 1 @@ -722,10 +706,17 @@ public class UndeadTargetProvider extends TargetProvider // -------------------------------------------------------------------------- ondestroy - g_undeadTargetProviders.remove(this) - unregisterHumanForceTargetCollection(this) + for i = 0 to 23 + //{ + if (m_hpcPropertyChangedEventHandlers[i] != INVALID_HANDLE) + players[i].getHumanPlayerComponent() + .onPropertyChanged() + .unregister(m_hpcPropertyChangedEventHandlers[i]) + m_hpcPropertyChangedEventHandlers[i] = INVALID_HANDLE + //} + if (m_preferOrganicTargetsChanged != null) destroy m_preferOrganicTargetsChanged m_preferOrganicTargetsChanged = null @@ -738,20 +729,14 @@ public class UndeadTargetProvider extends TargetProvider m_targetsByPriority[i].destr() m_targetsByPriority[i] = null - Log.info("Destroyed UTP {0}".format(m_id.toString())) - - // -------------------------------------------------------------------------- - function getId() returns int - return m_id - // -------------------------------------------------------------------------- function addPlayer(player p) m_players.addPlayer(p) g_playerData[p.getId()] = this - Log.info("Added player {0} to UTP {1}".format(p.getName(), m_id.toString())) - - updatePreferOrganicTargets() + m_hpcPropertyChangedEventHandlers[p.getId()] = p.getHumanPlayerComponent() + .onPropertyChanged() + .register((HumanPlayerComponent sender, string propertyName) -> onHumanPlayerComponentPropertyChanged(sender, propertyName)) addPlayerUnitsToGroups(p) @@ -760,15 +745,25 @@ public class UndeadTargetProvider extends TargetProvider m_players.removePlayer(p) g_playerData[p.getId()] = null - Log.info("Removed player {0} from UTP {1}".format(p.getName(), m_id.toString())) - - updatePreferOrganicTargets() - removePlayerUnitsFromGroups(p) + if (m_hpcPropertyChangedEventHandlers[p.getId()] != INVALID_HANDLE) + p.getHumanPlayerComponent() + .onPropertyChanged() + .unregister(m_hpcPropertyChangedEventHandlers[p.getId()]) + m_hpcPropertyChangedEventHandlers[p.getId()] = INVALID_HANDLE + if (m_players.count() == 0) release() + // ---------------------------------------------------------------------------- + function onHumanPlayerComponentPropertyChanged(HumanPlayerComponent sender, string propertyName) + + if (propertyName == HumanPlayerComponent.Properties.canPathToHeadquartersOrHero) + let uts = getUndeadTargetProviderForPlayer(sender.getOwnerPlayer()) + if (uts != null) + uts.setPreferOrganicTargets(sender.getCanPathToHeadquartersOrHero()) + // -------------------------------------------------------------------------- function getPlayers() returns force return m_players @@ -968,14 +963,6 @@ public class UndeadTargetProvider extends TargetProvider private function getBUTAttacksEnabled() returns bool return not m_preferOrganicTargets - // -------------------------------------------------------------------------- - protected function updatePreferOrganicTargets() - var preferOrganicTargets = false - for p in m_players - let comp = p.getMetadata().getHumanPlayerComponent() - preferOrganicTargets = preferOrganicTargets or comp.getCanPathToHeadquartersOrHero() - setPreferOrganicTargets(preferOrganicTargets) - // -------------------------------------------------------------------------- // private function enumNearbyStructures(vec2 pos) // g_targetUnitScoreFilterGroup = m_structureTargets @@ -1085,27 +1072,22 @@ function unregisterHumanForceTargetCollection(UndeadTargetProvider value) g_processUpdates = null // ============================================================================ -function getPlayerUTP(player p) returns UndeadTargetProvider +function getPlayerData(player p) returns UndeadTargetProvider return g_playerData[p.getId()] // ============================================================================ -function getTeamUTP(PlayerTeam team) returns UndeadTargetProvider - return g_utpByTeam.get(team) - -// ============================================================================ -function getOrCreateUTPForTeam(PlayerTeam team) returns UndeadTargetProvider - var utp = getTeamUTP(team) - if (utp == null) - utp = new UndeadTargetProvider(team)..acquire() - utp.addPlayer(p) - g_utpByTeam.put(team, utp) - return utp +function getOrCreatePlayerData(player p) returns UndeadTargetProvider + var data = getPlayerData(p) + if (data == null) + data = new UndeadTargetProvider()..acquire() + data.addPlayer(p) + return data // ============================================================================ function onUnitDeindexed() let indexingUnit = getIndexingUnit() let owningPlayer = indexingUnit.getOwner() - let playerData = getPlayerUTP(owningPlayer) + let playerData = getPlayerData(owningPlayer) if (playerData != null) playerData.unregisterPlayerUnit(indexingUnit) @@ -1113,14 +1095,6 @@ function onUnitDeindexed() function onPlayerLeave() clearLeavingLosingPlayerData(GetTriggerPlayer()) -// ============================================================================ -function onHumanPlayerComponentPropertyChanged(HumanPlayerComponent sender, string propertyName) - - if (propertyName == HumanPlayerComponent.Properties.canPathToHeadquartersOrHero) - let utp = getUndeadTargetProviderForPlayer(sender.getOwnerPlayer()) - if (utp != null) - utp.updatePreferOrganicTargets() - // ============================================================================ init @@ -1135,29 +1109,7 @@ init registerPlayerEvent(EVENT_PLAYER_LEAVE, function onPlayerLeave) for p in g_PlayingHumanPlayers - //{ - // Listen for changes to the - let comp = p.getMetadata().getHumanPlayerComponent() - if (comp != null) - comp.onPropertyChanged().register((s,a) -> onHumanPlayerComponentPropertyChanged(s,a)) - //} - - // Create an initial UTP for each team - for team in PlayerTeam.getTeams() - let utp = getOrCreateUTPForTeam(team) - if (utp != null) - for p in team.getPlayers() - utp.addPlayer(p) - - PlayerTeam.onTeamPlayerAdded().register() (PlayerTeam team, player p) -> - let utp = getOrCreateUTPForTeam(team) - if (utp != null) - utp.addPlayer(p) - - PlayerTeam.onTeamPlayerRemoved().register() (PlayerTeam team, player p) -> - let utp = getTeamUTP(team) - if (utp != null) - utp.removePlayer(p) + getOrCreatePlayerData(p) g_targetPriNone.add(TlsUnitIds.campFire) g_targetPriNone.add(TlsUnitIds.campFire2) diff --git a/wurst/Debug/DebugCommands.wurst b/wurst/Debug/DebugCommands.wurst index 4fcdca36..b10eada3 100644 --- a/wurst/Debug/DebugCommands.wurst +++ b/wurst/Debug/DebugCommands.wurst @@ -46,7 +46,6 @@ import MapEvents import Transform import Reflection import PlayerSpawnPointProviders -import PlayerStats constant string COMMAND_GODLIKE = "godlike" constant string COMMAND_DAY = "day" @@ -111,7 +110,6 @@ constant string COMMAND_DESTROY_LAST_MAP_EVENT_TEMPLATE = "destroyMET" constant string COMMAND_SPAWN_MAP_EVENT = "spawnME" constant string COMMAND_DESTROY_LAST_MAP_EVENT = "destroyME" constant string COMMAND_TYPENAME = "typename" -constant string COMMAND_PLAYERSTATS = "playerstats" constant string COMMAND_UTC = "utc" constant string COMMAND_UTS = "uts" @@ -1604,26 +1602,6 @@ function typename() chatCommandPrintToPlayer(commandPlayer, "{0} ({1])".format(typeIdToTypeName(id), id.toString())) -// ============================================================================ -function showPlayerStats() - let command = getChatCommand() - let commandPlayer = getChatCommandPlayer() - let player_id = command.getArgument(0).getInt() - - if (player_id < 0 or player_id >= 28) - chatCommandPrintToPlayer(commandPlayer, "Invalid player index: " + player_id.toString()) - return - - let p = players[player_id] - let playerStatsComp = p.getMetadata().getPlayerStatsComponent() - if (playerStatsComp == null) - chatCommandPrintToPlayer(commandPlayer, "Player {0} does not have stats".format(player_id.toString())) - return - - let stats = playerStatsComp.getGameStats() - stats.dump() (string text) -> - chatCommandPrintToPlayer(commandPlayer, text) - // ============================================================================ function registerDebugCommands1() @@ -1883,9 +1861,6 @@ function registerDebugCommands2() g_commandHandler.registerCommandDefinition(COMMAND_TYPENAME, function typename) ..addIntegerArgument("TYPESID", false) - g_commandHandler.registerCommandDefinition(COMMAND_PLAYERSTATS, function showPlayerStats) - ..addIntegerArgument("PLAYERID", false) - // ============================================================================ init diff --git a/wurst/Game/GameInstance.wurst b/wurst/Game/GameInstance.wurst index 368412d7..8c4d7e1a 100644 --- a/wurst/Game/GameInstance.wurst +++ b/wurst/Game/GameInstance.wurst @@ -26,7 +26,6 @@ import PlayerSetup import ItemType import PlayerSpawnPointProviders import Difficulties -import Events public GameInstance g_GameInstance = new GameInstance() @@ -42,21 +41,10 @@ public class GameInstance private bool m_hasStarted = false private bool m_spawnPedestals = false - private Event m_gameStarted - private Event m_gameFinished - // -------------------------------------------------------------------------- ondestroy destroy m_weatherPlayer - if (m_gameStarted != null) - destroy m_gameStarted - m_gameStarted = null - - if (m_gameFinished != null) - destroy m_gameFinished - m_gameFinished = null - // -------------------------------------------------------------------------- function now() returns time let tod = GetTimeOfDay() @@ -242,9 +230,6 @@ public class GameInstance for p in g_PlayingHumanPlayers initializePlayer(p) - if (m_gameStarted != null) - m_gameStarted.call() - // -------------------------------------------------------------------------- private function initializePlayer(player p) @@ -307,32 +292,15 @@ public class GameInstance doAfter(30.0) () -> for p in g_PlayingHumanPlayers //{ - let pmet = p.getMetadata() - - if (not pmet.getHasLostGame()) - pmet.setVictoryState(VictoryState.Won) - PlayerSaveData.save(p, true) let d = DialogCreate() - d.setMessage(pmet.getHasLostGame() ? "You lose. Better luck next time!" : "You win!") + d.setMessage(p.getMetadata().getHasLostGame() ? "You lose. Better luck next time!" : "You win!") d.addButton("OK") d.display(p, true) //} //} - // -------------------------------------------------------------------------- - function onGameStarted() returns IEvent - if (m_gameStarted == null) - m_gameStarted = new Event() - return m_gameStarted - - // -------------------------------------------------------------------------- - function onGameFinished() returns IEvent - if (m_gameFinished == null) - m_gameFinished = new Event() - return m_gameFinished - // -------------------------------------------------------------------------- function startNight() diff --git a/wurst/Game/GameSetup.wurst b/wurst/Game/GameSetup.wurst index 23de0bbd..7f866931 100644 --- a/wurst/Game/GameSetup.wurst +++ b/wurst/Game/GameSetup.wurst @@ -20,7 +20,6 @@ import PlayerExtensions import ProgressBarUtils import RegisterEvents import TLSMenuBar -import TlsMMD constant real GAME_SETUP_DURATION = 60.0 @@ -254,8 +253,6 @@ public class GameSetup PlayerSaveData.save(_player, false) //} - - TlsMMD.setGameDifficulty(_player, DIFFICULTY_NAMES[setup.getDifficulty().floor()]) //} // Show menu bar for players now that everything is loaded diff --git a/wurst/Lootables/Lootables.wurst b/wurst/Lootables/Lootables.wurst index 0a64f7bf..eaeb3d51 100644 --- a/wurst/Lootables/Lootables.wurst +++ b/wurst/Lootables/Lootables.wurst @@ -35,7 +35,6 @@ import Interaction import PlayerProperties import HeroExperienceComponent import TlsItemIds -import Events // Buildings public constant int UNIT_ID_LOOTABLE_BARN = 'h01H' @@ -128,28 +127,6 @@ SoundDefinition g_lootItemRewardSound CardInstanceComparator g_cardInstanceComparator = new CardInstanceComparator() -// ============================================================================ -public class LootAwardedArgs - unit lootingUnit = null - unit lootableUnit = null - CardInstance lootReward = null - -// ============================================================================ -public abstract class Lootables - - private static Event1 g_lootAwardedEvent = null - - // ============================================================================ - static function onLootAwarded() returns IEvent1 - if (g_lootAwardedEvent == null) - g_lootAwardedEvent = new Event1() - return g_lootAwardedEvent - - // ============================================================================ - protected static function raiseLootAwarded(LootAwardedArgs args) - if (g_lootAwardedEvent != null) - g_lootAwardedEvent.call(args) - // ============================================================================ public abstract class LootCard extends TieredCard @@ -706,15 +683,6 @@ public class LootableComponent extends UnitComponent if (xpComp != null and lootXpProp != null) xpComp.addXp(lootXpProp.getValue(), false) - let args = new LootAwardedArgs() - args.lootingUnit = lootingUnit - args.lootableUnit = getOwnerUnit() - args.lootReward = lootCardInstance - - Lootables.raiseLootAwarded(args) - - destroy args - destroy lootCardInstance doAfter(0.5) -> diff --git a/wurst/Players/HumanPlayerComponent.wurst b/wurst/Players/HumanPlayerComponent.wurst index 9ba5b2d4..fafa6276 100644 --- a/wurst/Players/HumanPlayerComponent.wurst +++ b/wurst/Players/HumanPlayerComponent.wurst @@ -14,7 +14,6 @@ import Observable import ClosureTimers import PlayerProperties import GroupExtensions -import Bases boolexpr g_isFilterUnitAliveHeadquartersCondition = Condition(function isFilterUnitAliveHeadquarters) group g_tempGroup = getGroup() @@ -32,14 +31,11 @@ public class HumanPlayerComponent extends PlayerComponent private real m_totalTierWeight = 0 private real m_cameraDistance = CAMERA_DISTANCE_DEFAULT private UnitMetadata m_heroMetadata - private Base m_base use Observable // -------------------------------------------------------------------------- public static class Properties - static constant string base = "base" - static constant string score = "score" static constant string cameraDistance = "cameraDistance" static constant string canPathToHeadquartersOrHero = "canPathToHeadquartersOrHero" @@ -74,10 +70,8 @@ public class HumanPlayerComponent extends PlayerComponent return m_score // -------------------------------------------------------------------------- - function setScore(int value) - if (m_score != value) - m_score = value - raisePropertyChangedEvent(Properties.score) + function incrementScore(int value) + m_score += value // -------------------------------------------------------------------------- function getCanPathToHeadquartersOrHero() returns bool @@ -199,16 +193,6 @@ public class HumanPlayerComponent extends PlayerComponent m_cameraDistance = clampedValue updateCamera() raisePropertyChangedEvent(Properties.cameraDistance) - - // -------------------------------------------------------------------------- - function setBase(Base base) - if (m_base != base) - m_base = base - raisePropertyChangedEvent(Properties.base) - - // -------------------------------------------------------------------------- - function getBase() returns Base - return m_base // -------------------------------------------------------------------------- function load() diff --git a/wurst/Players/PlayerTeam.wurst b/wurst/Players/PlayerTeam.wurst deleted file mode 100644 index 848fedde..00000000 --- a/wurst/Players/PlayerTeam.wurst +++ /dev/null @@ -1,236 +0,0 @@ -package PlayerTeam -import Bases -import HumanPlayers -import HumanPlayerComponent -import RefObject -import Observable -import Events -import LinkedList -import ProjectConstants -import DebuggerDialog -import Host -import PlayerExtensions -import GameConstants -import HashMap -import RegisterEvents - -PlayerTeam array g_playerTeamsByPlayerId -LinkedList g_playerTeams = new LinkedList() -HashMap g_playerTeamsByBase = new HashMap() -int g_teamId = 1 - -// ============================================================================ -public class PlayerTeam - - static private Event2 s_teamPlayerAdded - static private Event2 s_teamPlayerRemoved - - private int m_id = 0 - private Base m_base = null - private force m_players = CreateForce() - - use RefObject - use Observable - - // -------------------------------------------------------------------------- - public static class Properties - static constant string preferOrganicTargets = "preferOrganicTargets" - - // -------------------------------------------------------------------------- - construct(Base _base) - - m_base = _base - - if (m_base != null) - g_playerTeamsByBase.put(m_base, this) - - m_id = g_teamId - g_teamId++ - - Log.info("Created team {0}".format(m_id.toString())) - - g_playerTeams.add(this) - - // -------------------------------------------------------------------------- - ondestroy - g_playerTeams.remove(this) - - if (m_base != null and g_playerTeamsByBase.get(m_base) == this) - g_playerTeamsByBase.remove(m_base) - - m_players.destr() - m_players = null - - Log.info("Destroyed team {0}".format(m_id.toString())) - - // -------------------------------------------------------------------------- - static function getTeams() returns LinkedList - return g_playerTeams - - // -------------------------------------------------------------------------- - static function getPlayerTeam(player p) returns PlayerTeam - return g_playerTeamsByPlayerId[p.getId()] - - // -------------------------------------------------------------------------- - static function getPlayerTeam(Base b) returns PlayerTeam - return g_playerTeamsByBase.get(b) - - // -------------------------------------------------------------------------- - static function getOrCreatePlayerTeam(player p) returns PlayerTeam - var team = getPlayerTeam(p) - if (team == null) - team = new PlayerTeam(null)..acquire() - Log.info("Created new player team {0} for {1}".format(team.getId().toString(), p.getName())) - return team - - // -------------------------------------------------------------------------- - static function getOrCreatePlayerTeam(Base b) returns PlayerTeam - var team = getPlayerTeam(b) - if (team == null) - team = new PlayerTeam(b)..acquire() - Log.info("Created new base team {0} for {1}".format(team.getId().toString(), b.getId())) - return team - - // -------------------------------------------------------------------------- - static function onTeamPlayerAdded() returns IEvent2 - if (s_teamPlayerAdded == null) - s_teamPlayerAdded = new Event2() - return s_teamPlayerAdded - - // -------------------------------------------------------------------------- - static function onTeamPlayerRemoved() returns IEvent2 - if (s_teamPlayerRemoved == null) - s_teamPlayerRemoved = new Event2() - return s_teamPlayerRemoved - - // -------------------------------------------------------------------------- - function getId() returns int - return m_id - - // -------------------------------------------------------------------------- - function getPlayers() returns force - return m_players - - // -------------------------------------------------------------------------- - function getBase() returns Base - return m_base - - // -------------------------------------------------------------------------- - function addPlayer(player p) - m_players.addPlayer(p) - g_playerTeamsByPlayerId[p.getId()] = this - - Log.info("Added player {0} to base team {1}".format(p.getName(), m_id.toString())) - - if (s_teamPlayerAdded != null) - s_teamPlayerAdded.call(this, p) - - // -------------------------------------------------------------------------- - function removePlayer(player p) - m_players.removePlayer(p) - - Log.info("Removed player {0} from team {1}".format(p.getName(), m_id.toString())) - - if (g_playerTeamsByPlayerId[p.getId()] == this) - g_playerTeamsByPlayerId[p.getId()] = null - - if (s_teamPlayerRemoved != null) - s_teamPlayerRemoved.call(this, p) - - if (m_players.count() == 0) - release() - return - -// ============================================================================ -class PlayerTeamDebugger extends DebuggerRealtimeUpdateFrame - - // -------------------------------------------------------------------------- - construct() - super(createFrame("TEXTAREA", "TEAM", GAME_UI, "", 0)) - - // -------------------------------------------------------------------------- - override function realtimeUpdate(real _) - - let frameHandle = getFrameHandle() - - let selectedUnit = g_HostPlayer.getFirstSelectedUnit() - - if (selectedUnit == null) - BlzFrameSetText(frameHandle, "Select a unit") - return - - let selectedPlayer = selectedUnit.getOwner() - - let team = PlayerTeam.getPlayerTeam(selectedPlayer) - if (team == null) - BlzFrameSetText(frameHandle, "No player team found for " + selectedPlayer.getName()) - return - - BlzFrameSetText(frameHandle, "===== Team: {0} =====".format(team.getId().toString())) - - let b = team.getBase() - if (b != null) - let baseName = b.getName() - BlzFrameAddText(frameHandle, "Base: {0} ({1})".format( - (baseName.isNotBlank() ? baseName : b.getId()), - b.getDifficulty().toString())) - else - BlzFrameAddText(frameHandle, "No base") - - BlzFrameAddText(frameHandle, "Players: ") - - for p in team.getPlayers() - let comp = p.getMetadata().getHumanPlayerComponent() - BlzFrameAddText(frameHandle, " ยท {0} ({1})".format(p.getName(), DIFFICULTY_NAMES[comp.getDifficulty().floor()])) - -// ============================================================================ -function onHumanPlayerComponentPropertyChanged(HumanPlayerComponent sender, string propertyName) - - if (propertyName == HumanPlayerComponent.Properties.base) - //{ - let p = sender.getOwnerPlayer() - let prevTeam = PlayerTeam.getPlayerTeam(p) - PlayerTeam nextTeam = null - - let b = sender.getBase() - if (b != null) - nextTeam = PlayerTeam.getOrCreatePlayerTeam(b) - - if (nextTeam == null) - nextTeam = PlayerTeam.getOrCreatePlayerTeam(p) - - if (nextTeam != prevTeam) - //{ - if (prevTeam != null) - prevTeam.removePlayer(p) - - if (nextTeam != null) - nextTeam.addPlayer(p) - //} - //} - -// ============================================================================ -function onPlayerLeave() - let p = GetTriggerPlayer() - let team = PlayerTeam.getPlayerTeam(p) - if (team != null) - team.removePlayer(p) - -// ============================================================================ -init - - if (DEV_ENVIRONMENT) - DebuggerDialog.registerFrame("TEAM", () -> new PlayerTeamDebugger()) - - registerPlayerEvent(EVENT_PLAYER_LEAVE, function onPlayerLeave) - - for p in g_PlayingHumanPlayers - //{ - // Everyone starts in their own team - PlayerTeam.getOrCreatePlayerTeam(p)..addPlayer(p) - - // Listen for changes to the base property to move players to different teams - let comp = p.getMetadata().getOrAddHumanPlayerComponent() - comp.onPropertyChanged().register() (HumanPlayerComponent sender, string propertyName) -> - onHumanPlayerComponentPropertyChanged(sender, propertyName) - //} \ No newline at end of file diff --git a/wurst/Undead/Elites.wurst b/wurst/Undead/Elites.wurst index d3a65d58..e9f7ce43 100644 --- a/wurst/Undead/Elites.wurst +++ b/wurst/Undead/Elites.wurst @@ -15,19 +15,10 @@ public constant color TIER1_COLOR = color(255,255,255) public constant color TIER2_COLOR = color(53, 53, 255) public constant color TIER3_COLOR = color(255, 255, 0) -HashList g_normalUnitTypes = new HashList() HashList g_eliteUnitTypes = new HashList() HashList g_bossUnitTypes = new HashList() HashList array g_tieredUnitTypes = [new HashList(),new HashList(),new HashList()] -// ============================================================================ -public function unit.isNormal() returns bool - return this.getTypeId().isNormalUnitTypeId() - -// ============================================================================ -public function int.isNormalUnitTypeId() returns bool - return g_normalUnitTypes.has(this) - // ============================================================================ public function unit.isElite() returns bool return this.getTypeId().isEliteUnitTypeId() @@ -82,11 +73,6 @@ public function getTierColor(int tier) returns color public function registerTieredUnitType(int unitTypeId, int tier) g_tieredUnitTypes[tier].add(unitTypeId) -// ============================================================================ -public function registerNormalType(int unitTypeId, int tier) - g_normalUnitTypes.add(unitTypeId) - registerTieredUnitType(unitTypeId, tier) - // ============================================================================ public function registerEliteType(int unitTypeId, int tier) g_eliteUnitTypes.add(unitTypeId) @@ -103,8 +89,8 @@ init for i = 0 to MAX_ELITE_TIER-1 //{ // Zombies - registerNormalType(TlsUnitIds.Undead.zombiesDay[i], i) - registerNormalType(TlsUnitIds.Undead.zombiesNight[i], i) + registerTieredUnitType(TlsUnitIds.Undead.zombiesDay[i], i) + registerTieredUnitType(TlsUnitIds.Undead.zombiesNight[i], i) // Elites registerEliteType(TlsUnitIds.Undead.skeletonArchers[i], i) diff --git a/wurst/Undead/UndeadTargetServiceDebugger.wurst b/wurst/Undead/UndeadTargetServiceDebugger.wurst index 0e2946cb..b93cef48 100644 --- a/wurst/Undead/UndeadTargetServiceDebugger.wurst +++ b/wurst/Undead/UndeadTargetServiceDebugger.wurst @@ -26,12 +26,12 @@ class UndeadTargetServiceDebugger extends DebuggerRealtimeUpdateFrame let selectedPlayer = selectedUnit.getOwner() + BlzFrameSetText(frameHandle, "===== Undead Target Service: {0} =====".format(selectedPlayer.getName())) + let provider = getUndeadTargetProviderForPlayer(selectedPlayer) if (provider == null) - BlzFrameSetText(frameHandle, "No provider found for " + selectedPlayer.getName()) + BlzFrameAddText(frameHandle, "No provider found") return - - BlzFrameSetText(frameHandle, "===== Undead Target Service: {0} =====".format(provider.getId().toString())) var playersStr = "" for p in provider.getPlayers() diff --git a/wurst/World/Bases.wurst b/wurst/World/Bases.wurst index ba437a5e..bbb25ad7 100644 --- a/wurst/World/Bases.wurst +++ b/wurst/World/Bases.wurst @@ -7,12 +7,12 @@ import Optional import Vector import Transform import Quaternion +import MapEvents import Preload -import Spawning -import HumanPlayers -import UnitSpawner import initlater BasesInit +import Spawning +import HumanPlayers constant color BASE_EASY_COLOR = color(0, 255, 0) constant color BASE_MEDIUM_COLOR = color(255, 255, 0) @@ -50,18 +50,6 @@ public enum BaseDifficulty HARD ALL -// ============================================================================ -public function BaseDifficulty.toString() returns string - switch (this) - case EASY - return "Easy" - case MEDIUM - return "Medium" - case HARD - return "Hard" - case ALL - return "ALL" - // ============================================================================ public class Base protected Transform m_transform = new Transform() @@ -224,18 +212,6 @@ public abstract class Bases return _base - // -------------------------------------------------------------------------- - static function getClosestBase(vec2 pos) returns Base - Base result = null - real closestDD = REAL_MAX - for b in g_bases - let worldPos = b.getTransform().getWorldPosition() - let dd = worldPos.toVec2().distanceToSq(pos) - if (dd < closestDD) - closestDD = b.m_dd - result = b - return result - // -------------------------------------------------------------------------- /** Gets the base closest to any invalidating units */ static function getClosestSpawnPoint() returns optionalVec2 diff --git a/wurst/World/DestructableSpawner.wurst b/wurst/World/DestructableSpawner.wurst deleted file mode 100644 index 87e5190d..00000000 --- a/wurst/World/DestructableSpawner.wurst +++ /dev/null @@ -1,28 +0,0 @@ -package DestructableSpawner -import WorldObject -import Transform - -// ============================================================================ -public class DestructableSpawner extends WorldObject - private int m_destructableTypeId - private int m_variation - - // -------------------------------------------------------------------------- - construct(int destructableTypeId, int variation) - m_destructableTypeId = destructableTypeId - m_variation = variation - - // -------------------------------------------------------------------------- - function getDestructableTypeId() returns int - return m_destructableTypeId - - // -------------------------------------------------------------------------- - function getVariation() returns int - return m_variation - - // -------------------------------------------------------------------------- - function spawn(Transform parentTransform) returns destructable - m_transform.setParent(parentTransform) - let spawnedDest = createDestructable(m_destructableTypeId, m_variation, m_transform) - m_transform.setParent(null) - return spawnedDest diff --git a/wurst/World/MapEvents.wurst b/wurst/World/MapEvents.wurst index 6b7705ea..eeb7af22 100644 --- a/wurst/World/MapEvents.wurst +++ b/wurst/World/MapEvents.wurst @@ -13,15 +13,15 @@ import TlsMapEventIds import Runnable import Func import Jobs +import UnitRecycler +import UnitExtensions import ErrorHandling +import Bounds import CancellationToken import ObjectIds import DestructableUtility import Events import Lootables -import WorldObject -import UnitSpawner -import DestructableSpawner import initlater MapEventsInit @@ -686,6 +686,174 @@ public class MapEventInstance extends WorldObject private function createJobId(string id) returns string return "{0}:{1}:{2}".format(m_template.getId(), m_instanceId.toString(), id) +// ============================================================================ +public abstract class WorldObject + protected Transform m_transform = new Transform() + + // ---------------------------------------------------------------------------- + ondestroy + destroy m_transform + m_transform = null + + // -------------------------------------------------------------------------- + function getTransform() returns Transform + return m_transform + +// ============================================================================ +public class UnitSpawner extends WorldObject + private int m_unitTypeId + private real m_fadeInDuration + private real m_fadeOutDuration + private int m_fadeOutMove + private vec2 m_fadeOutMoveToPos + private bool m_useRecycler + private int m_userData + + // -------------------------------------------------------------------------- + construct(int unitTypeId) + m_unitTypeId = unitTypeId + + // -------------------------------------------------------------------------- + function getUserData() returns int + return m_userData + + // -------------------------------------------------------------------------- + function setUserData(int value) + m_userData = value + + // -------------------------------------------------------------------------- + function getFadeInDuration() returns real + return m_fadeInDuration + + // -------------------------------------------------------------------------- + function setFadeInDuration(real value) + m_fadeInDuration = value + + // -------------------------------------------------------------------------- + function getFadeOutDuration() returns real + return m_fadeOutDuration + + // -------------------------------------------------------------------------- + function setFadeOutDuration(real value) + m_fadeOutDuration = value + m_fadeOutMove = 0 + + // -------------------------------------------------------------------------- + function setFadeOutToPos(real duration, vec2 moveToPos) + m_fadeOutDuration = duration + m_fadeOutMove = 1 + m_fadeOutMoveToPos = moveToPos + + // -------------------------------------------------------------------------- + function setFadeOutToRandomPos(real duration) + m_fadeOutDuration = duration + m_fadeOutMove = 2 + + // -------------------------------------------------------------------------- + function getUseRecycler() returns bool + return m_useRecycler + + // -------------------------------------------------------------------------- + function setUseRecycler(bool value) + m_useRecycler = value + + // -------------------------------------------------------------------------- + function getUnitTypeId() returns int + return m_unitTypeId + + // -------------------------------------------------------------------------- + function spawn(player owner, Transform parentTransform) returns unit + m_transform.setParent(parentTransform) + let spawnedUnit = spawnUnit(owner, m_unitTypeId, m_transform) + m_transform.setParent(null) + return spawnedUnit + + // -------------------------------------------------------------------------- + function spawn(player owner, int unitTypeIdOverride, Transform parentTransform) returns unit + m_transform.setParent(parentTransform) + let spawnedUnit = spawnUnit(owner, unitTypeIdOverride, m_transform) + m_transform.setParent(null) + return spawnedUnit + + // -------------------------------------------------------------------------- + private function spawnUnit(player owner, int unitTypeId, Transform worldTransform) returns unit + let pos = worldTransform.getWorldPosition().toVec2() + let facingAngle = worldTransform.getWorldYaw() + + unit spawnedUnit + if (m_useRecycler) + spawnedUnit = createUnitRecycled(owner, unitTypeId, pos, facingAngle) + else + spawnedUnit = createUnit(owner, unitTypeId, pos, facingAngle) + + if (m_fadeInDuration > 0.0) + spawnedUnit.setInvulnerable(true) + spawnedUnit.fadeIn(m_fadeInDuration) + doAfter(m_fadeInDuration, () -> spawnedUnit.setInvulnerable(false)) + + return spawnedUnit + + // -------------------------------------------------------------------------- + function unspawnUnit(unit spawnedUnit) + + if (m_fadeOutDuration == 0.0 or not spawnedUnit.isAlive()) + removeOrRecycleUnit(spawnedUnit) + return + + spawnedUnit.setInvulnerable(true) + spawnedUnit.fadeOut() + + if (m_fadeOutMove == 1) + spawnedUnit.issuePointOrder("move", m_fadeOutMoveToPos) + else if (m_fadeOutMove == 2) + spawnedUnit.issuePointOrder("move", playableBounds.getRandomPoint()) + + doAfter(m_fadeOutDuration) () -> + removeOrRecycleUnit(spawnedUnit) + if (m_useRecycler) + if (not spawnedUnit.isStocked()) + spawnedUnit.stock() + else + spawnedUnit.remove() + + // -------------------------------------------------------------------------- + private function removeOrRecycleUnit(unit spawnedUnit) + if (m_useRecycler) + if (spawnedUnit.isAlive() and not spawnedUnit.isStocked()) + spawnedUnit.stock() + else + spawnedUnit.remove() + +// ============================================================================ +class DestructableSpawner extends WorldObject + private int m_destructableTypeId + private int m_variation + + // -------------------------------------------------------------------------- + construct(int destructableTypeId, int variation) + m_destructableTypeId = destructableTypeId + m_variation = variation + + // -------------------------------------------------------------------------- + function getDestructableTypeId() returns int + return m_destructableTypeId + + // -------------------------------------------------------------------------- + function getVariation() returns int + return m_variation + + // -------------------------------------------------------------------------- + function spawn(Transform parentTransform) returns destructable + m_transform.setParent(parentTransform) + let spawnedDest = createDestructable(m_destructableTypeId, m_variation, m_transform) + m_transform.setParent(null) + return spawnedDest + +// ============================================================================ +function filterUnitIsLootable() returns bool + let filterUnit = GetFilterUnit() + return filterUnit.isLootable() + // ============================================================================ class MapEventAreaCleanerSpawner extends WorldObject private real m_radius @@ -857,11 +1025,6 @@ public class MapEvent extends Runnable override protected function onCompleted() g_runningMapEvents.remove(this) -// ============================================================================ -function filterUnitIsLootable() returns bool - let filterUnit = GetFilterUnit() - return filterUnit.isLootable() - // ============================================================================ init diff --git a/wurst/World/MapEvents/Chickens.wurst b/wurst/World/MapEvents/Chickens.wurst index 1cb69262..0dab599b 100644 --- a/wurst/World/MapEvents/Chickens.wurst +++ b/wurst/World/MapEvents/Chickens.wurst @@ -14,7 +14,6 @@ import RegisterEvents import ItemType import TlsItemIds import TlsUnitDefinition -import UnitSpawner MapEvent g_chickensMapEvent diff --git a/wurst/World/MapEvents/Frogs.wurst b/wurst/World/MapEvents/Frogs.wurst index d86e134c..98d9d816 100644 --- a/wurst/World/MapEvents/Frogs.wurst +++ b/wurst/World/MapEvents/Frogs.wurst @@ -14,7 +14,6 @@ import RegisterEvents import ItemType import TlsItemIds import TlsUnitDefinition -import UnitSpawner MapEvent g_frogsMapEvent diff --git a/wurst/World/MapEvents/RaiderCamp.wurst b/wurst/World/MapEvents/RaiderCamp.wurst index 178e4891..d4e3079e 100644 --- a/wurst/World/MapEvents/RaiderCamp.wurst +++ b/wurst/World/MapEvents/RaiderCamp.wurst @@ -21,7 +21,6 @@ import HashMap import UnitMetadata import GateComponent import UnitExtensions -import UnitSpawner constant real GATE_MIN_DIST_SQ = 256.0 * 256.0 constant real BANDIT_SPAWN_DIST = 200.0 diff --git a/wurst/World/UnitSpawner.wurst b/wurst/World/UnitSpawner.wurst deleted file mode 100644 index aa3e4468..00000000 --- a/wurst/World/UnitSpawner.wurst +++ /dev/null @@ -1,132 +0,0 @@ -package UnitSpawner -import WorldObject -import Transform -import UnitRecycler -import UnitExtensions -import ClosureTimers -import Bounds - -// ============================================================================ -public class UnitSpawner extends WorldObject - private int m_unitTypeId - private real m_fadeInDuration - private real m_fadeOutDuration - private int m_fadeOutMove - private vec2 m_fadeOutMoveToPos - private bool m_useRecycler - private int m_userData - - // -------------------------------------------------------------------------- - construct(int unitTypeId) - m_unitTypeId = unitTypeId - - // -------------------------------------------------------------------------- - function getUserData() returns int - return m_userData - - // -------------------------------------------------------------------------- - function setUserData(int value) - m_userData = value - - // -------------------------------------------------------------------------- - function getFadeInDuration() returns real - return m_fadeInDuration - - // -------------------------------------------------------------------------- - function setFadeInDuration(real value) - m_fadeInDuration = value - - // -------------------------------------------------------------------------- - function getFadeOutDuration() returns real - return m_fadeOutDuration - - // -------------------------------------------------------------------------- - function setFadeOutDuration(real value) - m_fadeOutDuration = value - m_fadeOutMove = 0 - - // -------------------------------------------------------------------------- - function setFadeOutToPos(real duration, vec2 moveToPos) - m_fadeOutDuration = duration - m_fadeOutMove = 1 - m_fadeOutMoveToPos = moveToPos - - // -------------------------------------------------------------------------- - function setFadeOutToRandomPos(real duration) - m_fadeOutDuration = duration - m_fadeOutMove = 2 - - // -------------------------------------------------------------------------- - function getUseRecycler() returns bool - return m_useRecycler - - // -------------------------------------------------------------------------- - function setUseRecycler(bool value) - m_useRecycler = value - - // -------------------------------------------------------------------------- - function getUnitTypeId() returns int - return m_unitTypeId - - // -------------------------------------------------------------------------- - function spawn(player owner, Transform parentTransform) returns unit - m_transform.setParent(parentTransform) - let spawnedUnit = spawnUnit(owner, m_unitTypeId, m_transform) - m_transform.setParent(null) - return spawnedUnit - - // -------------------------------------------------------------------------- - function spawn(player owner, int unitTypeIdOverride, Transform parentTransform) returns unit - m_transform.setParent(parentTransform) - let spawnedUnit = spawnUnit(owner, unitTypeIdOverride, m_transform) - m_transform.setParent(null) - return spawnedUnit - - // -------------------------------------------------------------------------- - private function spawnUnit(player owner, int unitTypeId, Transform worldTransform) returns unit - let pos = worldTransform.getWorldPosition().toVec2() - let facingAngle = worldTransform.getWorldYaw() - - unit spawnedUnit - if (m_useRecycler) - spawnedUnit = createUnitRecycled(owner, unitTypeId, pos, facingAngle) - else - spawnedUnit = createUnit(owner, unitTypeId, pos, facingAngle) - - if (m_fadeInDuration > 0.0) - spawnedUnit.setInvulnerable(true) - spawnedUnit.fadeIn(m_fadeInDuration) - doAfter(m_fadeInDuration, () -> spawnedUnit.setInvulnerable(false)) - - return spawnedUnit - - // -------------------------------------------------------------------------- - function unspawnUnit(unit spawnedUnit) - - if (m_fadeOutDuration == 0.0 or not spawnedUnit.isAlive()) - removeOrRecycleUnit(spawnedUnit) - return - - spawnedUnit.setInvulnerable(true) - spawnedUnit.fadeOut() - - if (m_fadeOutMove == 1) - spawnedUnit.issuePointOrder("move", m_fadeOutMoveToPos) - else if (m_fadeOutMove == 2) - spawnedUnit.issuePointOrder("move", playableBounds.getRandomPoint()) - - doAfter(m_fadeOutDuration) () -> - removeOrRecycleUnit(spawnedUnit) - if (m_useRecycler) - if (not spawnedUnit.isStocked()) - spawnedUnit.stock() - else - spawnedUnit.remove() - - // -------------------------------------------------------------------------- - private function removeOrRecycleUnit(unit spawnedUnit) - if (m_useRecycler) - if (spawnedUnit.isAlive() and not spawnedUnit.isStocked()) - spawnedUnit.stock() - else - spawnedUnit.remove() diff --git a/wurst/World/WorldObject.wurst b/wurst/World/WorldObject.wurst deleted file mode 100644 index 037b7ca5..00000000 --- a/wurst/World/WorldObject.wurst +++ /dev/null @@ -1,15 +0,0 @@ -package WorldObject -import Transform - -// ============================================================================ -public abstract class WorldObject - protected Transform m_transform = new Transform() - - // ---------------------------------------------------------------------------- - ondestroy - destroy m_transform - m_transform = null - - // -------------------------------------------------------------------------- - function getTransform() returns Transform - return m_transform \ No newline at end of file