Skip to content
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

Add place variant building for BaseBuilderBotModule. #19941

Merged
merged 1 commit into from Apr 12, 2022

Conversation

dnqbob
Copy link
Contributor

@dnqbob dnqbob commented Mar 2, 2022

Add place variant building for BaseBuilderBotModule.

  1. If it follow the refinery placing logic, then we can use Facings in PlaceBuildingVariants to help BaseBuilderBotModule "rotates" it to minefield.

  2. If it is a normal building, BaseBuilderBotModule will place a random variant actor.

Ingame Picture

QQ图片20220220212022
QQ图片20220220212022
1
2
3
4

Usage

  1. Add Facing to refinery with facings like:
	PlaceBuildingVariants:
		Actors: refinery-nw, refinery-ne, refinery-se
		Facings: 640, 896, 128, 384 ## 640 is the actor itself facing
  1. In AI.yaml, add All related building variants to those lines below:
		RefineryTypes: refinery, refinery-nw, refinery-ne, refinery-se
		PowerTypes: pwrplt, advpwr, pwrplt-3x2
		BarracksTypes: barracks, nhand, nhand-2x3
		VehiclesFactoryTypes: warfactory, airstrip
		ProductionTypes: barracks, nhand, warfactory, airstrip, helipad, nhand-2x3

@dnqbob
Copy link
Contributor Author

dnqbob commented Mar 2, 2022

I got probably lots of grammar mistakes in english so... I need help with that in comment

@dnqbob dnqbob force-pushed the AI-place-rotation-building branch from c057919 to dcc2361 Compare March 5, 2022 14:57
Copy link
Member

@RoosterDragon RoosterDragon left a comment

Choose a reason for hiding this comment

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

Looks like a neat feature, have some minor suggestions for you.

The build failure would be resolved by one of my suggestions, or alternatively you can replace new string[0] with Array.Empty<string>() to solve it if you prefer.

// Add all the build varriant name in the name list and use it for count
var actorInfo = world.Map.Rules.Actors[name];
var buildingVariantInfo = actorInfo.TraitInfoOrDefault<PlaceBuildingVariantsInfo>();
var variants = (buildingVariantInfo != null && buildingVariantInfo.Actors != null) ? buildingVariantInfo.Actors : new string[0];
Copy link
Member

Choose a reason for hiding this comment

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

This might be a bit cleaner, up to you:

var varients = buildingVariantInfo?.Actors;

var count = playerBuildings.Count(a => a.Info.Name == name || variants?.Contains(a.Info.Name));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a pity that || cannot apply to a bool and bool?(by variants?.Contains(a.Info.Name)))

@dnqbob dnqbob force-pushed the AI-place-rotation-building branch 4 times, most recently from 047b795 to b7eb360 Compare March 12, 2022 06:18
@dnqbob
Copy link
Contributor Author

dnqbob commented Mar 12, 2022

Fixed and tested.

As for testcase of this branch:
if there is no other grammar and code problem here, I will push an engine upgrade for SP&RV which use current change on engine for building rotation. You can then use RV and SP to test it out.

At that time I need your permission and help @MustaphaTR

RoosterDragon
RoosterDragon previously approved these changes Mar 12, 2022
@dnqbob
Copy link
Contributor Author

dnqbob commented Mar 12, 2022

  1. Delete an useless comment right below Func<CPos, CPos, int, int, (CPos? Location, int Variant)> findPos
  2. Add comment Check the number of this structure and its variants

1. If it follow the refinery placing logic, then we can use Facings in PlaceBuildingVariants to help BaseBuilderBotModule "rotates" it to minefield.

2. If it is a normal building, BaseBuilderBotModule will place a random variant actor.
@dnqbob dnqbob force-pushed the AI-place-rotation-building branch from 218f91d to f0a0717 Compare March 12, 2022 13:02
@dnqbob
Copy link
Contributor Author

dnqbob commented Mar 13, 2022

test case mod:
https://github.com/ABrandau/Shattered-Paradise-SDK

Any AI will do

@Mailaender Mailaender merged commit 4f43b15 into OpenRA:bleed Apr 12, 2022
@Mailaender
Copy link
Member

Changelog

@dnqbob dnqbob deleted the AI-place-rotation-building branch April 12, 2022 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants