示例#1
0
void init_device(struct device* dev,
    /* ai */
    struct audio_out_backend* aout,
    /* pi */
    uint8_t* rom, size_t rom_size,
    uint8_t* flashram_data, struct storage_backend* flashram_storage,
    uint8_t* sram_data, struct storage_backend* sram_storage,
    /* ri */
    uint32_t* dram, size_t dram_size,
    /* si */
    struct controller_input_backend* cins,
    uint8_t* mpk_data[], struct storage_backend* mpk_storages,
    struct rumble_backend* rumbles,
    uint8_t* eeprom_data, size_t eeprom_size, uint16_t eeprom_id, struct storage_backend* eeprom_storage,
    struct clock_backend* rtc,
    /* vi */
    unsigned int vi_clock, unsigned int expected_refresh_rate, unsigned int count_per_scanline, unsigned int alternate_timing)
{
    init_rdp(&dev->dp, &dev->r4300, &dev->sp, &dev->ri);
    init_rsp(&dev->sp, &dev->r4300, &dev->dp, &dev->ri);
    init_ai(&dev->ai, &dev->r4300, &dev->ri, &dev->vi, aout);
    init_pi(&dev->pi, rom, rom_size, flashram_data, flashram_storage, sram_data, sram_storage, &dev->r4300, &dev->ri);
    init_ri(&dev->ri, dram, dram_size);
    init_si(&dev->si,
        cins,
        mpk_data, mpk_storages,
        rumbles,
        eeprom_data, eeprom_size, eeprom_id, eeprom_storage,
        rtc,
        rom + 0x40,
        &dev->r4300, &dev->ri);
    init_vi(&dev->vi, vi_clock, expected_refresh_rate, count_per_scanline, alternate_timing, &dev->r4300);
}
示例#2
0
/**************************************************************************
  Initialize default ai_type.
**************************************************************************/
void ai_init(void)
{
  struct ai_type *ai = ai_type_alloc();

  init_ai(ai);

  fc_ai_default_setup(ai);
}
示例#3
0
/**************************************************************************
  Load ai module from file.
**************************************************************************/
bool load_ai_module(const char *modname)
{
  struct ai_type *ai = ai_type_alloc();
  bool setup_success;
  lt_dlhandle handle;
  bool (*setup_func)(struct ai_type *ai);
  const char *(*capstr_func)(void);
  const char *capstr;
  char buffer[2048];
  char filename[1024];

  if (ai == NULL) {
    return FALSE;
  }

  init_ai(ai);

  fc_snprintf(filename, sizeof(filename), "fc_ai_%s", modname);
  fc_snprintf(buffer, sizeof(buffer), "%s", filename);
  handle = lt_dlopenext(buffer);
  if (handle == NULL) {
    log_error(_("Cannot open AI module %s (%s)"), filename, fc_module_error());
    return FALSE;
  }

  fc_snprintf(buffer, sizeof(buffer), "%s_capstr", filename);
  capstr_func = lt_dlsym(handle, buffer);
  if (capstr_func == NULL) {
    log_error(_("Cannot find capstr function from ai module %s (%s)"),
              filename, fc_module_error());
    return FALSE;
  }

  capstr = capstr_func();
  if (strcmp(FC_AI_MOD_CAPSTR, capstr)) {
    log_error(_("Incompatible ai module %s:"), filename);
    log_error(_("  Module options:    %s"), capstr);
    log_error(_("  Supported options: %s"), FC_AI_MOD_CAPSTR);

    return FALSE;
  }

  fc_snprintf(buffer, sizeof(buffer), "%s_setup", filename);
  setup_func = lt_dlsym(handle, buffer);
  if (setup_func == NULL) {
    log_error(_("Cannot find setup function from ai module %s (%s)"),
              filename, fc_module_error());
    return FALSE;
  }
  setup_success = setup_func(ai);

  if (!setup_success) {
    log_error(_("Setup of ai module %s failed."), filename);
    return FALSE;
  }

  return TRUE;
}
示例#4
0
void tableinit(GameTable* const gameStat) {
    for (int i = 0; i < Players; ++i) { // 代走させる処理
        if (gameStat->Player[i].ConnectionLost) {
            EnvTable::Instantiate()->PlayerDat[i].RemotePlayerFlag = 0;
            gameStat->Player[i].ConnectionLost = false;
        }
    }
    init_ai(gameStat);
    inittable(gameStat);
    // 局の開始で同期する。1.7系列まではこのとき落ち戻りが可能(落ち戻り機能は1.8で廃止されました)
    statsync(gameStat, mihajong_socket::protocol::Server_StartRound_Signature,
    [](GameTable* const gameStat, int ReceivedMsg) -> bool {
        if (ReceivedMsg == mihajong_socket::protocol::Server_StartRound_Signature) {
            return true;
        } else if (ReceivedMsg == 1023) { // 回線が切れてたら
            EnvTable::Instantiate()->GameMode = EnvTable::Standalone;
            for (int i = 0; i < Players; ++i)
                EnvTable::Instantiate()->PlayerDat[i].RemotePlayerFlag = 0;
            return true;
        } else {
            return false;
        }
    });
    // 牌譜バッファの初期化
    haifu::haifuinit();
    /* 卓の情報を同期 */
    syncTableStat(gameStat);
    // BGMを鳴らす
    choosebgm(gameStat);
    // 画面の準備
    screen(gameStat);
    // 洗牌
    tileshuffle(gameStat);
    // 賽を振る
    bool doraFlag = rolldice(gameStat, false, 0);
#ifndef GUOBIAO
    if (RuleData::chkRule("dice_roll", "roll_twice"))
#endif /* GUOBIAO */
        (void)rolldice(gameStat, doraFlag, 2); // 二度振りの2回目
    // 配牌
    haipai(gameStat);
    return;
}
示例#5
0
int main (int argc, char *argv[]) 
{
  theProgramTitle = argv[0];
  
   init_ai();
   
  /* initialize glut */
  glutInit(&argc, argv);      
  /* request initial window size and position on the screen */
  glutInitWindowSize(theWindowWidth, theWindowHeight);
  glutInitWindowPosition(theWindowPositionX, theWindowPositionY);
  /* request full color with double buffering and depth-based rendering */
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA);
 //glutInitDisplayMode(GLUT_SINGLE | GLUT_DEPTH | GLUT_RGBA);

  /* create window whose title is the name of the executable */
  glutCreateWindow(theProgramTitle);

  /* tell glut how to display model */
  glutDisplayFunc(onDisplay);
  /* tell glutwhat to do when it would otherwise be idle */
  glutIdleFunc(onIdle); 
  /* tell glut how to respond to changes in window size */
  glutReshapeFunc(onReshape);
  /* tell glut how to handle changes in window visibility */
  glutVisibilityFunc(onVisible);
  /* tell glut how to handle key presses */
  glutKeyboardFunc(onAlphaNumericKeyPress);
  glutSpecialFunc(onSpecialKeyPress);
  /* tell glut how to handle the mouse */
  glutMotionFunc(onMouseMotion);
  glutMouseFunc(onMouseButtonPress);

  /* initialize model */
  onInit(argc, argv);

  /* give control over to glut to handle rendering and interaction  */
  glutMainLoop();

  /* program should never get here */
  return 0;
}
示例#6
0
文件: gtnw.c 项目: laudarch/wargames
/* play a game of Global Thermonuclear War! */
void global_thermonuclear_war(void)
{
  srand(time(0)); // might want to move to main()...
  surrender=false;
  clear();
  for(int i=0;i<sizeof(const_map)/sizeof(const char*);++i)
    {
      strcpy(map[i], const_map[i]);
    }
  /* print the map */
  for(int i=0;i<sizeof(map)/sizeof(const char*);++i)
    {
      print_string(map[i]);
      print_string("\n");
    }
  
  /* get the side the user wants to be on */
  print_string("\nWHICH SIDE DO YOU WANT?\n\n  1.  UNITED STATES\n  2.  SOVIET UNION\n\n");
  bool good=false;
  unsigned int side=0;
  while(!good)
    {
      print_string("PLEASE CHOOSE ONE:  ");
      scanw("%u", &side);
      if(side==1 || side==2)
        good=true;
    }
  clear();
  do_first_strike(side);
  long long us_pop=0, ussr_pop;
  calc_pops(&us_pop, &ussr_pop);
  init_ai(side);
  while(us_pop!=0 && ussr_pop!=0 && !surrender)
    {
      do_human_move(side);
      calc_pops(&us_pop, &ussr_pop);
      if(us_pop!=0 && ussr_pop!=0 && !surrender)
        {
          do_ai_move(side);
          calc_pops(&us_pop, &ussr_pop);
        }
    }
  print_string("\n\n");
  if(!surrender)
    {
      if(us_pop==0 && ussr_pop==0)
        {
          print_string("WINNER: NONE\n\n");
        }
      else if(us_pop==0)
        {
          print_string("WINNER: SOVIET UNION\n\n");
        }
      else if(ussr_pop==0)
        {
          print_string("WINNER: UNITED STATES\n\n");
        }
    }
  else
    {
      switch(winner)
        {
        case 1:
          print_string("WINNER: UNITED STATES\n\n");
          break;
        case 2:
          print_string("WINNER: SOVIET UNION\n\n");
          break;
        }
    }
}
示例#7
0
void startClient() {
	char *logfile = "/sdcard/client.out";
	FILE *fp;
	  if((fp=freopen("/sdcard/freeciv_out_client.log", "w" ,stdout))==NULL) {
	    printf("Cannot open file.\n");
	    exit(1);
	  }

	  if((fp=freopen("/sdcard/freeciv_err_client.log", "w" ,stderr))==NULL) {
	    printf("Cannot open file.\n");
	    exit(1);
	  }

	  setenv ("HOME", "/sdcard/FreeCiv", 0);
	  setenv ("USER", "Sparky", 0);

	LOGI("Hello JNI");
	  log_init(logfile, LOG_DEBUG
			  , NULL);
	int i, loglevel;
	int ui_options = 0;
	bool ui_separator = FALSE;
	char *option=NULL;
	bool user_tileset = FALSE;

	  i_am_client(); /* Tell to libfreeciv that we are client */

	  /* Ensure that all AIs are initialized to unused state */
	  ai_type_iterate(ai) {
	    init_ai(ai);
	  } ai_type_iterate_end;




	init_our_capability();


	  (void)user_username(default_user_name, MAX_LEN_NAME);
	  if (!is_valid_username(default_user_name)) {
	    char buf[sizeof(default_user_name)];

	    my_snprintf(buf, sizeof(buf), "_%s", default_user_name);
	    if (is_valid_username(buf)) {
	      sz_strlcpy(default_user_name, buf);
	    } else {
	      my_snprintf(default_user_name, sizeof(default_user_name),
			  "player%d", myrand(10000));
	    }
	  }

	  game.all_connections = conn_list_new();
	  game.est_connections = conn_list_new();

	  ui_init();

	  fc_init_network();

	  init_our_capability();
	  chatline_common_init();
	  init_player_dlg_common();
	  init_themes();

	  options_init();

	  strcpy(default_sound_plugin_name,"none");

	  server_port = 9999;
	  sz_strlcpy(server_host, "localhost");
	  options_load();

	  mysrand(time(NULL));
	  helpdata_init();
	  boot_help_texts(NULL);




	  LOGI("Reading tilespec");
	  tilespec_try_read("amplio2", TRUE);
	  LOGI("Done reading tilespec");
	  overview_size_changed();

	  audio_real_init("stdsounds", "none");
	  //audio_play_music("music_start", NULL);

	  auto_connect = TRUE;

	  init_mapcanvas_and_overview();

	  /* run gui-specific client */
	  ui_main(0, NULL);

	  /* termination */
	  client_exit();

	return;
}
void init_device(
      struct device *dev,
      /* r4300 */
      unsigned int emumode,
      unsigned int count_per_op,
      int special_rom,
      /* ai */
      void * ai_user_data, void (*ai_set_audio_format)(void*,unsigned int, unsigned int),
      void (*ai_push_audio_samples)(void*,const void*,size_t),
      unsigned int fixed_audio_pos,
      /* pi */
      uint8_t *rom,
      size_t rom_size,
      void* flashram_user_data, void (*flashram_save)(void*), uint8_t* flashram_data,
      void* sram_user_data, void (*sram_save)(void*), uint8_t* sram_data,
      /* ri */
      uint32_t* dram, size_t dram_size,
      /* si */
      void* eeprom_user_data, void (*eeprom_save)(void*), uint8_t* eeprom_data, size_t eeprom_size, uint16_t eeprom_id,
      void* af_rtc_user_data, const struct tm* (*af_rtc_get_time)(void*),
      /* sp */
      unsigned int audio_signal,
      /* vi */
      unsigned int vi_clock,
      unsigned int expected_refresh_rate,
      uint8_t *ddrom,
      size_t ddrom_size,
      uint8_t *dd_disk,
      size_t dd_disk_size
      )
{
   init_r4300(&dev->r4300, emumode, count_per_op, special_rom);
   init_rdp(&dev->dp, &dev->r4300, &dev->sp, &dev->ri);
   init_rsp(&dev->sp, &dev->r4300, &dev->dp, &dev->ri, audio_signal);
   init_ai(&dev->ai, ai_user_data,
         ai_set_audio_format,
         ai_push_audio_samples,
         &dev->r4300, &dev->ri, &dev->vi,
	 fixed_audio_pos);
   init_pi(&dev->pi,
         rom, rom_size,
         ddrom, ddrom_size,
         flashram_user_data, flashram_save, flashram_data,
         sram_user_data, sram_save, sram_data,
         &dev->r4300, &dev->ri);
   init_ri(&dev->ri, dram, dram_size);
   init_si(&dev->si,
         eeprom_user_data,
         eeprom_save,
         eeprom_data,
         eeprom_size,
         eeprom_id,
         af_rtc_user_data,
         af_rtc_get_time,
         ((ddrom != NULL) && (ddrom_size != 0) && (rom == NULL) && (rom_size == 0)) ?
         (ddrom + 0x40) : (rom + 0x40),                       /* ipl3 */
         &dev->r4300, &dev->ri);

   init_vi(&dev->vi, vi_clock, expected_refresh_rate, &dev->r4300);
   init_dd(&dev->dd, &dev->r4300, dd_disk, dd_disk_size);
}
示例#9
0
/**************************************************************************
  Initialize ai stuff
**************************************************************************/
void ai_init(void)
{
  bool failure = FALSE;
#if !defined(AI_MODULES) || defined(AI_MOD_STATIC_CLASSIC) || defined(AI_MOD_STATIC_THREADED)
  /* First !defined(AI_MODULES) case is for default ai support. */
  struct ai_type *ai;
#endif

#ifdef AI_MODULES
  if (lt_dlinit()) {
    failure = TRUE;
  }
  if (!failure) {

#ifdef DEBUG
    /* First search ai modules under directory ai/<module> under
       current directory. This allows us to run freeciv without
       installing it. */
    const char *moduledirs[] = { "default", "threaded", "stub", NULL };
    int i;

    for (i = 0; moduledirs[i] != NULL ; i++) {
      char buf[2048];

      fc_snprintf(buf, sizeof(buf), "ai/%s", moduledirs[i]);
      lt_dladdsearchdir(buf);
    }
#endif /* DEBUG */

    /* Then search ai modules from their installation directory. */
    lt_dladdsearchdir(AI_MODULEDIR);
  }
#endif /* AI_MODULES */

#if defined(AI_MODULES) && !defined(AI_MOD_STATIC_CLASSIC)

  if (!failure && !load_ai_module("classic")) {
    failure = TRUE;
  }

#else  /* AI_MOD_STATIC_CLASSIC */

  ai = ai_type_alloc();
  init_ai(ai);
  if (!fc_ai_classic_setup(ai)) {
    failure = TRUE;
  }

#endif /* AI_MOD_STATIC_CLASSIC */

  if (failure) {
    log_fatal(_("Failed to setup default AI module, cannot continue."));
    exit(EXIT_FAILURE);
  }

  default_ai = ai;

#ifdef AI_MOD_STATIC_THREADED
  ai = ai_type_alloc();
  if (ai != NULL) {
    init_ai(ai);
    if (!fc_ai_threaded_setup(ai)) {
      log_error(_("Failed to setup threaded AI module"));
    }
  }
#endif /* AI_MOD_STATIC_THREADED */
}
示例#10
0
文件: oun_init.cpp 项目: 112212/7k2
//--------- Begin of function Unit::init ---------//
//
// <int> unitId               - the id. of the unit
// <int> nationRecno          - the recno of nation
// [int] rankId               - rank id. of the unit (none for non-human unit)
// [int] unitLoyalty          - loyalty of the unit  (none for non-human unit)
// [int] startXLoc, startYLoc - the starting location of the unit
//                              (if startXLoc < 0, this is a unit for hire, and is not a unit of the game yet. init_sprite() won't be called for this unit)
//                              (default: -1, -1)
//
// Note: sprite_recno must be initialized first before calling Unit::init()
//
void Unit::init(int unitId, int nationRecno, int rankId, int unitLoyalty, int startXLoc, int startYLoc)
{
	//------------ set basic vars -------------//

	nation_recno  = (char) nationRecno;
	rank_id       = rankId;       // rank_id must be initialized before init_unit_id() as init_unit_id() may overwrite it

	if( rank_id == RANK_GENERAL || rank_id == RANK_KING )
	{
		err_when( team_info );
		team_info = (TeamInfo*) mem_add( sizeof(TeamInfo) );
		memset( team_info, 0, sizeof(TeamInfo) );
	}

	init_unit_id(unitId);

	race_id = (char) unit_res[unit_id]->race_id;

	//------- init unit name ---------//

	if( is_human() && unit_id != UNIT_WAGON )
	{
		name_id = race_res[race_id]->get_new_name_id();
	}
	else if( is_monster() )
	{
		name_id = monster_res.get_new_name_id();
	}
	else  //---- init non-human unit series no. ----//
	{
		if( nation_recno )
			name_id = ++nation_array[nation_recno]->last_unit_name_id_array[unit_id-1];
		else
			name_id = 0;
	}

	// ###### begin Gilbert 23/2 ######//
	unique_id = misc.rand_long();
	// ###### end Gilbert 23/2 ######//

	//---------- init other vars ----------//

	err_when( unitLoyalty < 0 || unitLoyalty > 100 );

	loyalty = unitLoyalty;

	// ##### begin Gilbert 29/5 ########//
	if( is_die_after_attack() )
		// behavior_mode = UNIT_STAND_GROUND;		// bee die after attack, so don't waste his life
		behavior_mode = UNIT_DEFENSIVE;		// bee die after attack, so don't waste his life
	else
		behavior_mode = UNIT_AGGRESSIVE;		// the default mode is aggressive
	// ##### end Gilbert 29/5 ########//

	//--------- init skill, and skill potential ---------//

	skill.init(unit_id, 100);
	set_combat_level(-1);

	hit_points = (float) max_hit_points();

	//------ initialize the base Sprite class -------//

	if( startXLoc >= 0 )
		init_sprite( startXLoc, startYLoc );
	else
		cur_x = -1;

	//-------------- update loyalty -------------//

	update_loyalty();

	//--------------- init AI info -------------//

	init_ai();

	//----------- init derived class ----------//

	init_derived();

	set_combat_level(-1);
}