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

Map action 507 for printing a message with the remaining map objects #1266

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

FS-21
Copy link
Contributor

@FS-21 FS-21 commented May 19, 2024

  • A message will be printed with a list of alive map objects.
  • If no CSFKey is mentioned (value 0) it will use the default header text Remaining: .
  • HouseIndex points to any house index of the map. Multiplayer 4475-4482 & 8997 indexes are valid.
  • If HouseIndex is set -1 then [AIHousesListsIndex] will be used as index of a list of countries in the [AIHousesList] section located in rulesmd.ini. If any map object match the ownership with one of the list it will be counted.
  • [AITargetTypesIndex] is the index of an entry in the [AITargetTypes] section located in rulesmd.ini. Each alive map object listed here will be counted.
  • If [AITargetTypesIndex] is negative this value will be evaluated as a positive index in [AITargetTypesIndex] but instead of printing a list of alive map objects and the respective count it will appear as an unique global count of all the alive map objects listed in [AITargetTypes].
  • MesageDelay is the time (in minutes) of the message displayed. If the value is 0 then the duration of the message will be the default MesageDelay value specified in rulesmd.ini.
  • Be aware a message can't show more than 6 lines so if [AITargetTypes] contains more than 5 map objects then the first lines won't appear.

In mycampaign.map:

[Actions]
...
ID=ActionCount,[Action1],507,4,[CSFKey],[HouseIndex],[AIHousesListsIndex],[AITargetTypesIndex],[MesageDelay],A,[ActionX]
...

--- Example 1 ---
507,4,0,5,0,-39,30,A

  • No CSF entry so it will show as first line "Remaining: ".
  • 5 is the index of a specific house in the map we want to count its objects.
  • 0 is ignored here because we mentioned previously an unique house.
  • -39 in this case is the entry 39 of [AITargetTypes] that only contain a SAM Turret defense. Because the value is negative the message won't appear the name of the structure.
  • 30 means the message duration will be half minute.

If tehre are 7 SAM turrets of that house with index "5" then the result would look like "Remaining: 7".

--- Example 2 ---
507,4,0,5,0,39,0,A

  • No CSF entry so it will show as first line "Remaining: ".
  • 5 is the index of a specific house in the map we want to count its objects.
  • 0 is ignored here because we mentioned previously an unique house.
  • 39 in this case is the entry 39 of [AITargetTypes] that only contain a SAM Turret defense and a Laser defense. Because the value is positive the message will show the name of the map objects.
  • 0 means MesageDelay value will be the default specified in rulesmd.ini.

If there are 7 SAM turrets & 2 Laser defenses of that house with index "5" then the result would look like:
"Remaining:
SAM Turret: 7
Laser Turret: 2"

Copy link

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.

Copy link
Contributor

@MortonPL MortonPL left a comment

Choose a reason for hiding this comment

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

I don't think this is ready to be used as of now. Refer to review comments and compiler warnings.

// Multiplayer house index (Player@A - Player@H)
param3 = pThis->Param3 - HouseClass::PlayerAtA;
}
else if (pThis->Param3 - 8997 == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
else if (pThis->Param3 - 8997 == 0)
else if (pThis->Param3 == 8997)

// Obtain houses
int param3 = pThis->Param3;

if (pThis->Param3 - HouseClass::PlayerAtA >= 0 && pThis->Param3 - HouseClass::PlayerAtA < 8997)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (pThis->Param3 - HouseClass::PlayerAtA >= 0 && pThis->Param3 - HouseClass::PlayerAtA < 8997)
if (pThis->Param3 >= HouseClass::PlayerAtA && pThis->Param3 <= HouseClass::PlayerAtH)

Comment on lines +466 to +475
else if (pThis->Param3 > 8997)
{
Debug::Log("Map action %d: Invalid house index '%d'. This action will be skipped.\n", (int)pThis->ActionKind, pThis->Param3);
return true;
}

if (param3 >= 0)
{
pHousesList.push_back(HouseClass::Array->GetItem(param3));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we have only 4 houses, but set this param to i.e. 6? Or 5000?

return true;
// Example:
// ID=ActionCount,[Action1],507,4,[CSFKey],[HouseIndex],[AIHousesLists Index],[AITargetTypes Index],[MesageDelay],A,[ActionX]
std::vector<HouseClass*> pHousesList;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a pointer, so it shouldn't have the p prefix.

@@ -66,6 +67,7 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)

const char* sectionAITargetTypes = "AITargetTypes";
const char* sectionAIScriptsList = "AIScriptsList";
const char* sectionAIHousesList = "AIHousesList";
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it called AIHousesList when it lists house types and not houses, and got nothing to do with being AI controlled?

Comment on lines +540 to +544
if (pTechno->Owner == pHouse)
{
globalRemaining++;
nRemaining++;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a break here as there can be only one owner of an object.

Comment on lines +558 to +564
if (globalRemaining > 0)
{
wchar_t strInteger[24] = { 0 };
swprintf_s(strInteger, L"%d", globalRemaining);
wcscat_s(message, strInteger);
textToShow = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

When there are no remaining objects, nothing will be printed. Is this intentional? If so, then it should be explicitly mentioned in the documentation.

Comment on lines +572 to +573
if (technosRemaining[i] == 0)
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as the previous comment about skipping 0 objects.

Comment on lines +490 to +491
if (listIdx >= 0)
housesList = RulesExt::Global()->AIHousesLists.at(listIdx);
Copy link
Contributor

Choose a reason for hiding this comment

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

What if index is bigger than the number of elements?

Comment on lines +577 to +579
- If `HouseIndex` is set `-1` then `[AIHousesListsIndex]` will be used as index of a list of countries in the `[AIHousesList]` section located in `rulesmd.ini`. If any map object match the ownership with one of the list it will be counted.
- `[AITargetTypesIndex]` is the index of an entry in the `[AITargetTypes]` section located in `rulesmd.ini`. Each alive map object listed here will be counted.
- If `[AITargetTypesIndex]` is negative this value will be evaluated as a positive index in `[AITargetTypesIndex]` but instead of printing a list of alive map objects and the respective count it will appear as an unique global count of all the alive map objects listed in `[AITargetTypes]`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't say I'm a fan of controlling behavior like that. IMO it's better to have multiple actions with different behavior and well defined parameters.

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

2 participants