void frontnet_draw_current_message(struct GuiButton *gbtn) { static TbClockMSec last_time = 0; static TbBool print_with_cursor = 1; struct PlayerInfo *player; int font_idx; char text[2048]; // Blink cursor - switch state every 100ms if (LbTimerClock() >= last_time + 100) { print_with_cursor = !print_with_cursor; last_time = LbTimerClock(); } // Get player player = get_my_player(); if (player_invalid(player)) { return; } // Prepare text buffer and font snprintf(text, sizeof(text), "%s%s", player->mp_message_text, print_with_cursor?"_":""); font_idx = frontend_button_caption_font(gbtn, 0); // And draw the message frontnet_draw_scroll_selection_box(gbtn, font_idx, text); }
void toggle_ally_with_player(long plyridx, unsigned int allyidx) { struct PlayerInfo *player; player = get_player(plyridx); if (player_invalid(player)) return; player->allied_players ^= (1 << allyidx); }
struct Dungeon *get_players_dungeon_f(const struct PlayerInfo *player,const char *func_name) { PlayerNumber plyr_num; plyr_num = player->id_number; if (player_invalid(player) || (plyr_num < 0) || (plyr_num >= DUNGEONS_COUNT)) { ERRORLOG("%s: Tried to get non-existing dungeon %ld!",func_name,(long)plyr_num); return INVALID_DUNGEON; } return &(game.dungeon[(int)plyr_num]); }
TbBool set_ally_with_player(PlayerNumber plyridx, PlayerNumber ally_idx, TbBool state) { struct PlayerInfo *player; player = get_player(plyridx); if (player_invalid(player)) return false; if ((ally_idx < 0) || (ally_idx >= PLAYERS_COUNT)) return false; if (state) player->allied_players |= (1 << ally_idx); else player->allied_players &= ~(1 << ally_idx); return true; }
struct Dungeon *get_players_num_dungeon_f(long plyr_idx,const char *func_name) { struct PlayerInfo *player; PlayerNumber plyr_num; player = get_player(plyr_idx); plyr_num = player->id_number; if (player_invalid(player) || (plyr_num < 0) || (plyr_num >= DUNGEONS_COUNT)) { ERRORMSG("%s: Tried to get players %d non-existing dungeon %d!",func_name,(int)plyr_idx,(int)plyr_num); return INVALID_DUNGEON; } if (plyr_num != player->id_number) { WARNDBG(7,"%s: Player number(%d) differ from index(%d)!",func_name,(int)plyr_num,(int)plyr_idx); } return &(game.dungeon[(int)plyr_num]); }
/** * Returns if the given player is in use on current map. * @param player The player to check. * @return True if the player is in use, false otherwise. */ TbBool player_exists(const struct PlayerInfo *player) { if (player_invalid(player)) return false; return ((player->allocflags & PlaF_Allocated) != 0); }
short good_doing_nothing(struct Thing *creatng) { struct CreatureControl *cctrl; struct PlayerInfo *player; long nturns; PlayerNumber target_plyr_idx; //return _DK_good_doing_nothing(creatng); SYNCDBG(18,"Starting"); TRACE_THING(creatng); // Debug code to find incorrect states if (!is_hero_thing(creatng)) { ERRORLOG("Non hero %s index %d owned by player %d - reset", thing_model_name(creatng),(int)creatng->index,(int)creatng->owner); set_start_state(creatng); return 0; } cctrl = creature_control_get_from_thing(creatng); if (creature_control_invalid(cctrl)) { ERRORLOG("Invalid creature control; no action"); return 0; } // Respect the idle time - just wander around some time nturns = game.play_gameturn - cctrl->idle.start_gameturn; if (nturns <= 1) { return 1; } // Do some wandering also if can't find any task to do if (cctrl->field_5 > (long)game.play_gameturn) { if (creature_choose_random_destination_on_valid_adjacent_slab(creatng)) { creatng->continue_state = CrSt_GoodDoingNothing; } return 1; } // Done wandering - find a target player target_plyr_idx = cctrl->party.target_plyr_idx; if (target_plyr_idx != -1) { player = get_player(target_plyr_idx); if (player_invalid(player)) { ERRORLOG("Invalid target player in %s index %d owned by player %d - reset", thing_model_name(creatng),(int)creatng->index,(int)creatng->owner); cctrl->party.target_plyr_idx = -1; return 0; } if (player->victory_state != VicS_LostLevel) { nturns = game.play_gameturn - cctrl->long_91; if (nturns > 400) { // Go to the previously chosen dungeon if (!creature_can_get_to_dungeon(creatng,target_plyr_idx)) { // Cannot get to the originally selected dungeon - reset it cctrl->party.target_plyr_idx = -1; } } else if (nturns >= 0) { // Waiting - move around a bit if (creature_choose_random_destination_on_valid_adjacent_slab(creatng)) { creatng->continue_state = CrSt_GoodDoingNothing; return 0; } } else { // Value lower than 0 would mean it is invalid WARNLOG("Invalid wait time detected for %s, value %ld",thing_model_name(creatng),(long)cctrl->long_91); cctrl->long_91 = 0; } } else { // The player we've chosen has lost - we'll have to find other target cctrl->party.target_plyr_idx = -1; } } target_plyr_idx = cctrl->party.target_plyr_idx; if (target_plyr_idx == -1) { nturns = game.play_gameturn - cctrl->long_91; if (nturns > 400) { cctrl->long_91 = game.play_gameturn; cctrl->byte_8C = 1; } nturns = game.play_gameturn - cctrl->long_8D; if (nturns > 64) { cctrl->long_8D = game.play_gameturn; cctrl->party.target_plyr_idx = good_find_enemy_dungeon(creatng); } target_plyr_idx = cctrl->party.target_plyr_idx; if (target_plyr_idx == -1) { SYNCDBG(4,"No enemy dungeon to perform %s index %d task", thing_model_name(creatng),(int)creatng->index); if (creature_choose_random_destination_on_valid_adjacent_slab(creatng)) { creatng->continue_state = CrSt_GoodDoingNothing; return 1; } cctrl->field_5 = game.play_gameturn + 16; } return 1; } if (good_creature_setup_task_in_dungeon(creatng, target_plyr_idx)) { return 1; } // If there are problems with the task, do a break before re-trying cctrl->field_5 = game.play_gameturn + 200; return 0; }