static void board_fill(t_env *e) { int max_bot; int nb_food; int nb_rock; int i; int tmp; max_bot = e->opt.limit * e->opt.team_name->len; nb_food = max_bot * 10; i = 0; while (i < nb_food) { ft_lst_pushend(e->board[sq_rand(e)].obj, obj_new(OBJ_FOOD)); i++; } i = 6; while (i > 0) { nb_rock = (i == 6 ? 5 : nb_rock * 2); tmp = nb_rock; while (tmp--) ft_lst_pushend(e->board[sq_rand(e)].obj, obj_new(i)); i--; } }
void init_game(t_env *e) { t_iterator iter; char *name; t_team *team; int i; e->n_sq = e->opt.height * e->opt.width; e->client_lst = ft_lst_new(NULL); e->gfx_lst = ft_lst_new(NULL); e->team = ft_lst_new(NULL); iter = NULL; while ((name = (char *)ft_lst_iter_next_content(e->opt.team_name, &iter))) { team = team_new(name, e->opt.limit); i = 0; while (i < team->limit) { ft_lst_pushend(team->unconnected, bot_new(team)); i++; } ft_lst_pushend(e->team, team); } board_create(e); }
void take(t_env *e, t_bot *bot, char *obj_name) { int sq; t_obj *obj; int type; bot->action_timer = TAKE_TIME; if ((type = get_obj_type(obj_name)) == -1) return (error(bot, "Invalid object")); if ((obj = get_obj(e, bot->sq, type)) == NULL) return (error(bot, "Object not found")); if (type == OBJ_FOOD) { bot->life_unit += FOOD_UNIT; sq = sq_rand(e); ft_lst_pushend(e->board[sq].obj, obj_new(OBJ_FOOD)); notify_all_gfx_bct(e, sq); } else ft_lst_pushend(bot->inventory, obj); printf("BOT #%d take %s\n", bot->id, obj_name); notify_all_gfx_take(e, bot, type); buf_load(bot->buf_action, "ok\n"); }
t_list *ft_lst_cpy(t_list *lst) { t_list *new_lst; t_atom *atom; if ((new_lst = ft_lst_new(NULL)) == NULL) return (NULL); atom = lst->first; while (atom) { ft_lst_pushend(new_lst, atom->content); atom = atom->next; } return (new_lst); }
void add_line_in_list(t_edited_line *line, char *newdata) { char *oldline; if (newdata && line->option->mode == NORMAL_MODE) { ft_lst_pushend(line->option->historic, newdata); line->option->historic->curr = NULL; } else if (newdata && line->option->mode == NOFINISH_MODE) { oldline = line->option->historic->last->content; line->option->historic->last->content = ft_strjoin(oldline, newdata, 0); free(oldline); } }
void gfx_connection(t_env *e, int fd) { t_iterator iter_t; t_team *t; e->fds[fd].type = FD_GFX_CLIENT; ft_lst_pushend(e->gfx_lst, gfx_new(fd)); printf("Client #%d: Connected as GFX\n", fd); msz(e, fd); sgt(e, fd); mct(e, fd); tna(e, fd); iter_t = NULL; while ((t = (t_team *)ft_lst_iter_next_content(e->team, &iter_t))) notify_bot_for_connected_gfx(e, fd, t); }
void put(t_env *e, t_bot *bot, char *obj_name) { t_iterator iter; t_obj *obj; int type; bot->action_timer = PUT_TIME; if ((type = get_obj_type(obj_name)) == -1) return (error(bot, "Invalid object")); iter = NULL; while ((obj = (t_obj *)ft_lst_iter_next_content(bot->inventory, &iter))) { if (obj->type == type) { ft_lst_del_atom(bot->inventory, iter, NULL); ft_lst_pushend(e->board[bot->sq].obj, obj); printf("BOT #%d put %s\n", bot->id, obj_name); notify_all_gfx_put(e, bot, type); buf_load(bot->buf_action, "ok\n"); return ; } } return (error(bot, "Object not found")); }