OpenXcom Forum
Contributions => Programming => Topic started by: Fenyő on October 22, 2012, 10:10:00 pm
-
As i suggested this - Save Equipment - feature (https://openxcom.org/forum/index.php/topic,655.msg6698.html#msg6698), i want to discuss about its implementation.
I've ispected the code which deploys the items, and i have some ideas.
I think the code of this feature should start in BattlescapeGenerator::run(), in line 344.
We have to copy the for-cycle in lines 346-349, and put the copy before that cycle.
Because we have to sweep the soldiers first with the layout restoration, and after that we fill in the holes with the for-cycle with the classic auto-equip.
We need a new BattlescapeGenerator::addItem(BattleItem *item). (for eg. with a name addItemWithLayout or we can make a new overload of the name addItem)
This new method sweeps the soldiers with a cycle and finds the first empty slot (which corresponds to the layout stored) for the item, and places it there.
I think we need to save the layout on a per-soldier basis.
Of course we need to save the primed-state of a grenade, and ammo-state of a weapon with the layout.
And of course we need to save the layout to the savegame, WITH backwards compatibility, i mean that this layout can be absent (per-soldier) in the savegame. (and in the memory when a game is loaded)
What i'm unsure right now, is how do we need to store the layout?
My ideas:
std::map<std::string, std::string>
std::map<RuleInventory, BattleItem>
std::map<BattleItem, RuleInventory>
Or maybe i could make a new class to store these relations? :)
Any ideas? Daiky? Or anyone?
-
I've moved that posts out of Battlescape development - let's not steal Daiky's thread ;)
-
But this thing is a Battlescape development related issue, this is why i put it there instead of new topic.
-
I know, but "Battlescape development" topic was created by Daiky so he could write about his progress. Also, you've changed topic subject with your post.
-
Ok, i've done this! (PR) :)
The layout of the equipments is saved when clicking on the OK button in the inventory-view. (only when mission starts)
And it loads it back on the start of the next mission. (before the first inventory-view)
The layout is also stored in the savegame file.
And this feature is backwards compatible, i mean it can read savegames without layouts. (and then start using them)
Auto-equip now only works on a soldier if there is no layout for the soldier we are talking about.
Only two situations can lead to this:
1) The soldier has no layout yet (perhaps a new soldier)
2) The soldier has started a mission previously with a completely empty inventory.
If there is not enough equipment on board to the full layout, then only the parts in the layout which are on-board are getting to be placed only. If this means a soldier getting none, then that soldier's inventory will be clear. (and user needs to equip it manually)
I introduced unpriming grenades (right-click also) in the inventory-view. (mission-start only)
This is needed because the primed state is also stored in the layouts, :)
and of course we must give the user the opportunity to change this aspect of the layout.