Project

General

Profile

Feature #1482 ยป 0091-tile.-ch-Replace-NULL-with-nullptr.patch

Marko Lindqvist, 06/03/2025 04:34 AM

View differences:

common/tile.c
#ifndef tile_owner
/************************************************************************//**
Return the player who owns this tile (or NULL if none).
Return the player who owns this tile (or nullptr if none).
****************************************************************************/
struct player *tile_owner(const struct tile *ptile)
{
......
#ifndef tile_claimer
/************************************************************************//**
Return the player who owns this tile (or NULL if none).
Return the player who owns this tile (or nullptr if none).
****************************************************************************/
struct tile *tile_claimer(const struct tile *ptile)
{
......
#endif
/************************************************************************//**
Set the owner of a tile (may be NULL).
Set the owner of a tile (may be nullptr).
****************************************************************************/
void tile_set_owner(struct tile *ptile, struct player *pplayer,
struct tile *claimer)
{
if (BORDERS_DISABLED != game.info.borders
/* City tiles are always owned by the city owner. */
|| (tile_city(ptile) != NULL || ptile->owner != NULL)) {
|| (tile_city(ptile) != nullptr || ptile->owner != nullptr)) {
ptile->owner = pplayer;
ptile->claimer = claimer;
}
}
/************************************************************************//**
Return the city on this tile (or NULL), checking for city center.
Return the city on this tile (or nullptr), checking for city center.
****************************************************************************/
struct city *tile_city(const struct tile *ptile)
{
struct city *pcity = ptile->worked;
if (NULL != pcity && is_city_center(pcity, ptile)) {
if (pcity != nullptr && is_city_center(pcity, ptile)) {
return pcity;
}
return NULL;
return nullptr;
}
#ifndef tile_worked
/************************************************************************//**
Return any city working the specified tile (or NULL).
Return any city working the specified tile (or nullptr).
****************************************************************************/
struct city *tile_worked(const struct tile *ptile)
{
......
#endif
/************************************************************************//**
Set the city/worker on the tile (may be NULL).
Set the city/worker on the tile (may be nullptr).
****************************************************************************/
void tile_set_worked(struct tile *ptile, struct city *pcity)
{
......
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
{
/* The terrain change is valid if one of the following is TRUE:
* - pterrain is NULL (= unknown terrain)
* - pterrain is nullptr (= unknown terrain)
* - ptile is a virtual tile, or otherwise not on the map being checked
* - pterrain does not has the flag TER_NO_CITIES
* - there is no city on ptile
......
/* Assert disabled for now, so we don't need to make this function
* care about what map is being changed. */
#if 0
fc_assert_msg(NULL == pterrain
fc_assert_msg(pterrain == nullptr
|| !is_server()
|| !tile_map_check(nmap, ptile)
|| !terrain_has_flag(pterrain, TER_NO_CITIES)
|| NULL == tile_city(ptile),
|| tile_city(ptile) == nullptr,
"At (%d, %d), the terrain \"%s\" (nb %d) doesn't "
"support cities, whereas \"%s\" (nb %d) is built there.",
TILE_XY(ptile), terrain_rule_name(pterrain),
......
#endif /* 0 */
ptile->terrain = pterrain;
if (ptile->resource != NULL) {
if (NULL != pterrain
if (ptile->resource != nullptr) {
if (pterrain != nullptr
&& terrain_has_resource(pterrain, ptile->resource)) {
BV_SET(ptile->extras, extra_index(ptile->resource));
} else {
......
}
/************************************************************************//**
Returns a bit vector of the extras present at NULL tile.
Returns a bit vector of the extras present at nullptr tile.
****************************************************************************/
const bv_extras *tile_extras_null(void)
{
......
return; /* No change */
}
if (ptile->resource != NULL) {
if (ptile->resource != nullptr) {
tile_remove_extra(ptile, ptile->resource);
}
if (presource != NULL) {
if (presource != nullptr) {
if (ptile->terrain && terrain_has_resource(ptile->terrain, presource)) {
tile_add_extra(ptile, presource);
}
......
const struct extra_type *tgt)
{
struct terrain *pterrain = tile_terrain(ptile);
int eff = get_target_bonus_effects(NULL,
int eff = get_target_bonus_effects(nullptr,
&(const struct req_context) {
.tile = ptile,
.activity = activity,
.extra = tgt
}, NULL, EFT_ACTIVITY_TIME);
}, nullptr, EFT_ACTIVITY_TIME);
fc_assert(tgt != NULL || !is_targeted_activity(activity));
fc_assert(tgt != nullptr || !is_targeted_activity(activity));
if (eff > 0) {
/* Use effect provided value */
......
****************************************************************************/
static void tile_create_extra(struct tile *ptile, struct extra_type *pextra)
{
if (fc_funcs->create_extra != NULL) {
if (fc_funcs->create_extra != nullptr) {
/* Assume callback calls tile_add_extra() itself. */
fc_funcs->create_extra(ptile, pextra, NULL);
fc_funcs->create_extra(ptile, pextra, nullptr);
} else {
tile_add_extra(ptile, pextra);
}
......
****************************************************************************/
static void tile_destroy_extra(struct tile *ptile, struct extra_type *pextra)
{
if (fc_funcs->destroy_extra != NULL) {
if (fc_funcs->destroy_extra != nullptr) {
/* Assume callback calls tile_remove_extra() itself. */
fc_funcs->destroy_extra(ptile, pextra);
} else {
......
}
/************************************************************************//**
Build irrigation on the tile. This may change the extras of the tile
Build irrigation on the tile. This may change the extras of the tile
or change the terrain type itself.
****************************************************************************/
static void tile_irrigate(struct tile *ptile, struct extra_type *tgt)
{
fc_assert(tgt != NULL);
fc_assert(tgt != nullptr);
if (tgt != NULL) {
if (tgt != nullptr) {
tile_extra_apply(ptile, tgt);
}
}
/************************************************************************//**
Build a mine on the tile. This may change the extras of the tile
Build a mine on the tile. This may change the extras of the tile
or change the terrain type itself.
****************************************************************************/
static void tile_mine(struct tile *ptile, struct extra_type *tgt)
{
fc_assert(tgt != NULL);
fc_assert(tgt != nullptr);
if (tgt != NULL) {
if (tgt != nullptr) {
tile_extra_apply(ptile, tgt);
}
}
......
****************************************************************************/
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
{
if (pextra != NULL) {
if (pextra != nullptr) {
BV_SET(ptile->extras, extra_index(pextra));
}
}
......
****************************************************************************/
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
{
if (pextra != NULL) {
if (pextra != nullptr) {
BV_CLR(ptile->extras, extra_index(pextra));
if (ptile->resource == pextra) {
ptile->resource = NULL;
ptile->resource = nullptr;
}
}
}
......
{
bool changed = FALSE;
/* Handle empty label as NULL label */
if (label != NULL && label[0] == '\0') {
label = NULL;
/* Handle empty label as nullptr label */
if (label != nullptr && label[0] == '\0') {
label = nullptr;
}
if (ptile->label != NULL) {
if (label == NULL) {
if (ptile->label != nullptr) {
if (label == nullptr) {
changed = TRUE;
} else if (strcmp(ptile->label, label)) {
changed = TRUE;
}
FC_FREE(ptile->label);
ptile->label = NULL;
} else if (label != NULL) {
ptile->label = nullptr;
} else if (label != nullptr) {
changed = TRUE;
}
if (label != NULL) {
if (label != nullptr) {
if (strlen(label) >= MAX_LEN_MAP_LABEL) {
log_error("Overlong map label '%s'", label);
}
......
****************************************************************************/
bool tile_is_placing(const struct tile *ptile)
{
return ptile->placing != NULL;
return ptile->placing != nullptr;
}
common/tile.h
* (index_to_native_pos()). */
Continent_id continent;
bv_extras extras;
struct extra_type *resource; /* NULL for no resource */
struct terrain *terrain; /* NULL for unknown tiles */
struct extra_type *resource; /* nullptr for no resource */
struct terrain *terrain; /* nullptr for unknown tiles */
struct unit_list *units;
struct city *worked; /* NULL for not worked */
struct player *owner; /* NULL for not owned */
struct city *worked; /* nullptr for not worked */
struct player *owner; /* nullptr for not owned */
struct extra_type *placing;
int infra_turns;
struct player *extras_owner;
struct tile *claimer;
int altitude;
char *label; /* NULL for no label */
char *label; /* nullptr for no label */
char *spec_sprite;
};
......
#define tile_resource(_tile) ((_tile)->resource)
static inline bool tile_resource_is_valid(const struct tile *ptile)
{ return ptile->resource != NULL
{ return ptile->resource != nullptr
&& BV_ISSET(ptile->extras, ptile->resource->id);
}
/* const struct resource *tile_resource(const struct tile *ptile); */
    (1-1/1)