MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / populateInventoryItemsBase

Method populateInventoryItemsBase

game/ui/general/aequipscreen.cpp:897–970  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

895}
896
897void AEquipScreen::populateInventoryItemsBase()
898{
899 // Expecting to have an agent and that agent to have a base
900 auto currentAgent = selectedAgents.front();
901
902 // The gap between the end of one inventory image and the start of the next
903 static const int INVENTORY_IMAGE_X_GAP = 4;
904 Vec2<int> inventoryPosition = inventoryControl->Location + formMain->Location;
905
906 // Find base which is in the current building
907 StateRef<Base> base = getAgentBase(currentAgent);
908
909 for (auto &invPair : base->inventoryAgentEquipment)
910 {
911 StateRef<AEquipmentType> type = {state.get(), invPair.first};
912
913 // Skip wrong types
914 bool showArmor = formMain->findControlTyped<RadioButton>("BUTTON_SHOW_ARMOUR")->isChecked();
915 bool showOther =
916 formMain->findControlTyped<RadioButton>("BUTTON_SHOW_WEAPONS")->isChecked();
917 if (type->type == AEquipmentType::Type::Armor && !showArmor)
918 {
919 continue;
920 }
921 if (type->type != AEquipmentType::Type::Armor && !showOther)
922 {
923 continue;
924 }
925
926 // Find the item count
927 int count = 0;
928 int ammoRemaining = 0;
929 if (type->type == AEquipmentType::Type::Ammo)
930 {
931 count = invPair.second / type->max_ammo;
932 ammoRemaining = invPair.second - count * type->max_ammo;
933 if (ammoRemaining > 0)
934 {
935 count++;
936 }
937 }
938 else
939 {
940 count = invPair.second;
941 }
942
943 if (count == 0)
944 {
945 continue;
946 }
947
948 auto &equipmentImage = type->equipscreen_sprite;
949 Vec2<int> inventoryEndPosition = inventoryPosition;
950 inventoryEndPosition.x += equipmentImage->size.x;
951 inventoryEndPosition.y += equipmentImage->size.y;
952
953 auto equipment = mksp<AEquipment>();
954 equipment->type = type;

Callers

nothing calls this directly

Calls 3

isCheckedMethod · 0.80
emptyMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected