Esempio n. 1
0
int		print_loadbar(t_all *all, t_image *together,
			      double minmax, time_t start)
{
  static int	last_pc = -1;
  static int	last_time = -1;
  time_t	elapsed;
  int		pos;

  pos = (WIN_X / 2) - (630 / 2);
  elapsed = time(NULL) - start;
  if (last_time == elapsed && ABS(last_pc - minmax) < 5 && minmax != 100)
    return (0);
  mlx_clear_window(all->mlx_ptr, all->win_ptr);
  get_motd(all, elapsed);
  mlx_put_image_to_window(all->mlx_ptr, all->win_ptr,
			  together[0].img_ptr, pos, 2 * WIN_Y / 3);
  mlx_put_image_to_window(all->mlx_ptr, all->win_ptr,
			  together[1].img_ptr, pos + 30, 2 * WIN_Y / 3);
  mlx_put_image_to_window(all->mlx_ptr, all->win_ptr,
			  together[2].img_ptr,
			  pos + (minmax * 6) + 30, 2 * WIN_Y / 3);
  put_info(all, elapsed, minmax);
  last_time = elapsed;
  last_pc = minmax;
  return (0);
}
Esempio n. 2
0
//--------- Begin of function FirmHarbor::del_hosted_ship ---------//
//
void FirmHarbor::del_hosted_ship(int delUnitRecno)
{
	//---- reset the unit_mode of the ship ----//

	unit_array[delUnitRecno]->set_mode(0);

	//-----------------------------------------//

	int i;
	for( i=0 ; i<ship_count ; i++ )
	{
		if( ship_recno_array[i] == delUnitRecno )
		{
			err_when( ship_count > MAX_SHIP_IN_HARBOR );

			misc.del_array_rec( ship_recno_array, ship_count, sizeof(ship_recno_array[0]), i+1 );
			break;
		}
	}

	err_when( i==ship_count );

	ship_count--;

	if( firm_recno == firm_array.selected_recno )
		put_info(INFO_UPDATE);
}
Esempio n. 3
0
/*
 * dump the file into the fd
 */
static void dump_file(gzFile fd, struct log_global_header *hdr)
{
   struct log_header_packet pck;
   struct log_header_info inf;
   struct dissector_info infbuf;
   u_char *pckbuf;
   int count = 0;

   /* loop until EOF */
   LOOP {
      switch (hdr->type) {
         case LOG_INFO:
            if (get_info(&inf, &infbuf) != E_SUCCESS) {
               printf("\n");
               return;
            }
            /* write the info */
            put_info(fd, &inf, &infbuf);
	    SAFE_FREE(infbuf.user);
            SAFE_FREE(infbuf.pass);
            SAFE_FREE(infbuf.info);
            SAFE_FREE(infbuf.banner);

            break;

         case LOG_PACKET:
            if (get_packet(&pck, &pckbuf) != E_SUCCESS) {
               printf("\n");
               return;
            }
            /* write the data */
            put_packet(fd, &pck, pckbuf);
            SAFE_FREE(pckbuf);
            break;
            
         default:
            FATAL_ERROR("Unknown log type");
            break;
      }
      
      /* a dot every 10 packets */
      if (count++ % 10 == 0) {
         printf(".");
         fflush(stdout);
      }
   }

}
Esempio n. 4
0
//--------- Begin of function FirmHarbor::add_hosted_ship ---------//
//
void FirmHarbor::add_hosted_ship(int shipRecno)
{
	err_when( ship_count == MAX_SHIP_IN_HARBOR );

	ship_recno_array[ship_count++] = shipRecno;

	//---- set the unit_mode of the ship ----//

	err_when( firm_id != FIRM_HARBOR );

	unit_array[shipRecno]->set_mode(UNIT_MODE_IN_HARBOR, firm_recno);

	//---------------------------------------//

	if( firm_recno == firm_array.selected_recno )
		put_info(INFO_UPDATE);
}
Esempio n. 5
0
t_wid		*update_val_spot(t_wid *wid)
{
  int		id;
  t_spot	*tmp;

  id = 0;
  if (wid->data.spot == NULL)
    return (wid);
  tmp = wid->data.spot;
  while (id != wid->spot_id)
    {
      tmp = tmp->next;
      id++;
    }
  if (tmp != NULL)
    put_info(wid, tmp);
  return (wid);
}
Esempio n. 6
0
void
update_info_taper(
    disk_t *dp,
    char *label,
    off_t filenum,
    int level)
{
    info_t info;
    stats_t *infp;
    int rc;

    rc = open_infofile(getconf_str(CNF_INFOFILE));
    if(rc) {
	error(_("could not open infofile %s: %s (%d)"), getconf_str(CNF_INFOFILE),
	      strerror(errno), rc);
	/*NOTREACHED*/
    }

    get_info(dp->host->hostname, dp->name, &info);

    infp = &info.inf[level];
    /* XXX - should we record these two if no-record? */
    strncpy(infp->label, label, sizeof(infp->label)-1);
    infp->label[sizeof(infp->label)-1] = '\0';
    infp->filenum = filenum;

    info.command = NO_COMMAND;

    if (put_info(dp->host->hostname, dp->name, &info)) {
	int save_errno = errno;
	g_fprintf(stderr, _("infofile update failed (%s,'%s'): %s\n"),
		  dp->host->hostname, dp->name, strerror(save_errno));
	log_add(L_ERROR, _("infofile update failed (%s,'%s'): %s\n"),
		dp->host->hostname, dp->name, strerror(save_errno));
	error(_("infofile update failed (%s,'%s'): %s\n"),
	      dp->host->hostname, dp->name, strerror(save_errno));
	/*NOTREACHED*/
    }
    close_infofile();
}
Esempio n. 7
0
void
update_info_dumper(
     disk_t *dp,
     off_t origsize,
     off_t dumpsize,
     time_t dumptime)
{
    int level, i;
    info_t info;
    stats_t *infp;
    perf_t *perfp;
    char *conf_infofile;

    level = sched(dp)->level;

    conf_infofile = config_dir_relative(getconf_str(CNF_INFOFILE));
    if (open_infofile(conf_infofile)) {
	error(_("could not open info db \"%s\""), conf_infofile);
	/*NOTREACHED*/
    }
    amfree(conf_infofile);

    get_info(dp->host->hostname, dp->name, &info);

    /* Clean up information about this and higher-level dumps.  This
       assumes that update_info_dumper() is always run before
       update_info_taper(). */
    for (i = level; i < DUMP_LEVELS; ++i) {
      infp = &info.inf[i];
      infp->size = (off_t)-1;
      infp->csize = (off_t)-1;
      infp->secs = (time_t)-1;
      infp->date = (time_t)-1;
      infp->label[0] = '\0';
      infp->filenum = 0;
    }

    /* now store information about this dump */
    infp = &info.inf[level];
    infp->size = origsize;
    infp->csize = dumpsize;
    infp->secs = dumptime;
    if (sched(dp)->timestamp == 0) {
	infp->date = 0;
    } else {
	infp->date = get_time_from_timestamp(sched(dp)->datestamp);
    }

    if(level == 0) perfp = &info.full;
    else perfp = &info.incr;

    /* Update the stats, but only if the new values are meaningful */
    if(dp->compress != COMP_NONE && origsize > (off_t)0) {
	newperf(perfp->comp, (double)dumpsize/(double)origsize);
    }
    if(dumptime > (time_t)0) {
	if((off_t)dumptime >= dumpsize)
	    newperf(perfp->rate, 1);
	else
	    newperf(perfp->rate, (double)dumpsize/(double)dumptime);
    }

    if(origsize >= (off_t)0 && getconf_int(CNF_RESERVE)<100) {
	info.command = NO_COMMAND;
    }

    if (origsize >= (off_t)0 && level == info.last_level) {
	info.consecutive_runs++;
    } else if (origsize >= (off_t)0) {
	info.last_level = level;
	info.consecutive_runs = 1;
    }

    if(origsize >= (off_t)0 && dumpsize >= (off_t)0) {
	for(i=NB_HISTORY-1;i>0;i--) {
	    info.history[i] = info.history[i-1];
	}

	info.history[0].level = level;
	info.history[0].size  = origsize;
	info.history[0].csize = dumpsize;
	if (sched(dp)->timestamp == 0) {
	    info.history[0].date = 0;
	} else {
	    info.history[0].date = get_time_from_timestamp(sched(dp)->datestamp);
	}
	info.history[0].secs  = dumptime;
    }

    if (put_info(dp->host->hostname, dp->name, &info)) {
	int save_errno = errno;
	g_fprintf(stderr, _("infofile update failed (%s,'%s'): %s\n"),
		  dp->host->hostname, dp->name, strerror(save_errno));
	log_add(L_ERROR, _("infofile update failed (%s,'%s'): %s\n"),
		dp->host->hostname, dp->name, strerror(save_errno));
	error(_("infofile update failed (%s,'%s'): %s\n"),
	      dp->host->hostname, dp->name, strerror(save_errno));
	/*NOTREACHED*/
    }

    close_infofile();
}
Esempio n. 8
0
//--------- Begin of function Firm::disp_info_both ---------//
//
void Firm::disp_info_both(int refreshFlag)
{
	static char  lastUnderConstruction;
	static short lastFirmRecno;
	static char  lastShouldShowInfo;
	static short lastPlayerSpyCount;

	//------ check if under_construction has been changed -----//

	if( lastUnderConstruction != under_construction )
	{
		lastUnderConstruction = under_construction;

		if( refreshFlag == INFO_UPDATE )
			info.disp();							// refresh the display
	}

	//--------------------------------------------//

	if( under_construction )
	{
		disp_basic_info(INFO_Y1, refreshFlag);

		if( refreshFlag == INFO_REPAINT )
			font_san.d3_put( INFO_X1, INFO_Y1+54, INFO_X2, INFO_Y1+74, _("Under Construction") );
	}
	else
	{
		//------ check if should_show_info() has been changed -----//

		int shouldShowInfo = should_show_info();

		if( shouldShowInfo   != lastShouldShowInfo ||
			 player_spy_count != lastPlayerSpyCount )
		{
			lastShouldShowInfo = shouldShowInfo;
			lastPlayerSpyCount = player_spy_count;

			if( refreshFlag == INFO_UPDATE )
			{
				info.disp();
				return;
			}
		}

		//----------------------------------------//

		if( lastFirmRecno != firm_recno ||
			 (firm_menu_mode != FIRM_MENU_ASSASSINATE_RESULT &&
			  player_spy_count==0 && bribe_result==BRIBE_NONE) )		// don't refresh mode if the player spy in the firm has just failed the bribing and executed, and we now need to display the failure message
		{
			firm_menu_mode = FIRM_MENU_MAIN;
			lastFirmRecno = firm_recno;
			bribe_result  = BRIBE_NONE;
		}

		switch( firm_menu_mode )
		{
			case FIRM_MENU_MAIN:
				put_info(refreshFlag);
				break;

			case FIRM_MENU_SPY:
			case FIRM_MENU_SELECT_BRIBER:
				disp_spy_menu(refreshFlag);
				break;

			case FIRM_MENU_SET_BRIBE_AMOUNT:
				disp_bribe_menu(refreshFlag);
				break;

			case FIRM_MENU_VIEW_SECRET:
				spy_array.disp_view_secret_menu(action_spy_recno, refreshFlag);
				break;

			case FIRM_MENU_ASSASSINATE_RESULT:
				disp_assassinate_result(refreshFlag);
				break;
		}

		#ifdef DEBUG
		if(debug2_enable_flag)
		{
			font_san.d3_put( INFO_X1, INFO_Y2-30, INFO_X2, INFO_Y2, "" );
			font_san.field( INFO_X1+10, INFO_Y2-20, " ", INFO_X1+20, firm_recno, 1, INFO_X2-10, refreshFlag);
			font_san.field( INFO_X1+40, INFO_Y2-20, " ", INFO_X1+50, loc_x1, 1, INFO_X2-10, refreshFlag);
			font_san.field( INFO_X1+70, INFO_Y2-20, " ", INFO_X1+80, loc_y1, 1, INFO_X2-10, refreshFlag);
			font_san.field( INFO_X1+100, INFO_Y2-20, " ", INFO_X1+110, ai_link_checked, 1, INFO_X2-10, refreshFlag);
		}
		#endif
	}
}
Esempio n. 9
0
//--------- Begin of function FirmInn::hire ---------//
//
int FirmInn::hire(short recNo)
{
	err_when( recNo < 1 );

	if( recNo > inn_unit_count )		// this may happen in a multiplayer game
		return 0;

	//--------- first check if you have enough money to hire ------//

	InnUnit* innUnit;
	Nation* 	nationPtr		= nation_array[nation_recno];

	innUnit = inn_unit_array+recNo-1;

	if( nationPtr->cash < innUnit->hire_cost )
		return 0;

	//---------- add the unit now -----------//

	int unitRecno = create_unit( innUnit->unit_id );
	if(!unitRecno)
		return 0; // no space for creating the unit

	nationPtr->add_expense(EXPENSE_HIRE_UNIT, innUnit->hire_cost);

	//-------- set skills of the unit --------//

	Unit* unitPtr = unit_array[unitRecno];

	memcpy( &(unitPtr->skill), &(innUnit->skill), sizeof(Skill) );

	err_when( innUnit->skill.combat_level<=0 || innUnit->skill.combat_level>100 );

	unitPtr->set_combat_level( innUnit->skill.combat_level );

	//-------- if the unit's skill is spying -----//

	if( unitPtr->skill.skill_id == SKILL_SPYING )
	{
		unitPtr->spy_recno = spy_array.add_spy(unitRecno, unitPtr->skill.skill_level);
		unitPtr->skill.skill_id = 0;		// reset its primary skill, its spying skill has been recorded in spy_array
	}

	//----------------------------------------//
	//
	// Loyalty of the hired unit
	//
	// = 30 + the nation's reputation / 2 + 30 if racially homogenous
	//
	//----------------------------------------//

	int unitLoyalty = 30 + (int)nationPtr->reputation/2;

	if( race_res.is_same_race(unitPtr->race_id, nationPtr->race_id) )
		unitLoyalty += 20;

	unitLoyalty = MAX( 40, unitLoyalty );
	unitLoyalty = MIN( 100, unitLoyalty );

	if( unitPtr->spy_recno )
		spy_array[unitPtr->spy_recno]->spy_loyalty = unitLoyalty;
	else
		unitPtr->loyalty = unitLoyalty; 

	//---- remove the record from the hire list ----//

	del_inn_unit(recNo);

	if( firm_recno == firm_array.selected_recno &&
		 nation_recno == nation_array.player_recno )
	{
		put_info(INFO_UPDATE);
	}

	return unitRecno;
}