Commit Graph

303 Commits

Author SHA1 Message Date
SeventhM
d53766b7d7
Unify unit and civ triggers (#11011)
* Unify unit and civ triggers

* Update conditionalsApply check

* add tile in the city override

* Add StateForConditionals for unit uniques when founding a city

* Accidentally removed unit triggers from uponBuildingImprovement

* Accidentally removed parenthesis

* add "tile = tile" to improvement trigger's StateForContitionals

* Add unit's tile to default tile

Co-authored-by: Yair Morgenstern <yairm210@hotmail.com>

* Accidentally did getMatchingUniques instead of getTriggeredUniqued

* Merge triggerUnitWideUniques into TrigerUniques

* checkOnGameInfo Helper to shorten line length

* StateForConditionals secondary constructors

* accidentally deleted

* also accidentally deleted

---------

Co-authored-by: Yair Morgenstern <yairm210@hotmail.com>
2024-01-28 11:06:43 +02:00
SomeTroglodyte
e576b03fc6
Unit actions "paging" new architecture (#10988)
* Linting (and prioritize addGiftAction efficiency over the get used only by unit test)

* Move "paging" out of MapUnit, drop Normal/Additional getter split, "page" preference via UnitActionType

* Optimize UnitActions API a little - fallback does not enumerate actionTypeToFunctions again

* Cleaner access to GiftUnit action from unit test

* Allow freely switching from Sleep to Sleep-until-healed and back
2024-01-24 23:43:31 +02:00
SeventhM
dabd105cf8
Allow units to upgrade to more than one unit (#10947)
* Allow units to upgrade to more than one unit

* Actaully add changes to Base Unit

* And actually add the unique

* Kdocs fixes

* upgradeUnits to getUpgradeUnits and add missing state for condititonalss

* unique.params[0] shouldn't be empty..., right?

* Make old var first in the list, in case it matters

* wait... We're never yielding a null result

* Remove unnecessary function call

* Remove some indentation in RulesetValidation

* isEmpty instead none

* min cost instead of first

* Ruleset helper functions

* Imports

* helper functions part 2

* sanity check in case the unit actually isn't upgradable here

* I missed a spot

* This is NOT using a filter, itis looking for a unitName. Also, why do we use "unit" instead of "unitName"?

* Avoid crash in Scene2dExtentions, part 1

* Avoid crash in Scene2dExtentions, part 2

* inevitable request to move it to its own function

* Upgrade to the correct unit when upgrading all units

* Kdocs I overlooked

* Whoops

* Revert kdocs changes

* Should probably make sure action isn't null

* Fix loop in checkUnitRulesetInvariant

* Minor irrelevant fix

* No response, Removing getUpgradePath part 1 as it's redundant if we upgrade one at a time

* Move to UnitAutomation

* Imports

* Irrelevant fix: ignore consturctionRejections for upgrades

* Irrelevant fix: We should be able to upgrade to obsolete units, just not build new ones

* Simplify for clarity

* Irrelevant fix: unit is not destroyed is it doesn't upgrade

* Whoops

* Imports

* Remove getUpgradePath part 2: simplify UnitAutomation

* Remove now unnecessary circular reference check. We already check if it upgrades to itself

* Whoops, if we use a special upgrade, we should go back to a normal upgrade if we find no special upgrade unique

* Basic tests for last commit

* Forgot special to normal upgrade test

* whoops, forgot to change comment

* Not at computer: List.isEmpty to Sequence.none

* Not at computer: List.size to Sequence.count()
2024-01-24 23:43:07 +02:00
SomeTroglodyte
77c12fcae4
Unit actions builders use sequence (#10966)
* Change actionTypeToFunctions signature to use Sequence

* Linting and a little left pad for the unit action buttons
2024-01-21 19:14:54 +02:00
Oskar Niesen
169ccf5d03
AI worker road priority rework (#10918)
* WorkerAutomation now caches the roads to use

* Workers now build roads differently

* Fixed error if unit movement is zero

* Fixed civ researching an unwanted tech in a test

* Fixed spelling

* Increased road building priority

* getRoadConnectionBetweenCities no longer does unnecessary sorting

* roadsToConnectCitiesCache no longer stores roads that are already built

* ChooseImprovement now builds roads on resource tiles!

* Fixed tryConnectingCities error related to using minByOrNull instead of firstOrNull

* Roads can't have a negative value if they are bigger
2024-01-21 19:12:14 +02:00
Oskar Niesen
c3a4b5f7af
Worker remove feature AI fix (#10917)
* Workers now value the improvement that they want to build after removing a terrain feature

* Restructured getImprovementRanking
2024-01-15 18:55:45 +02:00
SomeTroglodyte
975b2ba165
Unit test against unmatched placeholders in a translation (#10863) 2024-01-09 12:42:04 +02:00
SeventhM
665b5aa87c
Add unique to allow for generalized great generals (#10828)
* Add unique to allow for generalized great generals

* Don't add compatibility for rulesets with conditional generals

* Add to rulesets

* add in pre Kotlin 9 parenthesis

* whoops missed a parenthesis

* I guess pre Kotlin 9 parenthesis was unnecessary, whoops

* Add back old variables to clone function

* Move the list of all potential generals to Ruleset

* Move list of unit construction rejections to IConstruction

* flip !any{} to none{}

* Fix imports

* Typo
2024-01-04 09:03:14 +02:00
Yair Morgenstern
35c19bf9de Fixed tests 2023-12-31 22:59:33 +02:00
Yair Morgenstern
783f846761 Remove source compatibility to java 8, in preparation for Gradle 8.5 upgrade
See #10740
2023-12-28 23:07:24 +02:00
Oskar Niesen
7745cd1c88
Worker AI Rework (#10776)
* WorkerAutomation now uses UnitAutomations's getDangerous tiles

* getPriority now values the current unit tile

* getPriority now values if the tile is worked instead of if it provides a yield

* getPriority prioritises clearing fallout

* getPriority prioritises new resources

* Fixed error in WorkerAutomationTest

* FindTileToWork now uses tilesToAvoid instead of checking for enemies itself

* Workers prioritise their own tile first

* Began reworking tile priority

* Changed getBasePriority() to account for tile damage

* findTileToWork now groups tiles and finds the best tile from the top group

* Fixed method calling findTileToWork()

* Workers don't build roads if their GPT is below 20

* Workers have multiple stages of wanting to connect cities

* Workers prioritise best tiles based on closeness

* Changed stuff

* Fixed a situation where a worker would be on a tile without improving it

* Reduced city connection priority

* Worker prioritises improving closer tiles more

* Worker prioritises improvements that are closer to being finished

* Reverted changes that broke tryConnectingCities more (it is already a little broken)

* Improved repair priority

* Added cityDistanceWant to tryConnectingCities

* Created a partial Test

* Finished first test

* Fixed a merge issue

* Fixed tileHasWorkToDo not accounting for base improvement values

* Added a failing test

* CityPopulationManager now assigns population to tiles in a predictable way for the Worker BasePriority tileProvidesYield

* Added an extra test with two cities and no roads

* Fixed Test creating new workers which ends up failing the test

* Test no longer research and have unnecessary research

* Test no longer include city center tiles as improvements built

* Added a failing test and removed a tryConnectCity filter

* Workers now improve tiles with unseeable resources on them

* Added a resource test

* Fixed should build roads in turns test

* Added an extra test

* tryConnectingCities takes into account the improvement priority

* Separated the improvement stat bonus from the base priority for tryConnectCities

* getBasePriority() now ranks a tile based on its base stats

* replaced mostUnderdevelopedCity with closestUnderDevelopedCity

* changed build road distances wanted

* getImprovementRanking now accounts for resources

* tilePriority now uses a float instead of an int

* Fixed float to int conversion in SpecificUnitAutomation

* Added a test for pillaging
2023-12-28 22:42:11 +02:00
Yair Morgenstern
b56a168e86
Save city focus as string, to allow changes in available city focuses without breaking games (#10794) 2023-12-22 10:07:28 +02:00
dHannasch
4b5bb54b72
Add BaseUnit.automaticallyUpgradedInProductionToUnitByTech() (#10664)
* Update BaseUnit.kt

* Update RulesetValidator.kt

* Update BasicTests.kt

* Update BaseUnit.kt

* Update TechManager.kt

* Update BaseUnit.kt

* Update BaseUnit.kt
2023-12-17 22:00:45 +02:00
Yair Morgenstern
2ae5a018de Added initial pathfinding tests 2023-12-08 14:48:48 +02:00
Yair Morgenstern
cce678800f Fixed pillage tests 2023-12-08 14:10:56 +02:00
Yair Morgenstern
8f049f45f1 Standardized 'create improvement' uniques - need to remember to deprecate the water improvements! 2023-12-07 19:47:45 +02:00
dHannasch
155498dc43
Wrap BaseUnit.obsoleteTech into function (#10648)
* Update BaseUnit.kt

* Update BaseUnit.kt

* Update TechManager.kt

* Update BaseUnit.kt

* Update RulesetValidator.kt

* Update BasicTests.kt
2023-12-03 22:26:16 +02:00
Oskar Niesen
f1ceaa216a
Get distance to nearest enemy rework (#10481)
* Initial refactor

* Moved checking if a tile has an enemy to a new method

* Rewrote getDistanceToEnemyUnit

* changed the position of the logic of checking if the enemy is still there

* Changed some of the other methods to use the ThreatManager getClosestEnemy()

* Added a new getTilesWithEnemyUnitsInDistance method

* Added a new getEnemyMilitaryUnitsInDistance method

* Converted a few lines to use ThreatManager

* Changed Air units to use threat manager

* Fixed tileWithEnemy error

* distanceToClosestEnemyTiles now clears at the start of every turn

* Added blank lines to end of ThreatManager.kt

* Renamed tilesInRange to tilesWithEnemyUnitsInRange

* Changed ArrayList return to a MutableList

* Removed ClosestEnemyTileData being a data class

* Improved commenting

* Improved commenting2

* getEnemyMilitaryUnitsInDistance now uses a flatMap and moved getDangerousTiles to threat manager

* Created a new helper method getEnemyUnitsOnTiles

* Renamed clearThreatData to clear

* Added shortcut if maxDist is less than or equal to distanceSearched

* Fixed distanceWithNoEnemies in getTilesWithEnemyUnitsInDistance

* Fixed notFoundDistance being higher than maxDistance when takeLargerValues is false

* Added some ThreatManager tests

* Added some more ThreatManager tests

* Removed visible map after use

* getTilesWithEnemyUnitsInDistance doesn't search distances <= tileData.distanceSearched (previously was <)

* Added 3 more tests

---------

Co-authored-by: Yair Morgenstern <yairm210@hotmail.com>
2023-11-25 20:11:10 +02:00
SomeTroglodyte
987f67d9cd
[code quality] Reorg, clean up and comment a few things (#10527)
* UncivGame is a pure class file again, GUI split off

* Purify GameSettings step 1 - non-multiplayer nested classes

* Purify GameSettings step 2 - multiplayer nested classes

* Purify GameParameters - BaseRuleset to own file

* Rework WindowState to centralize minimum/maximum treatment

* Rename MultiplayerTurnNotifierDesktop to UncivWindowListener

* Clarifications on what the WindowListener actually does (and now the attention-getting does something on non-Windows too)
2023-11-19 23:52:15 +02:00
Yair Morgenstern
fb1e57668e Added tests for parameters for complex filters, fixed nested complex filter returning 'possible filtering' when it should have been known 2023-11-19 00:06:34 +02:00
Framonti
8c9e6b07e0
Test/add tests for cityexpansionmanager (#10510)
* improve error message and add test for precondition checking

* add tests for CityExpansionManager
2023-11-18 22:34:26 +02:00
Yair Morgenstern
dc6413d707 Modding: Added "non-[filter]" filtering for unit filters
Cleaned up unit filter validations to match actual filters
2023-11-18 22:16:43 +02:00
SomeTroglodyte
cfeed82800
Whitespace linting for opening curly braces and inheritance colon (#10490) 2023-11-13 22:11:55 +02:00
Framonti
02844e51d7
add tests for CityFounder (#10439)
* 🎨 add spaces to better format code

*  add tests for CityFounder

* ️ exploit early returns to avoid computing some values
2023-11-07 10:39:34 +02:00
Framonti
e9b3ec5282
fix flaky tests by properly assigning pop to work on specific tile (#10421) 2023-11-04 21:24:26 +02:00
Yair Morgenstern
e43d870b43 Fastlane fixes 2023-10-30 12:43:28 +02:00
Yair Morgenstern
f9134c90dc @Framonti
This test seems to be flaky - works from my computer but fails sometimes on github
2023-10-30 11:11:11 +02:00
Framonti
f27fa7bab6
💚 add tests for city population manager (#10347) 2023-10-29 18:59:38 +02:00
SomeTroglodyte
13e3baac74
Split Fonts.kt (#10267)
* Fix font "symbols" not showing

* Move Fonts.kt to sub-package

* Re-sort imports

* Move top-level constants to prepare split

* Split Fonts.kt each existing class to its own file

* Split off FontRulesetIcons

* Linting and comments
2023-10-08 22:03:53 +03:00
Yair Morgenstern
2bd65f9f42 chore: Extracted all 'next turn' logic from DiplomacyManager to DiplomacyTurnManager 2023-10-08 11:48:33 +03:00
SomeTroglodyte
49e2979427
Align ruleset icons in text to font metrics (#10233)
* Try to respect actual font layout, so fontSizeMultiplier works for ruleset icons too

* Replace font-based nation symbol in top bar with statically sized actor

* Reuse getReadonlyPixmap in extractPixmapFromTextureRegion

* Tweak topbar selected civ vertical align to be more pleasing to the human eye

* FasterUIDevelopment missing implementation of FontMetricsCommon

* Address hardcoded pixel coordinates comment

* Readability and comment cleanup

* More readability changes
2023-10-07 22:00:30 +03:00
SomeTroglodyte
5db8489bcb
Tweak FasterUIDevelopment to offer normal Scene2D debugging, and some linting (#10263) 2023-10-07 21:58:19 +03:00
Framonti
3a3abd20fa
add golden age manager tests (#10226)
* 🚚 move test to right package

* 💚 add tests for golden age manager
2023-10-03 13:04:44 +03:00
SeventhM
98533b91f9
Reimplement and fix #10142 (#10213)
* Test Free Buildings

* Flip the order of logging free buildings to avoid loops with stat buildings

* unprivate constructionComplete for the notification and add validating the queue to addBuilding

* reimplement #10142

* Switch free buildings in cityFilter to also use constructionComplete for consistency
2023-10-03 12:10:43 +03:00
Framonti
b01353eee7
Test city conquest functions (#10196)
* 💚 add tests covering most city conquest functions

* ♻️ change var to val when values don't change
2023-09-29 16:27:43 +03:00
Yair Morgenstern
190d488c06 modding: Mod checker displays *all* unknown uniques 2023-09-28 20:46:31 +03:00
Yair Morgenstern
d1b2d652e3 reorg: Separated UnitActions into 3 files:
- UnitActionsFromUniques
- UnitActionModifiers
- UnitActions retains actions relevant to all units
2023-09-28 15:30:39 +03:00
Yair Morgenstern
b6f3c8571f chore: Move files to correct folders 2023-09-27 13:19:13 +03:00
Yair Morgenstern
0d942ac175 Reload images when downloading or removing a mod 2023-09-21 14:58:23 +03:00
Framonti
26bae52508
💚 add tests covering most nukes functionalities (#10146) 2023-09-19 10:31:39 +03:00
Framonti
fba3198887
Unit tests for Battle.kt (#10127)
*  add testing helper function to create the barbarian civilization

* add tests for Battle class

* add more tests for Battle class

* ♻️ let compiler infer types

* add helper test methods to create unit with uniques

* use unit with unique explicitly created to loose tests from specific ruleset

* add even more tests for Battle
2023-09-14 18:53:40 +03:00
Oskar Niesen
ee81b3e84e
Defensive pact Tests (#10088) 2023-09-11 09:06:09 +03:00
Framonti
885675bea3
💚 add tests for Diplomacy manager (#10087) 2023-09-09 21:27:03 +03:00
Yair Morgenstern
30570747a8
Unify placeholder parsing for unique parameters (#10072)
* Unify placeholder parsing for unique parameters

* Remove double "remove conditional" call - kudos @SomeTroglodyte
2023-09-07 09:57:40 +03:00
Yair Morgenstern
55a3fa2a75 cleanup: Copy Zero vectors before passing to localToStageCoordinates (#10048) 2023-09-06 12:38:14 +03:00
Framonti
538330db87
Test/refactor target helper and test it (#10048)
* ♻️ merge together two branches executing same code

* ♻️ swap if-else chain with when to improve readability

* ️ swap conditions to first check the lighter computationally-wise

* ♻️ extract method to increase readability

* 💚 add some tests for TargetHelper

* 💡 add comment explaining how Unciv grid system works using a graphical example

* 💚 add other tests

* ♻️ change method name to better reflect what it does

* 🐛 fix import after rebase

* 🔥 remove parameter when value is the default and use static field for Vector2(0f, 0f)

* ♻️ split setTileTerrainAndFeatures in two different methods

* ♻️ update older tests to use the new functions
2023-09-05 22:25:28 +03:00
Yair Morgenstern
93f882d3c8 tests: Load vanilla game test fixed 2023-09-04 17:08:52 +03:00
Yair Morgenstern
df03f36207 chore: Added missing imports 2023-09-04 16:09:55 +03:00
Yair Morgenstern
f4c7dc4890 chore: Reorg tests, so /testing folder contains only test-helper classes 2023-09-04 16:06:06 +03:00
Framonti
7952366afb
Refactor BattleDamage object and test it (#9992)
* 💡 add some comments providing examples

* ♻ refactor getGeneralModifiers to increase readability

* ♻ refactor getAttackModifiers to increase readability

* 🏗 move constants expressed as magic number to separated class to increase maintainability and expressivity

* ♻ invert condition to remove continue statement and simplify code

* 💚 add some tests for battle damage class
2023-08-30 23:37:10 +03:00