-
Notifications
You must be signed in to change notification settings - Fork 4
Reimplement native market pricing and goods trading #216
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
Open
Krarilotus
wants to merge
2
commits into
sourcehold:main
Choose a base branch
from
Krarilotus:reimplement/market-trading
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Market pricing and goods trading | ||
|
|
||
| The AI buys and sells resources using the game's price table. The trade routines | ||
| handle storage and gold accounting; the decision to trade is made by their callers. | ||
|
|
||
| | Function | Crusader 1.41 address | Behavior | | ||
| | --- | --- | --- | | ||
| | `GameStateStructures::getBuyPrice` | `0x004588A0` | Returns `(buyPrice / 5) * amount`. | | ||
| | `GameStateStructures::getSellPrice` | `0x00458910` | Returns `(salesPrice / 5) * amount`. | | ||
| | `AICState::buyGoods` | `0x004CC000` | Attempts resource storage, then deducts gold and displays the trade on success. | | ||
| | `AICState::sellGoods` | `0x004CBFA0` | Credits gold and final-result statistics, removes resources, then displays the trade. | | ||
|
|
||
| ## Prices | ||
|
|
||
| Prices are stored for lots of five goods. The game divides that price by five | ||
| using integer division, then multiplies by the amount traded. For example, a | ||
| table price of 14 and a trade of five goods produce a price of 10. The player | ||
| argument does not affect the price calculation. | ||
|
|
||
| ## Buying and selling | ||
|
|
||
| A purchase first attempts to store the goods. If storage fails, it returns | ||
| without deducting gold or displaying a trade. The routine itself does not check | ||
| whether the player can afford the purchase. Successful purchases reduce both | ||
| the player's gold and their net market-gold total. | ||
|
|
||
| A sale increases those two totals and the final-results gold statistic, then | ||
| removes the sold goods. Both successful purchases and sales display the trade | ||
| amount to the player. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #include "../AICState.func.hpp" | ||
|
|
||
| #include "OpenSHC/Game/GameStateStructures.func.hpp" | ||
| #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" | ||
|
|
||
| #include "OpenSHC/Globals/DAT_BuildingsState.hpp" | ||
| #include "OpenSHC/Globals/DAT_GameState.hpp" | ||
|
|
||
| namespace OpenSHC { | ||
| namespace AI { | ||
|
|
||
| // FUNCTION: STRONGHOLDCRUSADER 0x004CC000 | ||
| BOOLEnum AICState::buyGoods(int playerID, ResourceType resourceType, int amount) | ||
| { | ||
| int const cost = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getBuyPrice, DAT_GameState::ptr)( | ||
| playerID, resourceType, amount); | ||
| if (MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::processResourceGain, DAT_BuildingsState::ptr)( | ||
| playerID, resourceType, amount)) { | ||
| DAT_GameState::instance.playerDataArray[playerID].currentResources[Game::Resources::RT_GOLD] -= cost; | ||
| DAT_GameState::instance.playerDataArray[playerID].marketGold -= cost; | ||
| MACRO_CALL_MEMBER(Game::GameStateStructures_Func::displayPlayerTradeVisualEffect, DAT_GameState::ptr)( | ||
| playerID, 0, amount, resourceType); | ||
| return TRUE; | ||
| } | ||
| return FALSE; | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include "../AICState.func.hpp" | ||
|
|
||
| #include "OpenSHC/Game/GameStateStructures.func.hpp" | ||
| #include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" | ||
|
|
||
| #include "OpenSHC/Globals/DAT_BuildingsState.hpp" | ||
| #include "OpenSHC/Globals/DAT_GameState.hpp" | ||
| #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" | ||
|
|
||
| namespace OpenSHC { | ||
| namespace AI { | ||
|
|
||
| // FUNCTION: STRONGHOLDCRUSADER 0x004CBFA0 | ||
| void AICState::sellGoods(int playerID, ResourceType resourceType, int amount) | ||
| { | ||
| int const reward = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSellPrice, DAT_GameState::ptr)( | ||
| playerID, resourceType, amount); | ||
| DAT_GameSynchronyState::instance.finalResults.finalGold[playerID] += reward; | ||
| DAT_GameState::instance.playerDataArray[playerID].currentResources[Game::Resources::RT_GOLD] += reward; | ||
| DAT_GameState::instance.playerDataArray[playerID].marketGold += reward; | ||
| MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::processResourceLoss, DAT_BuildingsState::ptr)( | ||
| playerID, resourceType, amount, 0); | ||
| MACRO_CALL_MEMBER(Game::GameStateStructures_Func::displayPlayerTradeVisualEffect, DAT_GameState::ptr)( | ||
| playerID, 1, -amount, resourceType); | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include "../GameStateStructures.func.hpp" | ||
|
|
||
| namespace OpenSHC { | ||
| namespace Game { | ||
|
|
||
| // FUNCTION: STRONGHOLDCRUSADER 0x004588A0 | ||
| int GameStateStructures::getBuyPrice(undefined4 playerID, int resourceType, int amount) | ||
| { | ||
| return (this->mapAndTime.buyAndSalesPriceArray[resourceType].buyPrice / 5) * amount; | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include "../GameStateStructures.func.hpp" | ||
|
|
||
| namespace OpenSHC { | ||
| namespace Game { | ||
|
|
||
| // FUNCTION: STRONGHOLDCRUSADER 0x00458910 | ||
| int GameStateStructures::getSellPrice(int playerID, int resourceType, int amount) | ||
| { | ||
| return (this->mapAndTime.buyAndSalesPriceArray[resourceType].salesPrice / 5) * amount; | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you replace something here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No existing entry was replaced: the diff adds only the market-trading link below the load-balancing page. The rest of the index is unchanged.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is unclear that this article will be about AI. Please add a AI subsection and add this entry to it with AI in the title. And make sure the .md file refers to AI market behavior explicitly.