t_map *make_intra_lab(t_map *my_map, int larg, int haut) { int nb_rand; int dir; int cmp; cmp = 0; my_map->x = 1; my_map->y = 1; srand(time(NULL)); my_map->seen[my_map->y][my_map->x] = 1; my_map->cmp_lab = (larg * haut); while (cmp != my_map->cmp_lab-1) { nb_rand = rand()%4+1; dir = check_pos(nb_rand, my_map); my_map = save(my_map); while (dir == 0) { nb_rand = rand()%4+1; dir = check_pos(nb_rand, my_map); } my_map = change_pos(my_map, dir); cmp++; } return(my_map); }
void apply_movedown(t_historic **historic) { int col; struct winsize size; ioctl(0, TIOCGWINSZ, &size); if (check_pos(historic, size.ws_col, -1)) { tputs(tgetstr("do", NULL), 1, aff_c); tputs(tgoto(tgetstr("ch", NULL), 0, (*historic)->copy->comline->col % size.ws_col + 1), 1, aff_c); col = (*historic)->copy->comline->col + size.ws_col; while ((*historic)->copy->comline->col != col) (*historic)->copy->comline = (*historic)->copy->comline->right; } else if (check_pos(historic, size.ws_col, -2) && (*historic)->copy->comline->right->right) { tputs(tgetstr("do", NULL), 1, aff_c); while ((*historic)->copy->comline->right) (*historic)->copy->comline = (*historic)->copy->comline->right; tputs(tgoto(tgetstr("ch", NULL), 0, (*historic)->copy->comline->col % size.ws_col + 1), 1, aff_c); } }
/** @fn static pool_u check_pos(pool_u8* tree, pool_u pos, pool_u8 depth) @brief Checks if a memory slot (at pos) is free @param[in] tree The buddy tree @param[in] pos The memory slot @param[in] depth The depth of the tree @return 1 If available, 0 if not */ POOL_FUNC static pool_u check_pos(pool_u8* tree, pool_u pos, pool_u8 depth) { pool_u pos_level = pool_log2(pos); if (pos_level > depth) return 1; if (POOL_GET_BIT(tree, pos) == 0) return 0; if (check_pos(tree, 2 * pos, depth) == 0) return 0; if (check_pos(tree, 2 * pos + 1, depth) == 0) return 0; return 1; }
void ScrollControl::set(int xscroll, int yscroll, int Nxscroll, int Nyscroll, int Nx_show, int Ny_show) { STACKTRACE; x = xscroll; // this is top-left corner item of the visible screen y = yscroll; xselect = x; // this has some extra movement capacility within the visible screen yselect = y; Nxshow = Nx_show; // the size (in items) of the visible screen Nyshow = Ny_show; Nx = Nxscroll - Nxshow + 1; // the scrollable freedom Ny = Nyscroll - Nyshow + 1; // note: Nx = 1 indicates the "base" position; values >1 indicate out-of-sight positions. // or: Nx-Nxshow indicates the out-of-sight positions, +1 indicates the base value position. // check ranges. if (Nx < 1) Nx = 1; if (Ny < 1) Ny = 1; check_pos(); }
/** @fn static pool_u find_pos(pool_u8* tree, pool_u8 max_level, pool_u pos, pool_u8 depth) @brief Finds an available memory slot @param[in] tree The buddy tree @param[in] max_level The level in the tree to allocate into @param[in] pos The position in the tree we are looking at @param[in] depth The depth of the tree @return The position in the tree of an available memory slot, 0 if none */ POOL_FUNC static pool_u find_pos(pool_u8* tree, pool_u8 max_level, pool_u pos, pool_u8 depth) { pool_u level = pool_log2(pos); pool_u res = 0; if (level > max_level) return 0; if (level == max_level) { if (POOL_GET_BIT(tree, pos) && check_pos(tree, pos, depth)) return pos; else return 0; } else { if (POOL_GET_BIT(tree, pos)) { res = find_pos(tree, max_level, 2 * pos, depth); if (res) return res; res = find_pos(tree, max_level, pos * 2 + 1, depth); if (res) return res; } return 0; } }
void agent_learn(void) { // 既に学習済みならセンサーから値を取り込まない if(visible[curY][curX]) return; visible[curY][curX] = true; uint8_t sensor_data = sensor_get(); for(int k = 0; k < 4; ++k) { // 後ろのセンサーは付いていないので if(k == 2) continue; int ndir = (dir + k)%4; // 壁があるとき if(gbi(sensor_data, k)) { wall[curY][curX][ndir] = true; } int ny = curY + dy[ndir]; int nx = curX + dx[ndir]; if(check_pos(ny, nx)) { if(gbi(sensor_data, k)) { wall[ny][nx][(ndir + 2)%4] = true; } } } }
void ScrollControl::add(int dx, int dy) { STACKTRACE; x += dx; y += dy; check_pos(); }
void ScrollControl::set_sel(int xsel, int ysel) { STACKTRACE; xselect = xsel; yselect = ysel; check_sel(); check_pos(); }
void CApp::verify_winner(int id) { if (check_pos(id, next_pos(id, 0, 1), 0, 1) || check_pos(id, next_pos(id, 1, 0), 1, 0) || (check_anti_diag(id) && check_pos(id, next_pos(id, 1, -1), 1, -1)) || (check_diag(id) && check_pos(id, next_pos(id, 1, 1), 1, 1))) { if (grid[id] == GRID_TYPE_X) result = FINAL_X_WON; else result = FINAL_O_WON; finish = true; } if (grid_used == MATRIX_SIZE * MATRIX_SIZE) { result = FINAL_DRAW; finish = true; } }
bool CApp::check_pos(int id, int pos, int x_dir, int y_dir) { if (id == pos) return true; if (grid[id] != grid[pos]) return false; return check_pos(id, next_pos(pos, x_dir, y_dir), x_dir, y_dir); }
void actor_avoid(Actor * self) { int tx = self->x / tile_w; int ty = self->y / tile_h; if (land_array_count(app->actors->tilemap[tx + app->actors->w * ty] .actors) > 1) { actor_unplace(self); self->x += land_rand( - 1, 1); self->y += land_rand( - 1, 1); check_pos(self); actor_place(self); } }
void apply_moveup(t_historic **historic) { int col; struct winsize size; ioctl(0, TIOCGWINSZ, &size); if (check_pos(historic, size.ws_col, 1)) { tputs(tgetstr("up", NULL), 1, aff_c); col = (*historic)->copy->comline->col - size.ws_col; while ((*historic)->copy->comline->col != col) (*historic)->copy->comline = (*historic)->copy->comline->left; } else if (check_pos(historic, size.ws_col, 2) && (*historic)->copy->comline->left) { tputs(tgetstr("up", NULL), 1, aff_c); tputs(tgoto(tgetstr("ch", NULL), 0, (*historic)->prompt), 1, aff_c); while ((*historic)->copy->comline->c != '\0') (*historic)->copy->comline = (*historic)->copy->comline->left; } }
int play_chess(int i, int j) { /**/ if (!check_pos(i, j)) { /* 先遍历某一行的所有列 */ for (++j; j <= BOARD_SIZE; ++j) { if (check_pos(i, j)) break; } if (j > BOARD_SIZE) { /* 没有符合的列,要回溯 */ return 1; } } if (i <= BOARD_SIZE && j <= BOARD_SIZE) { /* 符合 */ set_chess(i, j, HAVE_CHESS); ret = play_chess(i+1, 1); // 下一层 } }
int check_map(char *str, t_infos *infos, t_list **rooms) { if (check_ants(str, infos) == 1) return (1); else if (check_start(str, infos) == 1 && infos->ok != 2) return (1); else if (check_end(str, infos) == 1 && infos->ok != 2) return (1); else if(check_pos(str, rooms, infos) == 1) return (1); else if(check_tubes(str, infos, rooms) == 1) return (1); return (0); }
int main(int ac, char **av) { Map map; if (get_map(&map)) return (-1); if (check_pos(map)) return (-1); Init_game(&map); aff_all(&map); SDL_Quit(); free(map.map); return (0); }
void ScrollControl::calculate() { STACKTRACE; int xold, yold; xold = x; yold = y; if (left && left->flag.left_mouse_press) { --xselect; if (xselect < x) x = xselect; } if (right && right->flag.left_mouse_press) { ++xselect; if (xselect > x + Nxshow - 1) x = xselect-Nxshow+1; } if (up && up->flag.left_mouse_press) { --yselect; if (yselect < y) y = yselect; } if (down && down->flag.left_mouse_press) { ++yselect; if (yselect > y + Nyshow - 1) y = yselect-Nyshow+1; } check_pos(); if (scrollhor && xold != x) scrollhor->setrelpos(double(x)/Nx); if (scrollvert && yold != y) scrollvert->setrelpos(double(y)/Ny); if (scrollhor && scrollhor->flag.left_mouse_hold) set_percent_pos_x(scrollhor->relpos); if (scrollvert && scrollvert->flag.left_mouse_hold) set_percent_pos_y(scrollvert->relpos); }
/* * 简单暴力实现法 */ void circle_play(void) { int i, j; int flag; for (i = 1, j = 1; i <= BOARD_SIZE;) { flag = 0; for (; j <= BOARD_SIZE; ++j) { printf("start_i = %d, start_j = %d\n", i, j); if (check_pos(i, j)) { /* 符合规则,放棋 */ printf("set chess [%d][%d]\n", i, j); flag = 1; CHESS[i] = j; set_attack_area(i, j); break; } /* 如果当前列不符合,则继续检查下一列 */ } if (flag == 0) { /* 回溯,设置上一层棋子的位置 */ --i; // 返回上一层 if (i <= 0) break; // end j = CHESS[i] + 1; // 要向右移一格 printf("return to level [%d], column [%d]\n", i, j); /* 要把上一层设置的棋子位置和攻击区域清除 */ CHESS[i] = 0; reset_attack_area(); } else { /* 下一层 */ ++i; /* 如果最后一层处理完,说明求出一个解了, * 继续往下求,直到回溯时i为0 */ if (i > BOARD_SIZE) { print_solution(); --i; ++j; /* 把位置和攻击区域清除 */ CHESS[i] = 0; reset_attack_area(); } else { /* 下一层从第一列开始 */ j = 1; } } } }
void ScrollControl::set_pos(int xnew, int ynew) { STACKTRACE; if ( xnew >= 0 && xnew < Nx && ynew >= 0 && ynew < Ny ) { x = xnew; y = ynew; if (scrollhor) scrollhor->setrelpos(double(x)/Nx); if (scrollvert) scrollvert->setrelpos(double(y)/Ny); } check_pos(); }
/** * Liest BOTFS_BLOCK_SIZE Bytes aus einer Datei in einen Puffer * \param *file Zeiger auf Datei-Deskriptor * \param *buffer Puffer fuer mindestens BOTFS_BLOCK_SIZE Byte, in die Daten geschrieben werden * \return 0, falls kein Fehler */ int8_t botfs_read(botfs_file_descr_t * file, void * buffer) { if (init_state != 1) { return -99; } /* Positions-Check */ if (check_pos(file, file->pos) != 0) { PRINT_MSG("botfs_read(): Position 0x%x ungueltig!", file->pos); return -1; } /* Daten lesen und Dateizeiger anpassen */ if (botfs_read_low(file->pos++, buffer) != 0) { PRINT_MSG("botfs_read(): botfs_read_low() meldet Fehler"); return -2; } return 0; }
void aff_cmpl(t_shell *shell) { t_cmd *tmp; tmp = shell->com.cmd_l; check_pos(shell); shell->com.y[0] = get_actual_pos(shell); while (tmp) { if (tmp == shell->com.cursor) my_dprintf(1, PINK"%s"RES"\t", tmp->str); else my_dprintf(1, "%s\t", tmp->str); tmp = tmp->next; } shell->com.y[1] = get_actual_pos(shell); gotoyx(shell, get_actual_pos(shell) + (shell->com.y[0] - get_actual_pos(shell)), 0); }
static void validate_result (void) { int i; check_pos (0, 0xff0000ff); check_pos (1, 0xffff00ff); check_pos (2, 0xff00ffff); for (i = 0; i <= 8; i++) { int green_value = i / 8.0f * 255.0f + 0.5f; check_pos (i + 3, 0xff0000ff + (green_value << 16)); } check_pos (12, 0x0080ffff); check_pos (13, 0xffffffff); check_pos (14, 0x80ffffff); }
/** * Schreibt BOTFS_BLOCK_SIZE Bytes aus einem Puffer in eine Datei * \param *file Zeiger auf Datei-Deskriptor * \param *buffer Puffer mit mindestens BOTFS_BLOCK_SIZE Byte, dessen Daten in die Datei geschrieben werden * \return 0, falls kein Fehler */ int8_t botfs_write(botfs_file_descr_t * file, void * buffer) { if (init_state != 1) { return -99; } /* Schreibschutz pruefen */ if (file->mode == BOTFS_MODE_r) { PRINT_MSG("botfs_write(): Fehler, Datei ist schreibgeschuetzt geoeffnet!"); return -1; } /* Positions-Check */ if (check_pos(file, file->pos) != 0) { PRINT_MSG("botfs_write(): Dateiposition unzulaessig"); return -2; } /* Daten schreiben und Dateizeiger anpassen */ if (botfs_write_low(file->pos, buffer) != 0) { PRINT_MSG("botfs_write(): write_low() schlug fehl"); return -3; } /* Info ueber benutzte Bloecke updaten */ if (file->pos < file->used.start) { file->used.start = file->pos; // PRINT_MSG("botfs_write(): Bloecke 0x%x bis 0x%x als benutzt vermerkt", file->used.start, file->used.end); } if (file->pos > file->used.end) { file->used.end = file->pos; file->used.bytes_last_block = BOTFS_BLOCK_SIZE; // PRINT_MSG("botfs_write(): Bloecke 0x%x bis 0x%x als benutzt vermerkt", file->used.start, file->used.end); } file->pos++; return 0; }
void ScrollControl::set_percent_pos_y(double alpha) { STACKTRACE; y = iround( (Ny-1) * alpha ); check_pos(); }
/* * The main entry point for executing commands. * Can be recursively called from 'at', 'order', 'force'. */ void interpret( CHAR_DATA * ch, char *argument ) { char command[MAX_INPUT_LENGTH]; char logline[MAX_INPUT_LENGTH]; char logname[MAX_INPUT_LENGTH]; char log_buf[MAX_STRING_LENGTH]; char *origarg = argument; char *buf; TIMER *timer = NULL; CMDTYPE *cmd = NULL; int trust; int loglvl; bool found; struct timeval time_used; long tmptime; if( !ch ) { bug( "%s: null ch!", __FUNCTION__ ); return; } if( !ch->in_room ) { bug( "%s: null in_room!", __FUNCTION__ ); return; } found = FALSE; if( ch->substate == SUB_REPEATCMD ) { DO_FUN *fun; if( ( fun = ch->last_cmd ) == NULL ) { ch->substate = SUB_NONE; bug( "%s: SUB_REPEATCMD with NULL last_cmd", __FUNCTION__ ); return; } else { int x; /* * yes... we lose out on the hashing speediness here... * but the only REPEATCMDS are wizcommands (currently) */ for( x = 0; x < 126; x++ ) { for( cmd = command_hash[x]; cmd; cmd = cmd->next ) if( cmd->do_fun == fun ) { found = TRUE; break; } if( found ) break; } if( !found ) { cmd = NULL; bug( "%s: SUB_REPEATCMD: last_cmd invalid", __FUNCTION__ ); return; } snprintf( logline, MAX_INPUT_LENGTH, "(%s) %s", cmd->name, argument ); } } if( !cmd ) { /* * Changed the order of these ifchecks to prevent crashing. */ if( !argument || !strcmp( argument, "" ) ) { bug( "%s: null argument!", __FUNCTION__ ); return; } /* * Strip leading spaces. */ while( isspace( *argument ) ) argument++; if( argument[0] == '\0' ) return; /* * xREMOVE_BIT( ch->affected_by, AFF_HIDE ); */ /* * Implement freeze command. */ if( !IS_NPC( ch ) && xIS_SET( ch->act, PLR_FREEZE ) ) { send_to_char( "You're totally frozen!\r\n", ch ); return; } /* * Grab the command word. * Special parsing so ' can be a command, * also no spaces needed after punctuation. */ mudstrlcpy( logline, argument, MAX_INPUT_LENGTH ); if( !isalpha( argument[0] ) && !isdigit( argument[0] ) ) { command[0] = argument[0]; command[1] = '\0'; argument++; while( isspace( *argument ) ) argument++; } else argument = one_argument( argument, command ); /* * Look for command in command table. * Check for council powers and/or bestowments */ trust = get_trust( ch ); for( cmd = command_hash[LOWER( command[0] ) % 126]; cmd; cmd = cmd->next ) if( !str_prefix( command, cmd->name ) && ( cmd->level <= trust || ( !IS_NPC( ch ) && ch->pcdata->council && is_name( cmd->name, ch->pcdata->council->powers ) && cmd->level <= ( trust + MAX_CPD ) ) || ( !IS_NPC( ch ) && ch->pcdata->bestowments && ch->pcdata->bestowments[0] != '\0' && is_name( cmd->name, ch->pcdata->bestowments ) && cmd->level <= ( trust + sysdata.bestow_dif ) ) ) ) { found = TRUE; break; } /* * Turn off afk bit when any command performed. */ if( !IS_NPC( ch ) && xIS_SET( ch->act, PLR_AFK ) && ( str_cmp( command, "AFK" ) ) ) { xREMOVE_BIT( ch->act, PLR_AFK ); act( AT_GREY, "$n is no longer afk.", ch, NULL, NULL, TO_CANSEE ); } } /* * Log and snoop. */ snprintf( lastplayercmd, ( MAX_INPUT_LENGTH * 2 ), "%s used %s", ch->name, logline ); if( found && cmd->log == LOG_NEVER ) mudstrlcpy( logline, "XXXXXXXX XXXXXXXX XXXXXXXX", MAX_INPUT_LENGTH ); loglvl = found ? cmd->log : LOG_NORMAL; /* * Write input line to watch files if applicable */ if( !IS_NPC( ch ) && ch->desc && valid_watch( logline ) ) { if( found && IS_SET( cmd->flags, CMD_WATCH ) ) write_watch_files( ch, cmd, logline ); else if( IS_SET( ch->pcdata->flags, PCFLAG_WATCH ) ) write_watch_files( ch, NULL, logline ); } if( ( !IS_NPC( ch ) && xIS_SET( ch->act, PLR_LOG ) ) || fLogAll || loglvl == LOG_BUILD || loglvl == LOG_HIGH || loglvl == LOG_ALWAYS ) { /* * Added by Narn to show who is switched into a mob that executes * a logged command. Check for descriptor in case force is used. */ if( ch->desc && ch->desc->original ) snprintf( log_buf, MAX_STRING_LENGTH, "Log %s (%s): %s", ch->name, ch->desc->original->name, logline ); else snprintf( log_buf, MAX_STRING_LENGTH, "Log %s: %s", ch->name, logline ); /* * Make it so a 'log all' will send most output to the log * file only, and not spam the log channel to death -Thoric */ if( fLogAll && loglvl == LOG_NORMAL && ( IS_NPC( ch ) || !xIS_SET( ch->act, PLR_LOG ) ) ) loglvl = LOG_ALL; log_string_plus( log_buf, loglvl, get_trust( ch ) ); } if( ch->desc && ch->desc->snoop_by ) { snprintf( logname, MAX_INPUT_LENGTH, "%s", ch->name ); write_to_buffer( ch->desc->snoop_by, logname, 0 ); write_to_buffer( ch->desc->snoop_by, "% ", 2 ); write_to_buffer( ch->desc->snoop_by, logline, 0 ); write_to_buffer( ch->desc->snoop_by, "\r\n", 2 ); } /* * check for a timer delayed command (search, dig, detrap, etc) */ if( ( timer = get_timerptr( ch, TIMER_DO_FUN ) ) != NULL ) { int tempsub; tempsub = ch->substate; ch->substate = SUB_TIMER_DO_ABORT; ( timer->do_fun ) ( ch, "" ); if( char_died( ch ) ) return; if( ch->substate != SUB_TIMER_CANT_ABORT ) { ch->substate = tempsub; extract_timer( ch, timer ); } else { ch->substate = tempsub; return; } } /* * Look for command in skill and socials table. */ if( !found ) { if( !check_skill( ch, command, argument ) && !check_ability( ch, command, argument ) // Racial Abilities Support - Kayle 7-8-07 && !rprog_command_trigger( ch, origarg ) && !mprog_command_trigger( ch, origarg ) && !oprog_command_trigger( ch, origarg ) && !check_social( ch, command, argument ) && !news_cmd_hook( ch, command, argument ) #ifdef IMC && !imc_command_hook( ch, command, argument ) #endif ) { EXIT_DATA *pexit; /* * check for an auto-matic exit command */ if( ( pexit = find_door( ch, command, TRUE ) ) != NULL && IS_SET( pexit->exit_info, EX_xAUTO ) ) { if( IS_SET( pexit->exit_info, EX_CLOSED ) && ( !IS_AFFECTED( ch, AFF_PASS_DOOR ) || IS_SET( pexit->exit_info, EX_NOPASSDOOR ) ) ) { if( !IS_SET( pexit->exit_info, EX_SECRET ) ) act( AT_PLAIN, "The $d is closed.", ch, NULL, pexit->keyword, TO_CHAR ); else send_to_char( "You cannot do that here.\r\n", ch ); return; } if( check_pos( ch, POS_STANDING ) ) move_char( ch, pexit, 0 ); return; } send_to_char( "Huh?\r\n", ch ); } return; } /* * Character not in position for command? */ if( !check_pos( ch, cmd->position ) ) return; /* * Berserk check for flee.. maybe add drunk to this?.. but too much * hardcoding is annoying.. -- Altrag * This wasn't catching wimpy --- Blod * if ( !str_cmp(cmd->name, "flee") && * IS_AFFECTED(ch, AFF_BERSERK) ) * { * send_to_char( "You aren't thinking very clearly..\r\n", ch); * return; * } */ /* * So we can check commands for things like Posses and Polymorph * * But still keep the online editing ability. -- Shaddai * * Send back the message to print out, so we have the option * * this function might be usefull elsewhere. Also using the * * send_to_char_color so we can colorize the strings if need be. --Shaddai */ buf = check_cmd_flags( ch, cmd ); if( buf[0] != '\0' ) { send_to_char_color( buf, ch ); return; } /* * Nuisance stuff -- Shaddai */ if( !IS_NPC( ch ) && ch->pcdata->nuisance && ch->pcdata->nuisance->flags > 9 && number_percent( ) < ( ( ch->pcdata->nuisance->flags - 9 ) * 10 * ch->pcdata->nuisance->power ) ) { send_to_char( "You can't seem to do that just now.\r\n", ch ); return; } /* * Dispatch the command. */ ch->prev_cmd = ch->last_cmd; /* haus, for automapping */ ch->last_cmd = cmd->do_fun; start_timer( &time_used ); ( *cmd->do_fun ) ( ch, argument ); end_timer( &time_used ); /* * Update the record of how many times this command has been used (haus) */ update_userec( &time_used, &cmd->userec ); tmptime = UMIN( time_used.tv_sec, 19 ) * 1000000 + time_used.tv_usec; /* * laggy command notice: command took longer than 1.5 seconds */ if( tmptime > 1500000 ) { log_printf_plus( LOG_NORMAL, get_trust( ch ), "[*****] LAG: %s: %s %s (R:%d S:%ld.%06ld)", ch->name, cmd->name, ( cmd->log == LOG_NEVER ? "XXX" : argument ), ch->in_room ? ch->in_room->vnum : 0, time_used.tv_sec, time_used.tv_usec ); cmd->lag_count++; /* count the lag flags */ } tail_chain( ); }
void actor_tick(Actor * self) { if (self->dead) { self->anim_tick++; return; } if (self->special < 900) { self->special++; } if (self->hp <= 0) { self->dead = 1; self->anim_tick = 0; } if (self->frozen > 0) { self->frozen--; return; } if (! self->target) { self->projectile = 0; } else if(self->target->dead) { self->target = NULL; self->projectile = 0; } if (self->projectile) { float dx = wrap(self->target->x - self->px); float dy = self->target->y - self->py; float d = sqrt(dx * dx + dy * dy); float s = self->kind->projectile_speed; if (d > s) { self->px += s * dx / d; self->py += s * dy / d; } else { if (self->kind->projectile == IT_HEAL) { actor_hp(self->target, self, + 10); } if (self->kind->projectile == IT_ARROW) { actor_hp(self->target, self, - 3); } if (self->kind->projectile == IT_MAGIC_MISSILE) { actor_hp(self->target, self, - 6); } if (self->kind->projectile == IT_FIREBALL) { actor_hp(self->target, self, - 5); } self->projectile = 0; } } if (self->walking) { float dx = wrap(self->tx - self->x); float dy = self->ty - self->y; float d = sqrt(dx * dx + dy * dy); if (d > 1) { bool col = 0; actor_unplace(self); float ox = self->x; float oy = self->y; self->x += dx / d; check_pos(self); if (! actor_place(self)) { self->x = ox; col = 1; } else { actor_unplace(self); } self->y += dy / d; check_pos(self); if (! actor_place(self)) { self->y = oy; actor_place(self); col = 1; } self->angle = atan2(dy, dx); self->walk_tick++; self->walk_tick &= 31; if (col) { if (d <= 30) { self->tx = self->x; self->ty = self->y; } } return; } else { self->walking = 0; actor_items(self); } } if ((self->walk_tick & 15) != 8) { self->walk_tick++; self->walk_tick &= 31; } actor_avoid(self); if (self->target) { float dx = wrap(self->target->x - self->x); float dy = self->target->y - self->y; float d = sqrt(dx * dx + dy * dy); if (d > 1) { self->angle = atan2(dy, dx); } actor_target_action(self); } else { if (self->kind->enemy) { ai_tick(self); } } }
static void validate_long_pipeline_result (void) { check_pos (15, 0xff0000ff); }
/* * The main entry point for executing commands. * Can be recursively called from 'at', 'order', 'force'. */ void interpret( CHAR_DATA * ch, const char *argument ) { char command[MAX_INPUT_LENGTH]; char logline[MAX_INPUT_LENGTH]; char logname[MAX_INPUT_LENGTH]; TIMER *timer = NULL; CMDTYPE *cmd = NULL; int trust; int loglvl; bool found; struct timeval time_used; long tmptime; if( !ch ) { bug( "interpret: null ch!", 0 ); return; } found = FALSE; if( ch->substate == SUB_REPEATCMD ) { DO_FUN *fun; if( ( fun = ch->last_cmd ) == NULL ) { ch->substate = SUB_NONE; bug( "interpret: SUB_REPEATCMD with NULL last_cmd", 0 ); return; } else { int x; /* * yes... we lose out on the hashing speediness here... * but the only REPEATCMDS are wizcommands (currently) */ for( x = 0; x < 126; x++ ) { for( cmd = command_hash[x]; cmd; cmd = cmd->next ) if( cmd->do_fun == fun ) { found = TRUE; break; } if( found ) break; } if( !found ) { cmd = NULL; bug( "interpret: SUB_REPEATCMD: last_cmd invalid", 0 ); return; } sprintf( logline, "(%s) %s", cmd->name, argument ); } } if( !cmd ) { /* * Changed the order of these ifchecks to prevent crashing. */ if( !argument || !strcmp( argument, "" ) ) { bug( "interpret: null argument!", 0 ); return; } /* * Strip leading spaces. */ while( isspace( *argument ) ) argument++; if( argument[0] == '\0' ) return; timer = get_timerptr( ch, TIMER_DO_FUN ); /* * REMOVE_BIT( ch->affected_by, AFF_HIDE ); */ /* * Implement freeze command. */ if( !IS_NPC( ch ) && IS_SET( ch->act, PLR_FREEZE ) ) { send_to_char( "You're totally frozen!\r\n", ch ); return; } /* * Grab the command word. * Special parsing so ' can be a command, * also no spaces needed after punctuation. */ strcpy( logline, argument ); if( !isalpha( argument[0] ) && !isdigit( argument[0] ) ) { command[0] = argument[0]; command[1] = '\0'; argument++; while( isspace( *argument ) ) argument++; } else argument = one_argument( argument, command ); /* * Look for command in command table. * Check for council powers and/or bestowments */ trust = get_trust( ch ); for( cmd = command_hash[LOWER( command[0] ) % 126]; cmd; cmd = cmd->next ) if( !str_prefix( command, cmd->name ) && ( cmd->level <= trust || ( !IS_NPC( ch ) && ch->pcdata->bestowments && ch->pcdata->bestowments[0] != '\0' && is_name( cmd->name, ch->pcdata->bestowments ) && cmd->level <= ( trust + 5 ) ) ) ) { found = TRUE; break; } /* * Turn off afk bit when any command performed. */ if( !IS_NPC( ch ) && IS_SET( ch->act, PLR_AFK ) && ( str_cmp( command, "AFK" ) ) ) { REMOVE_BIT( ch->act, PLR_AFK ); act( AT_GREY, "$n is no longer afk.", ch, NULL, NULL, TO_ROOM ); } } /* * Log and snoop. */ sprintf( lastplayercmd, "** %s: %s", ch->name, logline ); if( found && cmd->log == LOG_NEVER ) strcpy( logline, "XXXXXXXX XXXXXXXX XXXXXXXX" ); loglvl = found ? cmd->log : LOG_NORMAL; if( ( !IS_NPC( ch ) && IS_SET( ch->act, PLR_LOG ) ) || fLogAll || loglvl == LOG_BUILD || loglvl == LOG_HIGH || loglvl == LOG_ALWAYS ) { /* * Added by Narn to show who is switched into a mob that executes * a logged command. Check for descriptor in case force is used. */ if( ch->desc && ch->desc->original ) sprintf( log_buf, "Log %s (%s): %s", ch->name, ch->desc->original->name, logline ); else sprintf( log_buf, "Log %s: %s", ch->name, logline ); /* * Make it so a 'log all' will send most output to the log * file only, and not spam the log channel to death -Thoric */ if( fLogAll && loglvl == LOG_NORMAL && ( IS_NPC( ch ) || !IS_SET( ch->act, PLR_LOG ) ) ) loglvl = LOG_ALL; /* * This is handled in get_trust already */ /* if ( ch->desc && ch->desc->original ) log_string_plus( log_buf, loglvl, ch->desc->original->level ); else*/ log_string_plus( log_buf, loglvl, get_trust( ch ) ); } if( ch->desc && ch->desc->snoop_by ) { sprintf( logname, "%s", ch->name ); write_to_buffer( ch->desc->snoop_by, logname, 0 ); write_to_buffer( ch->desc->snoop_by, "% ", 2 ); write_to_buffer( ch->desc->snoop_by, logline, 0 ); write_to_buffer( ch->desc->snoop_by, "\r\n", 2 ); } if( timer ) { int tempsub; tempsub = ch->substate; ch->substate = SUB_TIMER_DO_ABORT; ( timer->do_fun ) ( ch, "" ); if( char_died( ch ) ) return; if( ch->substate != SUB_TIMER_CANT_ABORT ) { ch->substate = tempsub; extract_timer( ch, timer ); } else { ch->substate = tempsub; return; } } /* * Look for command in skill and socials table. */ if( !found ) { if( !check_skill( ch, command, argument ) && !check_social( ch, command, argument ) #ifdef IMC && !imc_command_hook( ch, command, argument ) #endif ) { EXIT_DATA *pexit; /* * check for an auto-matic exit command */ if( ( pexit = find_door( ch, command, TRUE ) ) != NULL && IS_SET( pexit->exit_info, EX_xAUTO ) ) { if( IS_SET( pexit->exit_info, EX_CLOSED ) && ( !IS_AFFECTED( ch, AFF_PASS_DOOR ) || IS_SET( pexit->exit_info, EX_NOPASSDOOR ) ) ) { if( !IS_SET( pexit->exit_info, EX_SECRET ) ) act( AT_PLAIN, "The $d is closed.", ch, NULL, pexit->keyword, TO_CHAR ); else send_to_char( "You cannot do that here.\r\n", ch ); return; } move_char( ch, pexit, 0 ); return; } send_to_char( "Huh?\r\n", ch ); } return; } /* * Character not in position for command? */ if( !check_pos( ch, cmd->position ) ) return; /* * Berserk check for flee.. maybe add drunk to this?.. but too much * hardcoding is annoying.. -- Altrag */ if( !str_cmp( cmd->name, "flee" ) && IS_AFFECTED( ch, AFF_BERSERK ) ) { send_to_char( "You aren't thinking very clearly..\r\n", ch ); return; } /* * Dispatch the command. */ ch->prev_cmd = ch->last_cmd; /* haus, for automapping */ ch->last_cmd = cmd->do_fun; start_timer( &time_used ); ( *cmd->do_fun ) ( ch, argument ); end_timer( &time_used ); /* * Update the record of how many times this command has been used (haus) */ update_userec( &time_used, &cmd->userec ); tmptime = UMIN( time_used.tv_sec, 19 ) * 1000000 + time_used.tv_usec; /* * laggy command notice: command took longer than 1.5 seconds */ if( tmptime > 1500000 ) { sprintf( log_buf, "[*****] LAG: %s: %s %s (R:%d S:%d.%06d)", ch->name, cmd->name, ( cmd->log == LOG_NEVER ? "XXX" : argument ), ch->in_room ? ch->in_room->vnum : 0, ( int )( time_used.tv_sec ), ( int )( time_used.tv_usec ) ); log_string_plus( log_buf, LOG_NORMAL, get_trust( ch ) ); } tail_chain( ); }