cmd = (struct Command *) parse_init_entry(&cmd_flags,
sizeof(struct Command));
cmd->dsc_short = strdup(token1);
- parse_id_uniq(NULL != get_command(cmd->dsc_short));
+ parse_id_uniq(!(!get_command(cmd->dsc_short)));
}
else if (!( parse_flagval(token0, token1, "DESCRIPTION", &cmd_flags,
DESC_SET, 's', (char *) &cmd->dsc_long)
}
*win = (struct Win *) parse_init_entry(win_flags, sizeof(struct Win));
parsetest_singlechar(token1);
- parse_id_uniq(world.winDB.ids && (NULL!=strchr(world.winDB.ids,token1[0])));
+ parse_id_uniq(world.winDB.ids && strchr(world.winDB.ids,token1[0]));
(*win)->id = token1[0];
return 1;
}
}
kb.keycode = atoi(token1);
char * err_uniq = "Binding to key already defined.";
- err_line(NULL != get_command_to_keycode(kbdb, kb.keycode), err_uniq);
+ err_line(!(!get_command_to_keycode(kbdb, kb.keycode)), err_uniq);
kb.command = get_command(token2);
err_line(!(kb.command), "No such command in command DB.");
array_append(kbdb->n_of_kbs, sizeof(struct KeyBinding), (void *) &kb,
break;
}
int old_size = 0;
- if (NULL != world.player_inventory)
+ if (world.player_inventory)
{
old_size = strlen(world.player_inventory);
}
while (try_fgets(read_buf, linemax + 1, file, __func__))
{
int old_size = 0;
- if (NULL != world.log)
+ if (world.log)
{
old_size = strlen(world.log);
}
char * errline_line = try_malloc(linemax + 1, __func__);
set_err_line_options(errline_intro, errline_line, 1);
err_line_zero();
- err_line(0 == linemax, "File is empty.");
+ err_line(!linemax, "File is empty.");
char * token0 = NULL; /* For final token_to_entry() if while() stagnates. */
char * token1 = NULL;
char * err_val = "No value given.";
extern void parsetest_too_many_values()
{
- err_line(NULL != token_from_line(NULL), "Too many values.");
+ err_line(!(!token_from_line(NULL)), "Too many values.");
}
extern void toggle_window(char id)
{
struct Win * win = get_win_by_id(id);
- if (NULL == strchr(world.winDB.order, id))
+ if (!strchr(world.winDB.order, id))
{
append_win(win);
return;
world.winDB.v_screen_size.y = maxy_test;
world.winDB.v_screen_size.x = maxx_test;
world.winDB.v_screen = newpad(world.winDB.v_screen_size.y, 1);
- exit_trouble(NULL == world.winDB.v_screen, __func__, err_m);
+ exit_trouble(!world.winDB.v_screen, __func__, err_m);
char id;
while (0 != (id = get_next_win_id()))
{
int test = sprintf(msg, "%s%s%s%s%s%s%s", msg1,f,msg2,mode,msg3,path,msg4);
exit_trouble(test < 0, __func__, "sprintf");
FILE * file_p = fopen(path, mode);
- exit_err(NULL == file_p, msg);
+ exit_err(!file_p, msg);
free(msg);
return file_p;
}
extern char * try_fgets(char * line, int linemax, FILE * file, const char * f)
{
char * test = fgets(line, linemax, file);
- exit_trouble(NULL == test && ferror(file), f, "fgets");
+ exit_trouble(!test && ferror(file), f, "fgets");
return test;
}
return;
}
cleanup_func();
- if (NULL == msg)
+ if (!msg)
{
msg = "Details unknown.";
}
{
char * prefix = "Trouble with malloc in ";
char * msg = malloc(strlen(prefix) + strlen(f) + 1 + 1);
- exit_err(NULL == msg,
+ exit_err(!msg,
"Trouble in try_malloc with malloc for error message string.");
int test = sprintf(msg, "%s%s.", prefix, f);
exit_err(test < 0, "Trouble in try_malloc with sprintf.");
void * p = malloc(size);
- exit_err(NULL == p, msg); /* Bypass exit_trouble() calling try_malloc(). */
+ exit_err(!p, msg); /* Bypass exit_trouble() calling try_malloc(). */
free(msg);
return p;
}
/* src/server/ai.c */
#include "ai.h"
-#include <stddef.h> /* NULL */
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, int16_t, UINT16_MAX */
#include <stdlib.h> /* free() */
#include "../common/try_malloc.h" /* try_malloc() */
int16_t selection = -1;
struct Thing * t = t_owner->owns;;
uint8_t i;
- for (i = 0; t != NULL; t = t->next, i++)
+ for (i = 0; t; t = t->next, i++)
{
struct ThingType * tt = get_thing_type(t->type);
if (tt->consumable > compare_consumability)
static uint8_t standing_on_consumable(struct Thing * t_standing)
{
struct Thing * t = world.things;
- for (; t != NULL; t = t->next)
+ for (; t; t = t->next)
{
if ( t != t_standing
&& t->pos.y == t_standing->pos.y && t->pos.x == t_standing->pos.x)
struct ThingInMemory * tm = t_eye->t_mem;
struct ThingInMemory * tm_prev = NULL;
struct ThingInMemory * tm_next = NULL;
- for (; tm != NULL; tm = tm_next)
+ for (; tm; tm = tm_next)
{
tm_next = tm->next;
if ('v' == t_eye->fov_map[tm->pos.y * world.map.length + tm->pos.x])
tm_prev = tm;
}
struct Thing * t = world.things;
- for (; t != NULL; t = t->next)
+ for (; t; t = t->next)
{
if ( !t->lifepoints
&& 'v' == t_eye->fov_map[t->pos.y * world.map.length + t->pos.x])
{
t = get_thing(world.things, id, 1);
char * err = "No thing type found to initialize new thing.";
- if (!t && !err_line(NULL == world.thing_types, err))
+ if (!t && !err_line(!world.thing_types, err))
{
t = add_thing(id, world.thing_types->id, 0, 0);
if (world.exists && t->lifepoints)
FILE * file = try_fopen(path, "r", __func__);
uint32_t linemax = textfile_width(file);
char * line = try_malloc(linemax + 1, __func__);
- while (NULL != try_fgets(line, linemax + 1, file, __func__))
+ while (try_fgets(line, linemax + 1, file, __func__))
{
if (strlen(line))
{
uint32_t linemax = textfile_width(file);
char * line = try_malloc(linemax + 1, __func__);
while ( world.turn < world.replay
- && NULL != try_fgets(line, linemax + 1, file, __func__))
+ && try_fgets(line, linemax + 1, file, __func__))
{
obey_msg(line, 0, 1);
err_line_inc();
{
uint8_t player_will_be_generated = 0;
struct ThingType * tt;
- for (tt = world.thing_types; NULL != tt; tt = tt->next)
+ for (tt = world.thing_types; tt; tt = tt->next)
{
if (world.player_type == tt->id)
{
free_things(world.things);
remake_map();
struct ThingType * tt;
- for (tt = world.thing_types; NULL != tt; tt = tt->next)
+ for (tt = world.thing_types; tt; tt = tt->next)
{
if (world.player_type == tt->id)
{
break;
}
}
- for (tt = world.thing_types; NULL != tt; tt = tt->next)
+ for (tt = world.thing_types; tt; tt = tt->next)
{
if (world.player_type != tt->id)
{
}
}
struct Thing * t;
- for (t = world.things; NULL != t; t = t->next)
+ for (t = world.things; t; t = t->next)
{
if (t->lifepoints)
{
static void write_inventory(struct Thing * player, FILE * file)
{
struct Thing * owned = player->owns;
- if (NULL == owned)
+ if (!owned)
{
char * empty = "(none)\n";
try_fwrite(empty, strlen(empty), 1, file, __func__);
else
{
uint8_t q;
- for (q = 0; NULL != owned; q++)
+ for (q = 0; owned; q++)
{
struct ThingType * tt = get_thing_type(owned->type);
try_fwrite(tt->name, strlen(tt->name), 1, file, __func__);
struct ThingInMemory * tm;
for (i = 0; i < 2; i++)
{
- for (tm = player->t_mem; tm != NULL; tm = tm->next)
+ for (tm = player->t_mem; tm; tm = tm->next)
{
if (' ' != player->mem_map[tm->pos.y*world.map.length+tm->pos.x])
{
while ( 0 < player->lifepoints
|| (0 == player->lifepoints && start_turn == world.turn))
{
- if (NULL == thing)
+ if (!thing)
{
world.turn++;
thing = world.things;
set_err_line_options("Trouble with message: ", msg, 0);
char * msg_copy = strdup(msg);
char * tok0 = token_from_line(msg_copy);
- if (NULL != tok0)
+ if (tok0)
{
if (parse_command(tok0))
record(msg, 0);
}
char * tokplus = token_from_line(NULL);
- err_line(NULL != tokplus, "Too many arguments, ignoring overflow.");
+ err_line(!(!tokplus), "Too many arguments, ignoring overflow.");
free(msg_copy);
return;
}
{
char * msg = io_round();
server_test();
- if (NULL == msg)
+ if (!msg)
{
continue;
}
extern void actor_drop(struct Thing * t)
{
- uint8_t owns_none = (NULL == t->owns);
+ uint8_t owns_none = (!t->owns);
if (!owns_none)
{
uint8_t select = t->arg;
{
struct Thing * picked = NULL;
struct Thing * t_i;
- for (t_i = world.things; NULL != t_i; t_i = t_i->next)
+ for (t_i = world.things; t_i; t_i = t_i->next)
{
if (t_i != t && yx_uint8_cmp(&t_i->pos, &t->pos))
{
picked = t_i;
}
}
- if (NULL != picked)
+ if (picked)
{
own_thing(&t->owns, &world.things, picked->id);
set_thing_position(picked, t->pos);
}
if (t == get_player())
{
- playerbonus_pick(NULL != picked);
+ playerbonus_pick(!(!picked));
}
}
extern void actor_use(struct Thing * t)
{
uint8_t wrong_thing = 1;
- uint8_t no_thing = (NULL == t->owns);
+ uint8_t no_thing = (!t->owns);
if (!no_thing)
{
uint8_t select = t->arg;
static void free_things_in_memory(struct ThingInMemory * tm)
{
- if (NULL == tm)
+ if (!tm)
{
return;
}
}
}
struct NextAndId ** nai_ptr_ptr = start;
- for (; NULL != * nai_ptr_ptr; nai_ptr_ptr = &(*nai_ptr_ptr)->next);
+ for (; * nai_ptr_ptr; nai_ptr_ptr = &(*nai_ptr_ptr)->next);
*nai_ptr_ptr = nai;
return nai;
}
extern void free_thing_actions(struct ThingAction * ta)
{
- if (NULL == ta)
+ if (!ta)
{
return;
}
extern void free_thing_types(struct ThingType * tt)
{
- if (NULL == tt)
+ if (!tt)
{
return;
}
extern void free_things(struct Thing * t)
{
- if (NULL == t)
+ if (!t)
{
return;
}
extern struct ThingAction * get_thing_action(uint8_t id)
{
struct ThingAction * ta = world.thing_actions;
- for (; NULL != ta && id != ta->id; ta = ta->next);
+ for (; ta && id != ta->id; ta = ta->next);
return ta;
}
extern struct ThingType * get_thing_type(uint8_t id)
{
struct ThingType * tt = world.thing_types;
- for (; NULL != tt && id != tt->id; tt = tt->next);
+ for (; tt && id != tt->id; tt = tt->next);
return tt;
}
extern uint8_t get_thing_action_id_by_name(char * name)
{
struct ThingAction * ta = world.thing_actions;
- while (NULL != ta)
+ while (ta)
{
if (0 == strcmp(ta->name, name))
{
{
while (1)
{
- if (NULL == ptr || id == ptr->id)
+ if (!ptr || id == ptr->id)
{
return ptr;
}
if (deep)
{
struct Thing * owned_thing = get_thing(ptr->owns, id, 1);
- if (NULL != owned_thing)
+ if (owned_thing)
{
return ptr;
}
penult->next = t->next;
}
struct Thing ** t_ptr_ptr = target;
- for (; NULL != * t_ptr_ptr; t_ptr_ptr = &(*t_ptr_ptr)->next);
+ for (; * t_ptr_ptr; t_ptr_ptr = &(*t_ptr_ptr)->next);
* t_ptr_ptr = t;
t->next = NULL;
}
{
t->pos = pos;
struct Thing * owned = t->owns;
- for (; owned != NULL; set_thing_position(owned, pos), owned = owned->next);
+ for (; owned; set_thing_position(owned, pos), owned = owned->next);
}