Files
Grinch-AP/worlds/civ_6/Rules.py
Carter Hesterman 5f73c245fc New Game Implementation: Civilization VI (#3736)
* Init

* remove submodule

* Init

* Update docs

* Fix tests

* Update to use apcivvi

* Update Readme and codeowners

* Minor changes

* Remove .value from options (except starting hint)

* Minor updates

* remove unnecessary property

* Cleanup Rules and Region

* Fix output file generation

* Implement feedback

* Remove 'AP' tag and fix issue with format strings and using same quotes

* Update worlds/civ_6/__init__.py

Co-authored-by: Scipio Wright <scipiowright@gmail.com>

* Minor docs changes

* minor updates

* Small rework of create items

* Minor updates

* Remove unused variable

* Move client to Launcher Components with rest of similar clients

* Revert "Move client to Launcher Components with rest of similar clients"

This reverts commit f9fd5df9fdf19eaf4f1de54e21e3c33a74f02364.

* modify component

* Fix generation issues

* Fix tests

* Minor change

* Add improvement and test case

* Minor options changes

* .

* Preliminary Review

* Fix failing test due to slot data serialization

* Format json

* Remove exclude missable boosts

* Update options (update goody hut text, make research multiplier a range)

* Update docs punctuation and slot data init

* Move priority/excluded locations into options

* Implement docs PR feedback

* PR Feedback for options

* PR feedback misc

* Update location classification and fix client type

* Fix typings

* Update research cost multiplier

* Remove unnecessary location priority code

* Remove extrenous use of items()

* WIP PR Feedback

* WIP PR Feedback

* Add victory event

* Add option set for death link effect

* PR improvements

* Update post fill hint to support items with multiple classifications

* remove unnecessary len

* Move location exclusion logic

* Update test to use set instead of accidental dict

* Update docs around progressive eras and boost locations

* Update docs for options to be more readable

* Fix issue with filler items and prehints

* Update filler_data to be static

* Update links in docs

* Minor updates and PR feedback

* Update boosts data

* Update era required items

* Update existing techs

* Update existing techs

* move boost data class

* Update reward data

* Update prereq data

* Update new items and progressive districts

* Remove unused code

* Make filler item name func more efficient

* Update death link text

* Move Civ6 to the end of readme

* Fix bug with hidden locations and location.name

* Partial PR Feedback Implementation

* Format changes

* Minor review feedback

* Modify access rules to use list created in generate_early

* Modify boost rules to precalculate requirements

* Remove option checks from access rules

* Fix issue with pre initialized dicts

* Add inno setup for civ6 client

* Update inno_setup.iss

---------

Co-authored-by: Scipio Wright <scipiowright@gmail.com>
Co-authored-by: Exempt-Medic <60412657+Exempt-Medic@users.noreply.github.com>
Co-authored-by: Exempt-Medic <ExemptMedic@Gmail.com>
Co-authored-by: NewSoupVi <57900059+NewSoupVi@users.noreply.github.com>
2025-03-10 14:53:26 +01:00

110 lines
4.0 KiB
Python

from typing import TYPE_CHECKING, List, Tuple
from BaseClasses import CollectionState
from .ItemData import CivVIBoostData
from .Items import format_item_name
from .Data import get_boosts_data, get_progressive_districts_data
from .Enum import CivVICheckType
from .ProgressiveDistricts import convert_item_to_progressive_item
from worlds.generic.Rules import forbid_item, set_rule
if TYPE_CHECKING:
from . import CivVIWorld
def generate_requirements_for_boosts(
world: "CivVIWorld", boost_data: CivVIBoostData
) -> Tuple[List[str], List[Tuple[str, int]]]:
required_non_progressive_items: List[str] = []
required_progressive_item_counts: List[Tuple[str, int]] = []
for item in boost_data.Prereq:
progressive_item_name = convert_item_to_progressive_item(item)
if (
world.options.progression_style != "none"
and "PROGRESSIVE" in progressive_item_name
):
required_progressive_item_counts.append(
(
format_item_name(progressive_item_name),
get_progressive_districts_data()[progressive_item_name].index(item)
+ 1,
)
)
else:
ap_item_name = world.item_by_civ_name[item]
required_non_progressive_items.append(ap_item_name)
return required_non_progressive_items, required_progressive_item_counts
def create_boost_rules(world: "CivVIWorld"):
boost_data_list = get_boosts_data()
boost_locations = [
location
for location in world.location_table.values()
if location.location_type == CivVICheckType.BOOST
]
for location in boost_locations:
boost_data = next(
(boost for boost in boost_data_list if boost.Type == location.name), None
)
world_location = world.get_location(location.name)
forbid_item(world_location, "Progressive Era", world.player)
if boost_data and boost_data.PrereqRequiredCount > 0:
required_non_progressive_items, required_progressive_item_counts = (
generate_requirements_for_boosts(world, boost_data)
)
if world.options.progression_style != "none":
set_rule(
world_location,
lambda state, non_progressive_prereqs=required_non_progressive_items, progressive_prereq_counts=required_progressive_item_counts, required_count=boost_data.PrereqRequiredCount: has_required_items_progressive(
state,
non_progressive_prereqs,
progressive_prereq_counts,
required_count,
world,
),
)
else:
set_rule(
world_location,
lambda state, prereqs=required_non_progressive_items, required_count=boost_data.PrereqRequiredCount: has_required_items_non_progressive(
state, prereqs, required_count, world
),
)
def has_required_items_progressive(
state: CollectionState,
non_progressive_prereqs: List[str],
progressive_prereq_counts: List[Tuple[str, int]],
required_count: int,
world: "CivVIWorld",
) -> bool:
collected_count = 0
for item, count in progressive_prereq_counts:
if state.has(item, world.player, count):
collected_count += 1
# early out if we've already gotten enough
if collected_count >= required_count:
return True
for item in non_progressive_prereqs:
if state.has(item, world.player):
collected_count += 1
# early out if we've already gotten enough
if collected_count >= required_count:
return True
return False
def has_required_items_non_progressive(
state: CollectionState, prereqs: List[str], required_count: int, world: "CivVIWorld"
) -> bool:
return state.has_from_list_unique(
prereqs,
world.player,
required_count,
)