Skip to content

New Feature: Support Convert to another type. - #2294

Open
frg2089 wants to merge 17 commits into
Phobos-developers:developfrom
ShimakazeProject:develop
Open

New Feature: Support Convert to another type.#2294
frg2089 wants to merge 17 commits into
Phobos-developers:developfrom
ShimakazeProject:develop

Conversation

@frg2089

@frg2089 frg2089 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactored the underlying type conversion system (ConvertToType / ConvertToTypeEx) to support cross-type conversion between all TechnoType classes except AircraftType. Added UndeploysInto.ConvertTo as a new conversion trigger on BuildingType.

Changes

Core: rewritten conversion logic

  • ConvertToType and new ConvertToTypeEx now handle cross-type conversion via creating a new object + destroying the old one, supporting InfantryType, UnitType, and BuildingType.
  • AircraftType is only supported for same-type conversion (in-place type pointer update).
  • Deferred conversion via PendingConvertTechnoType processed in OnEarlyUpdate — used when the source unit needs to finish its current animation frame before being destroyed.

This improvement applies to all existing conversion paths (Convert.Deploy, Convert.Undeploy, Convert.HumanToComputer, Convert.ComputerToHuman, etc.).

New feature: UndeploysInto.ConvertTo

  • BuildingType tag UndeploysInto.ConvertTo specifies a target TechnoType.
  • After UndeploysInto creates the vehicle, it is converted to the target type on the next frame.
  • The resulting unit inherits the vehicle's move order, destination, and selection state.
  • Mind control, shields, invulnerability, and attached effects are transferred.

Refactor

  • Moved TransferMindControlOnDeploy from Hooks.DeploysInto.cpp into TechnoExt as a reusable static method.

Selection preservation

  • Both deploy (infantry → building) and undeploy convert (vehicle → other) now preserve the original unit's selection state on the new unit.

Documentation

Updated New-or-Enhanced-Logics.md with documentation for UndeploysInto.ConvertTo, the expanded type support in Convert.Deploy / Convert.Undeploy, and a warning that cross-type conversion creates a new object and destroys the old one.

Files Changed

File Change
src/Ext/Techno/Body.cpp ConvertToTypeEx cross-type conversion, ConvertToType same-type fallback, property transfer
src/Ext/Techno/Body.h PendingConvertTechnoType, static method declarations
src/Ext/Techno/Body.Update.cpp Deferred conversion processing
src/Ext/Unit/Hooks.DeploysInto.cpp Delegate to TechnoExt, add UndeploysInto.ConvertTo hook
src/Ext/BuildingType/Body.h/.cpp UndeploysInto.ConvertTo tag
docs/New-or-Enhanced-Logics.md Documentation

@frg2089 frg2089 changed the title Refactor type conversion logic to support cross-type conversion and add UndeploysInto.ConvertTo trigger New Feature: Support Convert to another type. Jul 18, 2026
Comment thread src/Ext/Techno/Body.cpp
Comment thread src/Ext/Techno/Body.cpp Outdated
Comment thread src/Ext/Techno/Body.cpp Outdated
Comment thread src/Ext/Techno/Body.cpp Outdated
Comment thread src/Ext/Unit/Hooks.DeploysInto.cpp Outdated
Comment thread src/Ext/Techno/Body.Update.cpp Outdated
Comment thread docs/New-or-Enhanced-Logics.md Outdated
@frg2089
frg2089 marked this pull request as draft July 18, 2026 17:38
@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown

Nightly build for this pull request:

This comment is automatic and is meant to allow guests to get latest nightly builds for this pull request without registering. It is updated on every successful build.

@frg2089
frg2089 marked this pull request as ready for review July 19, 2026 02:21
Comment thread src/Ext/Techno/Body.cpp

@TaranDahl TaranDahl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no other issues.

@TaranDahl TaranDahl added Needs testing ⚙️T1 T1 maintainer review is sufficient labels Jul 23, 2026
@TaranDahl
TaranDahl requested a review from NetsuNegi July 23, 2026 10:27
@frg2089

frg2089 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

喵?

@TaranDahl

Copy link
Copy Markdown
Contributor

喵?

Since this is your first PR submission, your code will need reviews from more maintainers before it can be merged. This is the rule of Phobos.

@frg2089

frg2089 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

Since this is your first PR submission, your code will need reviews from more maintainers before it can be merged. This is the rule of Phobos.

OK, I will stop resolving the conflict before there are further results.

frg2089 added 11 commits August 23, 2026 12:10
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
… space

Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Signed-off-by: 舰队的偶像-岛风酱! <frg2089@outlook.com>
Align the actual building placement in ConvertToTypeEx with the deploy
cursor check so that the building ends up centered on the deploying
unit. Extract the shared top-left cell computation into
BuildingTypeExt::GetDeployBuildingTopLeftCell, mirroring the vanilla
deploy logic which offsets by (-1,-1) for foundations larger than 2x2.
@frg2089
frg2089 deleted the branch Phobos-developers:develop August 23, 2026 04:15
@frg2089 frg2089 closed this Aug 23, 2026
@frg2089
frg2089 deleted the develop branch August 23, 2026 04:15
@frg2089
frg2089 restored the develop branch August 23, 2026 04:17
@frg2089 frg2089 reopened this Aug 23, 2026
Copilot AI lite review requested due to automatic review settings August 23, 2026 04:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors Phobos’ TechnoType conversion pipeline to support cross-category conversions (object replacement) across Infantry/Unit/Building types, adds a new BuildingType INI trigger (UndeploysInto.ConvertTo) to convert the undeployed unit on the next frame, and updates documentation/changelog/credits accordingly.

Changes:

  • Added cross-category conversion via TechnoExt::ConvertToTypeEx (create new object + destroy old), with deferred conversion support (PendingConvertTechnoType) processed in TechnoExt::OnEarlyUpdate.
  • Centralized status transfer during deploy/undeploy (mind control, shields, invulnerability, attached effects, multipliers, etc.) via TechnoExt::SyncStatus.
  • Added deploy feedback improvements and documented the new conversion behaviors (including zh_CN locale updates and credits/changelog entries).

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Misc/Hooks.BugFixes.cpp Switches deploy-to-fire checks to TechnoExt::CanDeployIntoBuilding.
src/Ext/Unit/Hooks.DeploysInto.cpp Uses TechnoExt::SyncStatus, adds UndeploysInto.ConvertTo deferral, adds deploy action hook, adjusts deploy placement/desync logic.
src/Ext/Unit/Hooks.DeployFire.cpp Adds NoDeploy feedback (EVA) when Convert.Deploy targets a building without sufficient space.
src/Ext/Unit/Body.h Removes UnitExt deployer/static deploy checks now moved into TechnoExt.
src/Ext/Unit/Body.cpp Removes UnitExt::Deployer and UnitExt::CanDeployIntoBuilding implementation.
src/Ext/Techno/Body.Update.cpp Processes deferred conversions (PendingConvertTechnoType) during early update.
src/Ext/Techno/Body.h Adds PendingConvertTechnoType, Deployer, and new conversion/status-transfer method declarations.
src/Ext/Techno/Body.cpp Implements SyncStatus, moves deploy-related helpers into TechnoExt, and adds ConvertToTypeEx for cross-category conversions.
src/Ext/BuildingType/Body.h Adds UndeploysInto_ConvertTo storage and declares a helper for deploy cell computation.
src/Ext/BuildingType/Body.cpp Implements GetDeployBuildingTopLeftCell, reads/serializes UndeploysInto.ConvertTo.
docs/Whats-New.md Adds changelog entries for cross-category conversion and related improvements.
docs/New-or-Enhanced-Logics.md Documents UndeploysInto.ConvertTo.
docs/Fixed-or-Improved-Logics.md Updates “fixed/improved” notes for conversion behavior and feedback.
docs/locale/zh_CN/LC_MESSAGES/Whats-New.po Adds zh_CN translations for new changelog bullets.
docs/locale/zh_CN/LC_MESSAGES/New-or-Enhanced-Logics.po Adds zh_CN translations for UndeploysInto.ConvertTo docs.
docs/locale/zh_CN/LC_MESSAGES/Fixed-or-Improved-Logics.po Updates zh_CN translations to match new conversion/feedback entries.
docs/locale/zh_CN/LC_MESSAGES/CREDITS.po Adds zh_CN credits entries for the contributor.
CREDITS.md Adds credits entries for the new conversion features and preservation behaviors.
Suppressed comments (3)

src/Ext/Techno/Body.cpp:526

  • ConvertToTypeEx calls SyncStatus (which can transfer mind control, shields, attached effects, etc.) before ForceCreate. If ForceCreate fails, the source unit's state may already have been mutated (e.g., mind control freed), leaving it in an inconsistent state.
		SyncStatus(pThis, pBuilding);

		pBuilding->QueueMission(Mission::Construction, false);
		pBuilding->NextMission();

src/Ext/Techno/Body.cpp:576

  • ConvertToTypeEx calls SyncStatus before attempting Unlimbo the new unit. If Unlimbo fails, the rollback path re-unlimbos the old unit but does not restore any state already transferred (mind control, attached effects, etc.). Move status transfer until after the new unit has been successfully placed.
		if (auto const pUnit = static_cast<FootClass*>(pToType->CreateObject(pHouse)))
		{
			SyncStatus(pThis, pUnit);

			// Remove old techno from map
			pThis->Limbo();

src/Ext/Techno/Body.cpp:568

  • PR description says cross-category conversion should not support AircraftType (only same-type in-place conversion). ConvertToTypeEx currently includes AbstractType::AircraftType in the cross-type object-replacement path, which contradicts that behavior.
	case AbstractType::InfantryType:
	case AbstractType::UnitType:
	case AbstractType::AircraftType:

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Ext/Techno/Body.cpp
Comment on lines 372 to 379
const auto pType = pThis->GetTechnoType();

// It really should be at the beginning.
if (pType == pToType || pType->WhatAmI() != pToType->WhatAmI())
if (pType == pToType)
{
Debug::Log("Incompatible types between %s and %s\n", pThis->get_ID(), pToType->get_ID());
return false;
}
Comment on lines 49 to 50
// This line will break the bahavior of UnDeploysInto buildings. However, it might serve a purpose that no one knows yet
// Comment out the line instead of removing it for now, so we can turn to it if something related goes wrong in the future
Comment on lines +224 to 225
if (!builtOnCanBeBuiltOn && (pCell->OccupationFlags & (skipFlag ? 0x03 : 0x3F)))
return CanNotExistHere;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs testing ⚙️T1 T1 maintainer review is sufficient

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants