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

Pirating state of trade routes not saved/loaded #131

Closed
LynxAbraxas opened this issue May 3, 2019 · 2 comments
Closed

Pirating state of trade routes not saved/loaded #131

LynxAbraxas opened this issue May 3, 2019 · 2 comments

Comments

@LynxAbraxas
Copy link
Contributor

Now that #127 is in, it seems that the pirating states of trade routes are not saved/loaded. E.g. when pirating in the test-game of #75, ending the turn then the trade manager shows the pirating color orange. However when saving and re-loading that game, the pirating column color is back to white.
Same holds for the action: pirating in the test-game then save and load before ending the turn will lead to no pirating for blue in the next turn.
I'd guess that the m_piratingArmy from

void TradeRouteData::SetPiratingArmy(Army &a)
{
m_piratingArmy = a;
}

is not saved, not sure about m_isPirating here
archive.PutUINT8(m_isPirating);

at least allown this would not be enough since IsBeingPirated needs m_piratingArmy
bool TradeRouteData::IsBeingPirated()
{
return m_piratingArmy.IsValid();
}

@MartinGuehmann What do you think?

@MartinGuehmann
Copy link
Collaborator

The problem is that m_piratingArmy is not saved.

TradeRouteData::Serialize(CivArchive &archive)
{
if(archive.IsStoring()) {
archive << m_id;
archive << m_transportCost;
archive << m_owner;
archive.PutSINT32(m_sourceRouteType);
archive << m_sourceResource;
archive.Store((uint8 *)m_passesThrough, sizeof(m_passesThrough)) ;
archive.PutSINT32(m_crossesWater) ;
archive.PutSINT8(static_cast<sint8>(m_isActive));
archive.PutUINT32(m_color);
archive.PutUINT32(m_outline);
archive.PutSINT32(m_selectedIndex);
archive.PutSINT32(m_path_selection_state);
archive.PutSINT32(m_valid);
archive << m_payingFor;
archive << m_gold_in_return;
m_sourceCity.Serialize(archive);
m_destinationCity.Serialize(archive);
m_recip.Serialize(archive);
m_path.Serialize(archive);
m_wayPoints.Serialize(archive) ;
m_selectedPath.Serialize(archive);
m_selectedWayPoints.Serialize(archive);
m_astarPath->Serialize(archive);
m_setPath.Serialize(archive);
m_setWayPoints.Serialize(archive);
uint8 hasChild;
hasChild = m_lesser != NULL;
archive << hasChild;
if (m_lesser) {
((TradeRouteData *)(m_lesser))->Serialize(archive) ;
}
hasChild = m_greater != NULL;
archive << hasChild;
if (m_greater)
((TradeRouteData *)(m_greater))->Serialize(archive) ;
} else {
archive >> m_id;
archive >> m_transportCost;
archive >> m_owner;
m_sourceRouteType = (ROUTE_TYPE)(archive.GetSINT32()) ;
archive >> m_sourceResource;
archive.Load((uint8 *)m_passesThrough, sizeof(m_passesThrough)) ;
m_crossesWater = (BOOL)(archive.GetSINT32()) ;
m_isActive = (BOOL)(archive.GetSINT8());
m_color = archive.GetUINT32();
m_outline = archive.GetUINT32();
m_selectedIndex = archive.GetSINT32();
m_path_selection_state = archive.GetSINT32();
m_valid = archive.GetSINT32();
archive >> m_payingFor;
archive >> m_gold_in_return;
m_sourceCity.Serialize(archive);
m_destinationCity.Serialize(archive);
m_recip.Serialize(archive);
m_path.Serialize(archive);
m_wayPoints.Serialize(archive) ;
m_selectedPath.Serialize(archive);
m_selectedWayPoints.Serialize(archive);
m_astarPath->Serialize(archive);
m_setPath.Serialize(archive);
m_setWayPoints.Serialize(archive);
uint8 hasChild;
archive >> hasChild;
if (hasChild) {
m_lesser = new TradeRouteData(archive);
} else {
m_lesser = NULL;
}
archive >> hasChild;
if (hasChild)
m_greater = new TradeRouteData(archive);
else
m_greater = NULL;
}
}

You can reuse the slot of m_path_selection_state, it also occupies 32 bits like Army.

So you have to replace the lines

archive.PutSINT32(m_path_selection_state);
m_path_selection_state = archive.GetSINT32();

by

m_piratingArmy.Serialize(archive);

each.

Possible values for m_path_selection_state are 0, 1, and 2. Actually, it is also somewhere in the code set, but it is not used. So it shouldn't be a problem to reuse the spot. 0, 1, and 2 are not valid IDs for armies, IsValid should care about it.

LynxAbraxas added a commit to LynxAbraxas/civctp2 that referenced this issue May 4, 2019
@LynxAbraxas
Copy link
Contributor Author

Solved with #132, many thanks @MartinGuehmann.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants