Skip to content

Commit

Permalink
Make compilable with modern compiler (clang-3.4.1):
Browse files Browse the repository at this point in the history
	. Resolve all of the warnings having to do with string
	  literals used as "char *" -- by changing them to
	  "const char *" throughout.
	. The above allowed to for much more straightforward
	  API-calls in various places, where before the string
	  literal would be first copied into a local variable --
	  pass the literal to the function, that now accepts
	  const anyway.
	. Remove the vast number of unused variables.
	. Remove references to <malloc.h> -- the file was removed
	  from the standard collection in the last millennium.
	. Make compilable on FreeBSD (hopefully, other BSDs would
	  work too).
	. Fixes to autotools glue to please the modern versions of
	  the tools.
	. Fixes to CivPaths to avoid crashing if data-files aren't
	  found at startup

To be continued...


git-svn-id: http://ctp2.darkdust.net/anonsvn/branches/linux@1117 34d2fc0c-33df-0310-8a34-85f8040ba873
  • Loading branch information
mi committed May 23, 2016
1 parent da6e30e commit 88eb706
Show file tree
Hide file tree
Showing 667 changed files with 4,345 additions and 7,773 deletions.
8 changes: 1 addition & 7 deletions configure.ac
Expand Up @@ -7,7 +7,7 @@ AC_CONFIG_AUX_DIR(ctp2_code/os/autoconf/config)
AC_CANONICAL_HOST
AC_CANONICAL_TARGET

AM_INIT_AUTOMAKE
AM_INIT_AUTOMAKE([subdir-objects])
AM_CONFIG_HEADER(ctp2_code/os/include/config.h)
AM_MAINTAINER_MODE
AC_PROG_MAKE_SET
Expand Down Expand Up @@ -87,12 +87,6 @@ AC_PATH_PROG(PERL,perl)
AC_PATH_PROG(THUMBPDF,thumbpdf)
AC_PATH_PROGS(VIEWPDF,acroread gpdf)

for ac_remove_CFLAG in "-O1" "-O2" "-O3" ; do
CFLAGS=${CFLAGS//${ac_remove_CFLAG}/}
CPPFLAGS=${CPPFLAGS//${ac_remove_CFLAG}/}
CXXFLAGS=${CXXFLAGS//${ac_remove_CFLAG}/}
done

ctp2_code='$(top_srcdir)/ctp2_code'
AC_SUBST(ctp2_code)

Expand Down
25 changes: 7 additions & 18 deletions ctp2_code/ai/CityManagement/governor.cpp
Expand Up @@ -191,7 +191,7 @@ void Governor::ResizeAll(const PLAYER_INDEX & newMaxPlayerId)

s_theGovernors.resize(newMaxPlayerId);

for (size_t i = old_size; i < newMaxPlayerId; ++i)
for (size_t i = old_size; i < (size_t)newMaxPlayerId; ++i)
{
s_theGovernors[i].SetPlayerId(i);
}
Expand Down Expand Up @@ -408,7 +408,6 @@ sint32 Governor::ComputeBestGovernment() const
Player * player_ptr = g_player[m_playerId];
Assert(player_ptr != NULL);

bool config_found = false;
bool obsolete;
sint32 government_index = -1;
for (sint32 gov_index = 0; government_index == -1 && gov_index < strategy.GetNumGovernment(); gov_index++)
Expand Down Expand Up @@ -962,8 +961,7 @@ bool Governor::ComputeBestSliders(SlidersSetting & sliders_setting) const
bool Governor::FitSlidersToCities( SlidersSetting & sliders_setting ) const
{
Assert(m_playerId >= 0);
Player *player_ptr = g_player[m_playerId];
Assert(player_ptr);
Assert(g_player[m_playerId]);

bool production_test;
bool gold_test;
Expand All @@ -973,9 +971,6 @@ bool Governor::FitSlidersToCities( SlidersSetting & sliders_setting ) const

NormalizeSliders(sliders_setting);

const StrategyRecord & strategy =
Diplomat::GetDiplomat(m_playerId).GetCurrentStrategy();

bool found = false;
bool changed = true;

Expand Down Expand Up @@ -1498,11 +1493,8 @@ void Governor::ComputeRoadPriorities()




float total_cost = 0.0;
Path found_path;
double trans_max_r = 0.8;


if (g_city_astar.FindRoadPath(city_unit.RetPos(), min_neighbor_unit.RetPos(),
m_playerId,
Expand Down Expand Up @@ -1622,14 +1614,13 @@ void Governor::PlaceTileImprovements()

strategy.GetMaxEvalTileImprovements(max_eval);
max_eval = MIN(max_eval, (sint32)s_tiQueue.size());
TiGoalQueue::iterator max_iter = TiGoalQueue::iterator(&s_tiQueue[max_eval]);

std::partial_sort(s_tiQueue.begin(), max_iter, s_tiQueue.end(), std::greater<TiGoal>());
std::partial_sort(s_tiQueue.begin(), s_tiQueue.begin() + max_eval, s_tiQueue.end(), std::greater<TiGoal>());

sint32 avail_pw = player_ptr->GetMaterialsStored() - reserve_pw;

TiGoalQueue::const_iterator iter;
for(iter = s_tiQueue.begin(); iter != max_iter; iter++)
for(iter = s_tiQueue.begin(); iter != s_tiQueue.begin() + max_eval; iter++)
{
sint32 const needed_pw =
terrainutil_GetProductionCost(iter->type, iter->pos, 0);
Expand Down Expand Up @@ -4121,7 +4112,7 @@ sint32 Governor::GetNeededUnitType(const CityData *city, sint32 & list_num) cons

BUILD_UNIT_LIST max_list = BUILD_UNIT_LIST_MAX;
sint32 max_production = 0;
sint32 turns_to_build = 9999;
sint32 turns_to_build;
sint32 needed_production;
sint32 type = -1;
sint32 cont;
Expand All @@ -4134,8 +4125,6 @@ sint32 Governor::GetNeededUnitType(const CityData *city, sint32 & list_num) cons
strategy.GetBuildTransportProductionLevel(build_transport_production_level);
strategy.GetBuildSettlerProductionLevel(build_settler_production_level);

bool can_build_settler = false;

for (list_num = 0; list_num < BUILD_UNIT_LIST_MAX; list_num++)
{

Expand Down Expand Up @@ -4227,7 +4216,9 @@ sint32 Governor::GetNeededUnitType(const CityData *city, sint32 & list_num) cons
}
}

#ifdef _DEBUG
UnitRecord const * unit = g_theUnitDB->Get(type);
#endif
DPRINTF(k_DBG_GAMESTATE, ("Selected unit type: %s\n", unit ? unit->GetNameText() : "none"));
DPRINTF(k_DBG_GAMESTATE, ("Player: %lx\n", m_playerId));

Expand Down Expand Up @@ -4635,8 +4626,6 @@ void Governor::ManageGoodsTradeRoutes()
Assert(g_player[m_playerId] != NULL);
Player *player_ptr = g_player[m_playerId];

sint32 cur_round = player_ptr->GetCurRound();

Unit city;
sint32 i,g,d; // Are compared against sint32
UnitDynamicArray *city_list = player_ptr->GetAllCitiesList();
Expand Down
1 change: 0 additions & 1 deletion ctp2_code/ai/CityManagement/governor.h
Expand Up @@ -83,7 +83,6 @@ class CityData;
class BuildingBuildListRecord;
class BuildListSequenceRecord;
class WonderBuildListRecord;
class StrategyRecord::PopAssignmentElement;
class UnitBuildListRecord;

//----------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion ctp2_code/ai/ctp2/ctp2.h
Expand Up @@ -14,7 +14,6 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <malloc.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down
21 changes: 4 additions & 17 deletions ctp2_code/ai/ctpai.cpp
Expand Up @@ -488,8 +488,6 @@ void CtpAi::GroupWithEscort(const Army & army)
if (army.Num() > 1)
return;

PLAYER_INDEX playerId = army->GetOwner();

sint32 min_strength = -1;
sint32 tmp_strength;
Army min_army;
Expand Down Expand Up @@ -1601,10 +1599,7 @@ void CtpAi::UnGroupGarrisonUnits(const PLAYER_INDEX playerId)
MapPoint pos(city.RetPos());
g_theWorld->GetArmy(pos, garrison);

sint32 min_size = k_MAX_ARMY_SIZE;

for (sint32 j = 0; j < garrison.Num(); ++j)
{
for (sint32 j = 0; j < garrison.Num(); ++j) {
//there is a problem to determine if units are in garrison or just pathing through the city
// If fear it will also ungroup all the units of the tile (garrison points on a cellunitlist that
// cannot know which units is group tu another.
Expand Down Expand Up @@ -1836,7 +1831,6 @@ void CtpAi::NetworkClientBeginTurn(PLAYER_INDEX player)
void CtpAi::Resize()
{

sint32 old_player_count = s_maxPlayers;
s_maxPlayers = 0;
sint32 index;
for(index = 0; index < k_MAX_PLAYERS; index++) {
Expand Down Expand Up @@ -2028,8 +2022,7 @@ void CtpAi::AddMiscMapTargets(const PLAYER_INDEX playerId)
const StrategyRecord & strategy =
Diplomat::GetDiplomat(playerId).GetCurrentStrategy();

Player *player_ptr = g_player[playerId];
Assert(player_ptr);
Assert(g_player[playerId]);

CTPGoal_ptr goal_ptr;

Expand Down Expand Up @@ -2088,8 +2081,6 @@ void CtpAi::AddMiscMapTargets(const PLAYER_INDEX playerId)

void CtpAi::ComputeCityGarrisons(const PLAYER_INDEX playerId )
{
sint32 committed_units = 0;

Unit city;
MapPoint pos;
Army army;
Expand Down Expand Up @@ -2343,8 +2334,7 @@ bool CtpAi::GetNearestRefuel(const Army & army, const MapPoint & start_pos, MapP

if (refueling_distance < 0)
{
bool NO_REFUEL_DESTINATION = false;
Assert(NO_REFUEL_DESTINATION);
Assert(!"NO_REFUEL_DESTINATION");
return false;
}
return true;
Expand Down Expand Up @@ -2389,9 +2379,7 @@ void CtpAi::RefuelAirplane(const Army & army)
new_path,
total_cost))
{

bool NO_REFUEL_PATH = false;
Assert(NO_REFUEL_PATH);
Assert(!"NO_REFUEL_PATH");
return;
}

Expand Down Expand Up @@ -2420,7 +2408,6 @@ void CtpAi::ExecuteOpportunityActions(const PLAYER_INDEX player)
if (player_ptr == NULL)
return;
sint32 num_armies = player_ptr->m_all_armies->Num();
sint32 num_cities = player_ptr->m_all_cities->Num();
Army army;


Expand Down
6 changes: 0 additions & 6 deletions ctp2_code/ai/diplomacy/RejectResponseEvent.cpp
Expand Up @@ -35,7 +35,6 @@ STDEHANDLER(NoThreat_RejectResponseEvent)
return GEV_HD_Continue;

Diplomat & sender_diplomat = Diplomat::GetDiplomat(sender);
Diplomat & receiver_diplomat = Diplomat::GetDiplomat(receiver);

if (1) {
Response response;
Expand All @@ -57,9 +56,6 @@ STDEHANDLER(NoThreat_RejectResponseEvent)
return GEV_HD_Continue;
}




STDEHANDLER(ThreatenAlliedInvasion_RejectResponseEvent)
{
PLAYER_INDEX sender;
Expand All @@ -72,7 +68,6 @@ STDEHANDLER(ThreatenAlliedInvasion_RejectResponseEvent)
return GEV_HD_Continue;

Diplomat & sender_diplomat = Diplomat::GetDiplomat(sender);
Diplomat & receiver_diplomat = Diplomat::GetDiplomat(receiver);

const NewProposal & sender_proposal =
sender_diplomat.GetMyLastNewProposal(receiver);
Expand All @@ -89,7 +84,6 @@ STDEHANDLER(ThreatenAlliedInvasion_RejectResponseEvent)
allyId = foreignerId;
}


if (allyId != -1) {
Response response;

Expand Down
10 changes: 0 additions & 10 deletions ctp2_code/ai/diplomacy/counterresponseevent.cpp
Expand Up @@ -63,7 +63,6 @@ STDEHANDLER(ThreatenAttackCity_CounterResponseEvent)
Diplomat & sender_diplomat = Diplomat::GetDiplomat(sender);
Diplomat & receiver_diplomat = Diplomat::GetDiplomat(receiver);

const NewProposal & proposal = sender_diplomat.GetMyLastNewProposal(receiver);
const Response & response = receiver_diplomat.GetMyLastResponse(sender);

if ( AgreementMatrix::s_agreements.HasAgreement(sender,
Expand Down Expand Up @@ -202,15 +201,9 @@ STDEHANDLER(PayForGiveCity_CounterResponseEvent)
response.counter.first_type != PROPOSAL_REQUEST_GIVE_CITY )
return GEV_HD_Continue;




sint32 at_risk_value_percent =
MapAnalysis::GetMapAnalysis().AtRiskCitiesValue(receiver,sender);

sint32 at_risk_value = (sint32) ((double)at_risk_value_percent / 100.0) *
MapAnalysis::GetMapAnalysis().TotalValue(receiver);

sint32 accept_priority =
sender_diplomat.GetAcceptPriority(receiver, response.counter.second_type);

Expand Down Expand Up @@ -351,7 +344,6 @@ STDEHANDLER(AdvanceForGold_CounterResponseEvent)
Diplomat & sender_diplomat = Diplomat::GetDiplomat(sender);
Diplomat & receiver_diplomat = Diplomat::GetDiplomat(receiver);

const NewProposal & sender_proposal = sender_diplomat.GetMyLastNewProposal(receiver);
const Response & receiver_response = receiver_diplomat.GetMyLastResponse(sender);

if ( receiver_response.type != RESPONSE_COUNTER ||
Expand Down Expand Up @@ -435,7 +427,6 @@ STDEHANDLER(ActionForValue_CounterResponseEvent)
Diplomat & sender_diplomat = Diplomat::GetDiplomat(sender);
Diplomat & receiver_diplomat = Diplomat::GetDiplomat(receiver);

const NewProposal & sender_proposal = sender_diplomat.GetMyLastNewProposal(receiver);
const Response & receiver_response = receiver_diplomat.GetMyLastResponse(sender);

sint32 turns_since_last_war = AgreementMatrix::s_agreements.TurnsSinceLastWar(sender, receiver);
Expand Down Expand Up @@ -542,7 +533,6 @@ STDEHANDLER(ReciprocateAction_CounterResponseEvent)
Diplomat & sender_diplomat = Diplomat::GetDiplomat(sender);
Diplomat & receiver_diplomat = Diplomat::GetDiplomat(receiver);

const NewProposal & sender_proposal = sender_diplomat.GetMyLastNewProposal(receiver);
const Response & receiver_response = receiver_diplomat.GetMyLastResponse(sender);

if ( receiver_response.type != RESPONSE_COUNTER ||
Expand Down

0 comments on commit 88eb706

Please sign in to comment.