Exemplo n.º 1
0
Arquivo: cee.c Projeto: Pirolf/rosey
int main()
{
	GameState *level = new_game_state();

	add_player (level, new_player("mizu"));
	add_player (level, new_player("zeroeth"));
	add_player (level, new_player("haiiro"));
	add_player (level, new_player("takeshi"));

	player_report (level);
}
Exemplo n.º 2
0
Character *load_player_by_name(Connection *conn, const char *name)
{
    char buf[400];
    sql_stmt *stmt;
    db_begin_transaction();
    int len = sprintf(buf,
                      "select * from character natural join player where name='%s'",
                      escape_sql_str(name));

    if (sql_query(buf, len, &stmt) != SQL_OK)
    {
        log_data("could not prepare sql statement");
        return 0;
    }
    Character *ch = new_char();
    ch->pc = new_player(conn);

    if (sql_step(stmt) != SQL_DONE)
    {
        load_player_columns(conn->account, ch, stmt);
    }

    if (sql_finalize(stmt) != SQL_OK)
    {
        log_data("unable to finalize statement");
    }
    load_char_objs(ch);
    load_char_affects(ch);
    db_end_transaction();
    return ch;

}
Exemplo n.º 3
0
Character *load_player_by_id(Connection *conn, identifier_t charId)
{
    char buf[400];
    sql_stmt *stmt;
    db_begin_transaction();
    int len = sprintf(buf,
                      "select * from character join player on playerId=characterId where characterId=%"
                      PRId64,
                      charId);

    if (sql_query(buf, len, &stmt) != SQL_OK)
    {
        log_data("could not prepare sql statement");
        return 0;
    }
    Character *ch = new_char();
    ch->pc = new_player(conn);

    if (sql_step(stmt) != SQL_DONE)
    {
        load_player_columns(conn->account, ch, stmt);
    }

    if (sql_finalize(stmt) != SQL_OK)
    {
        log_data("unable to finalize statement");
    }
    load_char_objs(ch);
    load_char_affects(ch);
    db_end_transaction();
    return ch;

}
Exemplo n.º 4
0
Arquivo: game.c Projeto: phoboz/yz
void init_game(int tile_index)
{
  if ((game_hero = load_actor_XML("aron.stat")) == NULL) {
    fprintf(stderr, "ERROR - Unable to initialize hero.\n");
    exit(1);
  }

  if ((game_player = new_player(128 * 32, 96 * 32, game_hero)) == NULL) {
    fprintf(stderr, "ERROR - Unable to initialize player.\n");
    exit(1);
  }

  if ((game_world = new_world("world.png", tile_index,
                         game_player->x, game_player->y,
                         300, 200,
	                 DEFAULT_CELL_WIDTH, DEFAULT_CELL_HEIGHT)) == NULL) {
    fprintf(stderr, "ERROR - Unable to initialize world\n");
    exit(1);
  }

  if ((game_scanner = new_scanner("marker4x4.png")) == NULL) {
    fprintf(stderr, "ERROR - Unable to initialize scanner\n");
    exit(1);
  }

  if ((game_battle = new_battle(game_world)) == NULL) {
    fprintf(stderr, "ERROR - Unable to initialize battle\n");
    exit(1);
  }

  set_game_state(GAME_STATE_WORLD);

  update_game();
}
Exemplo n.º 5
0
int	first_step(t_util *util)
{
  int	pid;

  util->id = 0;
  util->shm_id = shmget(util->key, (sizeof(char) * (MAP_X * MAP_Y)),
			IPC_CREAT | SHM_R | SHM_W);
  util->msg_id = msgget(util->key, IPC_CREAT | SHM_R | SHM_W);
  util->sem_id = semget(util->key, 1, IPC_CREAT | SHM_R | SHM_W);
  if (util->shm_id == -1 || util->msg_id == -1 ||  util->sem_id == -1)
    return (err_msg(": the creation of a shared memory fail"));
  util->addr = shmat(util->shm_id, NULL, SHM_R | SHM_W);
  init_map(util);
  semctl(util->sem_id, 0, SETVAL, 1);
  pid = fork();
  if (pid != 0)
    {
      display(util->addr, init_sdl());
      SDL_Quit();
      return (1);
    }
  if (new_player(util) == -1)
    return (-1);
  return (1);
}
Exemplo n.º 6
0
t_env	*new_env()
{
	t_env	*env;

	env = (t_env *)malloc(sizeof(t_env));
	if (env)
	{
		env->mlx = mlx_init();
		env->win = mlx_new_window(env->mlx, MAP_HEIGHT * 30, MAP_WIDTH * 30, "wolf3d");
		env->player = new_player();
		env->time = 0;
		env->oldtime = 0;
		env->step = new_int2Dvect(0,0);
		if (! (env->step && env->player))
		{
			//free(player);
			free(env);
			return (NULL);
		}
		env->hit = 0;
		env->side = 0;
		env->draw_start = 0;
		env->draw_end = 0;
	}
	return (env);
}
Exemplo n.º 7
0
int	other_player(t_util *util)
{
  util->addr = shmat(util->shm_id, NULL, SHM_R | SHM_W);
  util->id = count_player(util->addr, 'a');
  if (new_player(util) == -1)
    return (-1);
  return (0);
}
Exemplo n.º 8
0
int	other_player(t_util *util)
{
  util->addr = shmat(util->shm_id, NULL, SHM_R | SHM_W);
  util->id = count_player(util->addr, 'a');
  printf("Creation of player nb : %d\n", util->id + 1);
  if (new_player(util) == -1)
    return (-1);
  return (0);
}
Exemplo n.º 9
0
int main()
{
    //TODO: Add Event List Class
    //TODO: Add event subscriptions

    game_state *game_state;
    player *player;

    game_state = init_game_engine();

	player = new_player(game_state, "BOT", GLOBAL_DEFAULT_BOT);

	player = new_player(game_state, "John", GLOBAL_HUMAN_PLAYER);

    start_game_loop(game_state);

    return 0;
}
Exemplo n.º 10
0
void populate_roster(unsigned char *buffer, Team *team, int offset)
{
    int position_count = sizeof(POSITIONS) / sizeof(unsigned long);

    for (int i = 0 ; i < 25 ; i++) {
        Player *player = new_player();
        strcpy(player->pos, POSITIONS[i]); // Set position for player
        add_stats(buffer, player, i + offset);
        team->roster[i] = *player;
    }
}
Exemplo n.º 11
0
/*
 * Accept a new Telnet connection.
 */
static void
telnet_accept(void *vp)
{
    ndesc_t *nd = vp;
    int addrlen, s;
    struct sockaddr_in addr;
    telnet_t *tp;
    void *ip;

    nd_enable(nd, ND_R);
    
    addrlen = sizeof (addr);
    s = accept(nd_fd(nd), (struct sockaddr *)&addr, &addrlen);
    if (s == -1)
    {
	switch (errno)
	{
	default:
            warning("telnet_accept: accept() errno = %d. ip: %s\n",
                errno, inet_ntoa(addr.sin_addr));
	case EWOULDBLOCK:
	case EINTR:
	case EPROTO:
	    return;
	}
    }

    enable_nbio(s);
    enable_oobinline(s);
    enable_nodelay(s);
    enable_lowdelay(s);
    enable_keepalive(s);
    set_rcvsize(s, TELNET_RCVBUF_SIZE);
    set_sndsize(s, TELNET_SNDBUF_SIZE);

    tp = telnet_alloc();
    tp->t_nd = nd_attach(s, telnet_read, telnet_write, telnet_exception,
			 NULL, telnet_shutdown, tp);
    ip = (void *)new_player(tp, &addr, addrlen);
    if (ip == NULL)
    {
	telnet_shutdown(tp->t_nd, tp);
    }
    else
    {
	telnet_attach(tp, ip);
	nd_enable(tp->t_nd, ND_R | ND_X);
    }
}
Exemplo n.º 12
0
static int run(void)
{
    player_t* pl[2];
    int res = 0;


    pl[0]= new_player(ch_stream1, ch_stream1_info, 0);
    pl[1]= new_player(ch_stream2, ch_stream2_info, 1);
    hd_channel_invalidate(ch_stream1, 1);
    hd_channel_invalidate(ch_stream2, 1);
    new_osd(ch_osd);
    start_thread();
    signal(SIGINT, signalhandler);
    signal(SIGQUIT, signalhandler);
    signal(SIGTERM, signalhandler);
    signal(SIGSEGV, signalhandlerCrash);
    signal(SIGBUS, signalhandlerCrash);

    hda->hdp_running=1;
    hda->active_player[0] = HD_PLAYER_MODE_LIVE; // Save mode
    hda->active_player[1] = HD_PLAYER_MODE_LIVE; // Save mode
    hda->osd_dont_touch&=~2; // Clear xine draw bit (prevent no fb osd if hdplayer crashes)
    /* TB: avoid busy-waiting */
    while ((res = run_player(pl[0])|run_player(pl[1]))) {
	    if(res==1) 
		    usleep(5*1000);
            if (hda->hdp_terminate==1)
		    break;
    };
    delete_player(pl[1]);
    delete_player(pl[0]);
    hda->hdp_terminate=0;
    printf("hdplayer clean exit %i\n",hda->hdp_terminate);

    return 0;
}
Exemplo n.º 13
0
void io_loop(void)
{
        int n,fmax=0,tmp;						
        fd_set in_fd,out_fd;
        struct timeval tv;
        int panic=0;
	unsigned long long prof;

	if (ticker%8) return;

 	while (panic++<100) {	
                FD_ZERO(&in_fd); FD_ZERO(&out_fd); fmax=0;

                FD_SET(io_sock,&in_fd);
                if (io_sock>fmax) fmax=io_sock;

                for (n=1; n<MAXPLAYER; n++) {
                        if (player[n]) {
                                if (player[n]->in_len<256) {
                                        FD_SET(player[n]->sock,&in_fd);
                                        if (player[n]->sock>fmax) fmax=player[n]->sock;
                                }
			}
			if (player[n]) {
                                if (player[n]->iptr!=player[n]->optr) {
                                        FD_SET(player[n]->sock,&out_fd);
                                        if (player[n]->sock>fmax) fmax=player[n]->sock;
                                }
                        }
                }

                tv.tv_sec=0;
                tv.tv_usec=0;

                tmp=select(fmax+1,&in_fd,&out_fd,NULL,&tv);

                if (tmp<1) break;

                if (FD_ISSET(io_sock,&in_fd)) new_player(io_sock);

                for (n=1; n<MAXPLAYER; n++) {
                        if (!player[n]) continue;
                        if (FD_ISSET(player[n]->sock,&in_fd)) { prof=prof_start(9); rec_player(n); prof_stop(9,prof); }
			if (!player[n]) continue;	// yuck - rec_player might have kicked the player
			if (FD_ISSET(player[n]->sock,&out_fd)){ prof=prof_start(10); send_player(n); prof_stop(10,prof); }
                }
        }
}
Exemplo n.º 14
0
Arquivo: battle.c Projeto: phoboz/yz
BATTLE_ACTOR* new_battle_actor(
    BATTLE *battle,
    int i,
    int j,
    ACTOR *actor,
    ACTOR_TYPE type
)
{
    BATTLE_ACTOR *ba;

    ba = (BATTLE_ACTOR *) malloc( sizeof(BATTLE_ACTOR) );
    if (ba == NULL) {

        fprintf(stderr, "Error - Out of memory\n");
        exit(1);

    }

    memset(ba, 0, sizeof(BATTLE_ACTOR));

    ba->type = type;
    ba->index = battle->counter++;
    ba->i = i;
    ba->j = j;
    listInit(&ba->stepList);
    listInit(&ba->walkList);
    listInit(&ba->attackList);
    listInit(&ba->targetList);
    ba->cursor.i = i;
    ba->cursor.j = j;
    ba->player = new_player(i * BMARKER_WIDTH, j * BMARKER_HEIGHT, actor);

    if ((ba->player->spells[0] = load_spell_XML("fire.stat")) == NULL) {
        fprintf(stderr, "ERROR - Unable to load spell.\n");
        exit(1);
    }

    if ((ba->player->spells[1] = load_spell_XML("heal.stat")) == NULL) {
        fprintf(stderr, "ERROR - Unable to load spell.\n");
        exit(1);
    }

    set_battle_state(battle, ba, BATTLE_STATE_IDLE, NULL);

    return ba;
}
Exemplo n.º 15
0
void network_multiplexer_acceptclient(t_network *network)
{
  t_client *client;
  t_player *player;
  struct rlimit limit;

  getrlimit(RLIMIT_NOFILE, &limit);
  if ((client = network->serv->accept_connect(network->serv)) != NULL)
    {
      if ((network->max_fd + 1) < (int)limit.rlim_cur)
	{
	  if ((player = new_player()) != NULL)
	    network_multiplexer_acceptclient_net(player, client);
	}
      else
	{
	  client->disconnect(client);
	  delete_network_client(client);
	}
    }
}
Exemplo n.º 16
0
int main() {

  // Initial blocks
  uint8_t blocks[5][2] = { {2,1}, {3,5}, {4,5}, {4,6}, {9,8}};

  // Initial start position
  uint8_t startx = WIDTH / 2;
  uint8_t starty = HEIGHT / 2;
	
  int readc = 0, quit = 0, playerid = PLAYER1;
  int textpos = 0;
	
  // Game area
  gamearea* game = new_gamearea(WIDTH,HEIGHT,5,blocks);
	
  // Player
  player* pl1 = new_player(playerid,startx,starty,HEALTH);

  initscr(); // Start ncurses
  noecho(); // Disable echoing of terminal input
  cbreak(); // Individual keystrokes
  intrflush(stdscr, FALSE); // Prevent interrupt flush
  keypad(stdscr,TRUE); // Allow keypad usage 

  start_color(); // Initialize colors

  // Color pairs init_pair(colorpair id,foreground color, background color)
  init_pair(PLAYER1,PLAYER1,COLOR_BLACK); // Player1 = COLOR_RED (1)
  init_pair(PLAYER2,PLAYER2,COLOR_BLACK); // Player2 = COLOR_GREEN (2)
  init_pair(PLAYER3,PLAYER3,COLOR_BLACK); // Player3 = COLOR_YELLOW (3)
  init_pair(PLAYER4,PLAYER4,COLOR_BLACK); // Player4 = COLOR_BLUE (4)
  init_pair(PLAYER_HIT_COLOR,COLOR_RED,COLOR_YELLOW);
  init_pair(WALL_COLOR,COLOR_WHITE,COLOR_WHITE);

  // Prepare everything
  clear_log();
  prepare_horizontal_line(WIDTH);
  ui_draw_grid(game, pl1);

  fd_set readfs;
  int rval = 0;

  while(1) {
    FD_ZERO(&readfs);
    FD_SET(fileno(stdin),&readfs);
 
    // Block until we have something
    if((rval = select(fileno(stdin)+1,&readfs,NULL,NULL,NULL)) > 0) {

      // From user
      if(FD_ISSET(fileno(stdin),&readfs)) {
        readc = getch(); // Get each keypress
        pl1->hitwall = 0;

        switch(readc) {
          case KEY_LEFT:
            if(is_position_a_wall(game,pl1->posx-1,pl1->posy)) pl1->hitwall = 1;
            else pl1->posx--;
            break;
          case KEY_RIGHT:
            if(is_position_a_wall(game,pl1->posx+1,pl1->posy)) pl1->hitwall = 1;
            else pl1->posx++;
            break;
          case KEY_UP:
            if(is_position_a_wall(game,pl1->posx,pl1->posy-1)) pl1->hitwall = 1;
            else pl1->posy--;
            break;
          case KEY_DOWN:
            if(is_position_a_wall(game,pl1->posx,pl1->posy+1)) pl1->hitwall = 1;
            else pl1->posy++;
            break;
          // Function keys, here F1 is reacted to
          case KEY_F(1):
            status = status ^ 1;
            break;
          case 27: // Escape key
            quit = 1;
            break;
          case '/':
            // User wants to write something
            memset(&textbuffer,0,BUFFER);
            textinput = 1;
            textpos = 0;
            break;
          // Erase text
          case KEY_BACKSPACE:
          case KEY_DC:
            textpos--;
            textbuffer[textpos] = '\0';
            break;
          // Push the line to log with enter
          case KEY_ENTER:
          case '\n':
            textinput = 0;
            if(strlen(textbuffer) > 0) add_log(textbuffer,textpos);
            textpos = 0;
            memset(&textbuffer,0,BUFFER);
            break;
          // Add the character to textbuffer if we were inputting text
          default:
            if(textinput == 1) {
              textbuffer[textpos] = readc;
              textpos++;
              if(textpos == BUFFER-1) {
                textpos = 0;
                textinput = 0;
              }
            }
            break;
          }
        }
      }

    // Hit a wall, change player
    if(pl1->hitwall) {
      pl1->health--;
      if(pl1->id == PLAYER4) pl1->id = PLAYER1;
      else pl1->id++;
    }

    // Update screen
    ui_draw_grid(game, pl1);

    // Suicide
    if(pl1->health == 0) {
      ui_draw_end(1);
      break;
    }
		
    // Surrended
    if(quit) {
      ui_draw_end(0);
      break;
    }
  }
  free_gamearea(game);
  free_player(pl1);
  free_horizontal_line();
  sleep(1);
  endwin(); // End ncurses
  return 0;
}