コード例 #1
0
ファイル: nmea.c プロジェクト: imh/piksi_firmware
/** Assemble an NMEA GPRMC message and send it out NMEA USARTs.
 * NMEA RMC contains minimum GPS data 
 *
 * \param nav_meas Pointer to navigation_measurement struct.
 * \param soln Pointer to gnss_solution struct
 * \param gps_t Pointer to the current GPS Time
 */
void nmea_gprmc(const navigation_measurement_t *nav_meas,
                const gnss_solution *soln, const gps_time_t *gps_t)
{
  
  /* NMEA Parameters
   * Ex.
   * $GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70
   *   |      |    |    |    |    |     |   |      |      |     |  |  |
   * Command  |    |   Lat  N/S   |     |   |      | Date Stamp | W/E |
   *    Time (UTC) |            Long   W/E  |  True Course      |   Cksum
   *            Validity (A-OK)           Speed            Variation 
   * Variation is ignored as we have no way to maintain that information
   * currently
   */
  time_t unix_t;
  struct tm t;

  unix_t = gps2time(*gps_t);
  gmtime_r(&unix_t, &t);
  double frac_s = fmod(gps_t->tow, 1.0);

  s16 lat_deg = R2D * (soln->pos_llh[0]);
  double lat_min = MINUTES(soln->pos_llh[0]);
  s16 lon_deg = R2D * (soln->pos_llh[1]);
  double lon_min = MINUTES(soln->pos_llh[1]);
  lat_deg = abs(lat_deg);
  lon_deg = abs(lon_deg);

  char lat_dir = soln->pos_llh[0] < 0 ? 'S' : 'N';
  char lon_dir = soln->pos_llh[1] < 0 ? 'W' : 'E';

  float velocity;
  float x,y,z;
  x = soln->vel_ned[0];
  y = soln->vel_ned[1];
  z = soln->vel_ned[2];
  float course = atan2(y,x);

  /* Conversion to magnitue knots */
  velocity = MS2KNOTTS(x,y,z);

  double az, el;
  wgsecef2azel(nav_meas[0].sat_pos, soln->pos_ecef, &az, &el);

  char buf[100];
  u8 n = sprintf(buf,
                "$GPRMC,%02d%02d%06.3f,A," /* Command, Time (UTC), Valid */
                "%02d%010.7f,%c,%03d%010.7f,%c," /* Lat/Lon */
                "%06.2f,%05.1f," /* Speed, Course */
                "%02d%02d%02d," /* Date Stamp */
                ",", /* Variation */
                t.tm_hour, t.tm_min, t.tm_sec + frac_s,
                lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir,
                velocity, course * R2D, 
                t.tm_mday, t.tm_mon, t.tm_year-100);

  u8 sum = nmea_checksum(buf);
  sprintf(buf + n, "*%02X\r\n", sum);
  nmea_output(buf);
}
コード例 #2
0
void 
starttourn(void)
{
    int     i, j;
    struct planet *pl;
    char    s[80];

    opentlog();
    for (i = 0, pl = &planets[i]; i < NUMPLANETS; i++, pl++) {
	for (j = 0; j < MAXTEAM + 1; j++) {
	    pl->pl_tinfo[j].timestamp = 0;
	    /* doesn't work? */
	    pl->pl_hinfo = (PL_TYPE(*pl) == PLSTAR) ? ALLTEAM : pl->pl_owner;
	}
    }
    status->clock = 0;

    explode_everyone(KTOURNSTART, 0);

    tlog_all();


    status2->league++;
    status2->leagueticksleft = MINUTES(configvals->regulation_minutes);

    /* version team names configured time date */
    pmessage(" ", 0, MALL, UMPIRE);
    sprintf(s, "Timer started -- %d minutes remaining",
	    status2->leagueticksleft / MINUTES(1));
    pmessage(s, 0, MALL, UMPIRE);
    pmessage(" ", 0, MALL, UMPIRE);
}
コード例 #3
0
ファイル: cmd.c プロジェクト: 0bliv10n/s2e
void
timestr(
	struct timeval	*tv,
	char		*ts,
	size_t		size,
	int		format)
{
	double		usec = (double)tv->tv_usec / 1000000.0;

	if (format & TERSE_FIXED_TIME) {
		if (!HOURS(tv->tv_sec)) {
			snprintf(ts, size, "%u:%02u.%02u",
				(unsigned int) MINUTES(tv->tv_sec),
				(unsigned int) SECONDS(tv->tv_sec),
				(unsigned int) (usec * 100));
			return;
		}
		format |= VERBOSE_FIXED_TIME;	/* fallback if hours needed */
	}

	if ((format & VERBOSE_FIXED_TIME) || tv->tv_sec) {
		snprintf(ts, size, "%u:%02u:%02u.%02u",
			(unsigned int) HOURS(tv->tv_sec),
			(unsigned int) MINUTES(tv->tv_sec),
			(unsigned int) SECONDS(tv->tv_sec),
			(unsigned int) (usec * 100));
	} else {
		snprintf(ts, size, "0.%04u sec", (unsigned int) (usec * 10000));
	}
}
コード例 #4
0
int recipe::print_time( WINDOW *w, int ypos, int xpos, int width,
                        nc_color col, int batch ) const
{
    const int turns = batch_time( batch ) / 100;
    std::string text;
    if( turns < MINUTES( 1 ) ) {
        const int seconds = std::max( 1, turns * 6 );
        text = string_format( ngettext( "%d second", "%d seconds", seconds ), seconds );
    } else {
        const int minutes = ( turns % HOURS( 1 ) ) / MINUTES( 1 );
        const int hours = turns / HOURS( 1 );
        if( hours == 0 ) {
            text = string_format( ngettext( "%d minute", "%d minutes", minutes ), minutes );
        } else if( minutes == 0 ) {
            text = string_format( ngettext( "%d hour", "%d hours", hours ), hours );
        } else {
            const std::string h = string_format( ngettext( "%d hour", "%d hours", hours ), hours );
            const std::string m = string_format( ngettext( "%d minute", "%d minutes", minutes ), minutes );
            //~ A time duration: first is hours, second is minutes, e.g. "4 hours" "6 minutes"
            text = string_format( _( "%1$s and %2$s" ), h.c_str(), m.c_str() );
        }
    }
    text = string_format( _( "Time to complete: %s" ), text.c_str() );
    return fold_and_print( w, ypos, xpos, width, col, text );
}
コード例 #5
0
ファイル: calendar.cpp プロジェクト: alapazam/Cataclysm-DDA
std::string to_string( const time_duration &d )
{
    const int turns = to_turns<int>( d );
    int divider = 0;

    if( turns > MINUTES( 1 ) && turns < calendar::INDEFINITELY_LONG ) {
        if( turns < HOURS( 1 ) ) {
            divider = MINUTES( 1 );
        } else if( turns < DAYS( 1 ) ) {
            divider = HOURS( 1 );
        } else {
            divider = DAYS( 1 );
        }
    }

    const int remainder = divider ? turns % divider : 0;
    if( remainder != 0 ) {
        //~ %1$s - greater units of time (e.g. 3 hours), %2$s - lesser units of time (e.g. 11 minutes).
        return string_format( _( "%1$s and %2$s" ),
                              to_string_clipped( time_duration::from_turns( turns ) ),
                              to_string_clipped( time_duration::from_turns( remainder ) ) );
    }

    return to_string_clipped( d );
}
コード例 #6
0
ファイル: weather.cpp プロジェクト: Bubbadoo/Cataclysm-DDA
////// Funnels.
weather_sum sum_conditions( const calendar &startturn,
                            const calendar &endturn,
                            const tripoint &location )
{
    int tick_size = MINUTES(1);
    weather_sum data;

    for( calendar turn(startturn); turn < endturn; turn += tick_size ) {
        const int diff = endturn - startturn;
        if( diff <= 0 ) {
            return data;
        } else if( diff < 10 ) {
            tick_size = 1;
        } else if( diff > DAYS(7) ) {
            tick_size = HOURS(1);
        } else {
            tick_size = MINUTES(1);
        }

        const auto wtype = g->weather_gen->get_weather_conditions( point( location.x, location.y ), turn );
        proc_weather_sum( wtype, data, turn, tick_size );
    }

    return data;
}
コード例 #7
0
mon_id MonsterGroupManager::GetMonsterFromGroup( std::string group, std::vector <mtype*> *mtypes,
                                                 int *quantity, int turn )
{
    int roll = rng(1, 1000);
    MonsterGroup g = monsterGroupMap[group];
    for (FreqDef_iter it = g.monsters.begin(); it != g.monsters.end(); ++it)
    {
        if((turn == -1 || (turn + 900 >= MINUTES(STARTING_MINUTES) + HOURS((*mtypes)[it->first]->difficulty))) &&
           (!OPTIONS["CLASSIC_ZOMBIES"] ||
            (*mtypes)[it->first]->in_category(MC_CLASSIC) ||
            (*mtypes)[it->first]->in_category(MC_WILDLIFE)))
        {   //Not too hard for us (or we dont care)
            if(it->second.first >= roll)
            {
                if( quantity) { *quantity -= it->second.second; }
                return it->first;
            }
            else { roll -= it->second.first; }
        }
    }
    if ((turn + 900 < MINUTES(STARTING_MINUTES) + HOURS((*mtypes)[g.defaultMonster]->difficulty))
        && (!OPTIONS["STATIC_SPAWN"]))
    {
        return mon_null;
    }
    else
    {
        return g.defaultMonster;
    }
}
コード例 #8
0
ファイル: nmea.c プロジェクト: kovach/piksi_firmware
/** Assemble a NMEA GPGGA message and send it out NMEA USARTs.
 * NMEA GPGGA message contains Global Positioning System Fix Data.
 *
 * \param soln Pointer to gnss_solution struct.
 * \param dops Pointer to dops_t struct.
 */
void nmea_gpgga(const double pos_llh[3], const gps_time_t *gps_t, u8 n_used,
                u8 fix_type, double hdop)
{
  time_t unix_t;
  struct tm t;

  unix_t = gps2time(*gps_t);
  gmtime_r(&unix_t, &t);

  double frac_s = fmod(gps_t->tow, 1.0);

  s16 lat_deg = R2D * (pos_llh[0]);
  double lat_min = MINUTES(pos_llh[0]);
  s16 lon_deg = R2D * (pos_llh[1]);
  double lon_min = MINUTES(pos_llh[1]);
  lat_deg = abs(lat_deg);
  lon_deg = abs(lon_deg);

  char lat_dir = pos_llh[0] < 0 ? 'S' : 'N';
  char lon_dir = pos_llh[1] < 0 ? 'W' : 'E';

  NMEA_SENTENCE_START(120);
  NMEA_SENTENCE_PRINTF("$GPGGA,%02d%02d%06.3f,"
                       "%02d%010.7f,%c,%03d%010.7f,%c,"
                       "%01d,%02d,%.1f,%.2f,M,,M,,",
                       t.tm_hour, t.tm_min, t.tm_sec + frac_s,
                       lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir,
                       fix_type, n_used, hdop, pos_llh[2]
                       );
  NMEA_SENTENCE_DONE();
}
コード例 #9
0
std::string calendar::print_duration( int turns )
{
    std::string res;

    if( turns < MINUTES( 1 ) ) {
        int sec = std::max( 1, turns * 6 );
        res += string_format( ngettext( "%d second", "%d seconds", sec ), sec );

    } else if( turns < HOURS( 1 ) ) {
        int min = turns / MINUTES( 1 );
        int sec = turns % MINUTES( 1 );
        res += string_format( ngettext( "%d minute", "%d minutes", min ), min );
        if( sec ) {
            res += string_format( ngettext( " and %d second", " and %d seconds", sec ), sec );
        }

    } else if( turns < DAYS( 1 ) ) {
        int hour = turns / HOURS( 1 );
        int min = turns % HOURS( 1 );
        res += string_format( ngettext( "%d hour", "%d hours", hour ), hour );
        if( min ) {
            res += string_format( ngettext( " and %d minute", " and %d minutes", min ), min );
        }

    } else {
        int day = turns / DAYS( 1 );
        int hour = turns % DAYS( 1 );
        res += string_format( ngettext( "%d day", "%d days", day ), day );
        if( hour ) {
            res += string_format( ngettext( " and %d hour", " and %d hours", hour ), hour );
        }
    }
    return res;
}
コード例 #10
0
ファイル: nmea.c プロジェクト: kovach/piksi_firmware
/** Assemble an NMEA GPGLL message and send it out NMEA USARTs.
 * NMEA GLL contains course and speed
 *
 * \param soln Pointer to gnss_solution struct
 * \param gpt_t Pointer to the current GPS Time
 */
void nmea_gpgll(const gnss_solution *soln, const gps_time_t *gps_t)
{
  /* NMEA Parameters for GPGLL
   * Ex.
   * $GPGLL,5133.81,N,00042.25,W,225444,A*75
   *   |       |    |    |     |    |   |
   * Command   |   N/S Lon    E/W   | Valid
   *          LAT                  UTC
   */ 
  time_t unix_t;
  struct tm t;

  unix_t = gps2time(*gps_t);
  gmtime_r(&unix_t, &t);

  double frac_s = fmod(gps_t->tow, 1.0);
  s16 lat_deg = R2D * (soln->pos_llh[0]);
  double lat_min = MINUTES(soln->pos_llh[0]);
  s16 lon_deg = R2D * (soln->pos_llh[1]);
  double lon_min =  MINUTES(soln->pos_llh[1]);
  lat_deg = abs(lat_deg);
  lon_deg = abs(lon_deg);

  char lat_dir = soln->pos_llh[0] < 0 ? 'S' : 'N';
  char lon_dir = soln->pos_llh[1] < 0 ? 'W' : 'E';

  NMEA_SENTENCE_START(120);
  NMEA_SENTENCE_PRINTF("$GPGLL,"
                "%02d%010.7f,%c,%03d%010.7f,%c," /* Lat/Lon */
                "%02d%02d%06.3f,A", /* Time (UTC), Valid */
                lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir,
                t.tm_hour, t.tm_min, t.tm_sec + frac_s);
  NMEA_SENTENCE_DONE();
}
コード例 #11
0
ファイル: nmea.c プロジェクト: EmuxEvans/piksi_firmware
/** Assemble an NMEA GPRMC message and send it out NMEA USARTs.
 * NMEA RMC contains minimum GPS data 
 *
 * \param soln Pointer to gnss_solution struct
 * \param gps_t Pointer to the current GPS Time
 */
void nmea_gprmc(const gnss_solution *soln, const gps_time_t *gps_t)
{
  
  /* NMEA Parameters
   * Ex.
   * $GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70
   *   |      |    |    |    |    |     |   |      |      |     |  |  |
   * Command  |    |   Lat  N/S   |     |   |      | Date Stamp | W/E |
   *    Time (UTC) |            Long   W/E  |  True Course      |   Cksum
   *            Validity (A-OK)           Speed            Variation 
   * Variation is ignored as we have no way to maintain that information
   * currently
   */
  time_t unix_t;
  struct tm t;

  unix_t = gps2time(*gps_t);
  gmtime_r(&unix_t, &t);
  double frac_s = fmod(gps_t->tow, 1.0);

  s16 lat_deg = R2D * (soln->pos_llh[0]);
  double lat_min = MINUTES(soln->pos_llh[0]);
  s16 lon_deg = R2D * (soln->pos_llh[1]);
  double lon_min = MINUTES(soln->pos_llh[1]);
  lat_deg = abs(lat_deg);
  lon_deg = abs(lon_deg);

  char lat_dir = soln->pos_llh[0] < 0 ? 'S' : 'N';
  char lon_dir = soln->pos_llh[1] < 0 ? 'W' : 'E';

  float velocity;
  float x,y,z;
  x = soln->vel_ned[0];
  y = soln->vel_ned[1];
  z = soln->vel_ned[2];
  float course = atan2(y,x);

  /* Conversion to magnitue knots */
  velocity = MS2KNOTTS(x,y,z);

  NMEA_SENTENCE_START(140);
  NMEA_SENTENCE_PRINTF(
                "$GPRMC,%02d%02d%06.3f,A," /* Command, Time (UTC), Valid */
                "%02d%010.7f,%c,%03d%010.7f,%c," /* Lat/Lon */
                "%06.2f,%05.1f," /* Speed, Course */
                "%02d%02d%02d," /* Date Stamp */
                ",", /* Variation */
                t.tm_hour, t.tm_min, t.tm_sec + frac_s,
                lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir,
                velocity, course * R2D, 
                t.tm_mday, t.tm_mon + 1, t.tm_year % 100);
  NMEA_SENTENCE_DONE();
}
コード例 #12
0
ファイル: calendar.cpp プロジェクト: CoderDuan/Cataclysm-DDA
std::string calendar::print_approx_duration( int turns, bool verbose )
{
    const auto make_result = [verbose]( int turns, const char *verbose_str, const char *short_str ) {
        return string_format( verbose ? verbose_str : short_str, print_clipped_duration( turns ).c_str() );
    };

    int divider = 0;
    int vicinity = 0;

    if( turns > DAYS( 1 ) ) {
        divider = DAYS( 1 );
        vicinity = HOURS( 2 );
    } else if( turns > HOURS( 1 ) ) {
        divider = HOURS( 1 );
        vicinity = MINUTES( 5 );
    } // Minutes and seconds can be estimated precisely.

    if( divider != 0 ) {
        const int remainder = turns % divider;

        if( remainder >= divider - vicinity ) {
            turns += divider;
        } else if( remainder > vicinity ) {
            if( remainder < divider / 2 ) {
                //~ %s - time (e.g. 2 hours).
                return make_result( turns, _( "more than %s" ), ">%s" );
            } else {
                //~ %s - time (e.g. 2 hours).
                return make_result( turns + divider, _( "less than %s" ), "<%s" );
            }
        }
    }
    //~ %s - time (e.g. 2 hours).
    return make_result( turns, _( "about %s" ), "%s" );
}
コード例 #13
0
void activity_handlers::vibe_do_turn( player_activity *act, player *p )
{
    //Using a vibrator takes time, not speed
    act->moves_left -= 100;

    item &vibrator_item = p->i_at(act->position);

    if( (p->is_wearing("rebreather")) || (p->is_wearing("rebreather_xl")) ||
        (p->is_wearing("mask_h20survivor")) ) {
        act->moves_left = 0;
        add_msg(m_bad, _("You have trouble breathing, and stop."));
    }

    //Deduct 1 battery charge for every minute using the vibrator
    if( calendar::once_every(MINUTES(1)) ) {
        vibrator_item.charges--;
        p->add_morale(MORALE_FEELING_GOOD, 4, 320); //4 points/min, one hour to fill
        // 1:1 fatigue:morale ratio, so maxing the morale is possible but will take
        // you pretty close to Dead Tired from a well-rested state.
        p->fatigue += 4;
    }
    if( vibrator_item.charges == 0 ) {
        act->moves_left = 0;
        add_msg(m_info, _("The %s runs out of batteries."), vibrator_item.tname().c_str());
    }
    if( p->fatigue >= DEAD_TIRED ) { // Dead Tired: different kind of relaxation needed
        act->moves_left = 0;
        add_msg(m_info, _("You're too tired to continue."));
    }

    // Vibrator requires that you be able to move around, stretch, etc, so doesn't play
    // well with roots.  Sorry.  :-(

    p->pause();
}
コード例 #14
0
ファイル: calendar.cpp プロジェクト: Atzerkins/Cataclysm-DDA
void calendar::sync()
{
    year = turn_number / year_turns();
    season = season_type(turn_number / DAYS(season_length()) % 4);
    day = turn_number / DAYS(1) % season_length();
    hour = turn_number / HOURS(1) % 24;
    minute = turn_number / MINUTES(1) % 60;
    second = (turn_number * 6) % 60;
}
コード例 #15
0
ファイル: calendar.cpp プロジェクト: 0x90sled/Cataclysm-DDA
void calendar::sync()
{
    const int sl = season_length();
    year = turn_number / DAYS(sl * 4);
    season = season_type(turn_number / DAYS(sl) % 4);
    day = turn_number / DAYS(1) % sl;
    hour = turn_number / HOURS(1) % 24;
    minute = turn_number / MINUTES(1) % 60;
    second = (turn_number * 6) % 60;
}
コード例 #16
0
ファイル: log.c プロジェクト: ilyak/openbsd
const char	*
timestr(int t)
{
	static char	s[80];

	if (DAY(t) > 0)
		(void)snprintf(s, sizeof s, "%dd+%02dhrs", DAY(t), HOUR(t));
	else if (HOUR(t) > 0)
		(void)snprintf(s, sizeof s, "%d:%02d:%02d",
		    HOUR(t), MINUTES(t), SEC(t));
	else if (MINUTES(t) > 0)
		(void)snprintf(s, sizeof s, "%d:%02d", MINUTES(t), SEC(t));
	else if (SEC(t) > 0)
		(void)snprintf(s, sizeof s, ":%02d", SEC(t));
	else
		*s = '\0';

	return (s);
}
コード例 #17
0
ファイル: nmea.c プロジェクト: imh/piksi_firmware
/** Assemble a NMEA GPGGA message and send it out NMEA USARTs.
 * NMEA GPGGA message contains Global Positioning System Fix Data.
 *
 * \param soln Pointer to gnss_solution struct.
 * \param dops Pointer to dops_t struct.
 */
void nmea_gpgga(const double pos_llh[3], const gps_time_t *gps_t, u8 n_used,
                u8 fix_type, double hdop)
{
  time_t unix_t;
  struct tm t;

  unix_t = gps2time(*gps_t);
  gmtime_r(&unix_t, &t);

  double frac_s = fmod(gps_t->tow, 1.0);

  s16 lat_deg = R2D * (pos_llh[0]);
  double lat_min = MINUTES(pos_llh[0]);
  s16 lon_deg = R2D * (pos_llh[1]);
  double lon_min = MINUTES(pos_llh[1]);
  lat_deg = abs(lat_deg);
  lon_deg = abs(lon_deg);

  char lat_dir = pos_llh[0] < 0 ? 'S' : 'N';
  char lon_dir = pos_llh[1] < 0 ? 'W' : 'E';

  char buf[80];
  u8 n = sprintf(buf,
                 "$GPGGA,%02d%02d%06.3f,"
                 "%02d%010.7f,%c,%03d%010.7f,%c,"
                 "%01d,%02d,%.1f,%.2f,M,,M,,",
                 t.tm_hour, t.tm_min, t.tm_sec + frac_s,
                 lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir,
                 fix_type, n_used, hdop, pos_llh[2]
                 );

  u8 sum = nmea_checksum(buf);

  sprintf(buf + n, "*%02X\r\n", sum);

  nmea_output(buf);
}
コード例 #18
0
ファイル: nmea.c プロジェクト: imh/piksi_firmware
/** Assemble an NMEA GPGLL message and send it out NMEA USARTs.
 * NMEA GLL contains course and speed
 *
 * \param soln Pointer to gnss_solution struct
 * \param gpt_t Pointer to the current GPS Time
 */
void nmea_gpgll(const gnss_solution *soln, const gps_time_t *gps_t)
{
  /* NMEA Parameters for GPGLL
   * Ex.
   * $GPGLL,5133.81,N,00042.25,W,225444,A*75
   *   |       |    |    |     |    |   |
   * Command   |   N/S Lon    E/W   | Valid
   *          LAT                  UTC
   */ 
  time_t unix_t;
  struct tm t;

  unix_t = gps2time(*gps_t);
  gmtime_r(&unix_t, &t);

  double frac_s = fmod(gps_t->tow, 1.0);
  s16 lat_deg = R2D * (soln->pos_llh[0]);
  double lat_min = MINUTES(soln->pos_llh[0]);
  s16 lon_deg = R2D * (soln->pos_llh[1]);
  double lon_min =  MINUTES(soln->pos_llh[1]);
  lat_deg = abs(lat_deg);
  lon_deg = abs(lon_deg);

  char lat_dir = soln->pos_llh[0] < 0 ? 'S' : 'N';
  char lon_dir = soln->pos_llh[1] < 0 ? 'W' : 'E';

  char buf[80];
  u8 n = sprintf(buf,
                "$GPGLL,"
                "%02d%010.7f,%c,%03d%010.7f,%c," /* Lat/Lon */
                "%02d%02d%06.3f,A", /* Time (UTC), Valid */
                lat_deg, lat_min, lat_dir, lon_deg, lon_min, lon_dir,
                t.tm_hour, t.tm_min, t.tm_sec + frac_s);
  u8 sum = nmea_checksum(buf);
  sprintf(buf + n, "*%02X\r\n", sum);
  nmea_output(buf);
}
コード例 #19
0
ファイル: calendar.cpp プロジェクト: CoderDuan/Cataclysm-DDA
std::string calendar::print_duration( int turns )
{
    int divider = 0;

    if( turns > MINUTES( 1 ) && turns < INDEFINITELY_LONG ) {
        if( turns < HOURS( 1 ) ) {
            divider = MINUTES( 1 );
        } else if( turns < DAYS( 1 ) ) {
            divider = HOURS( 1 );
        } else {
            divider = DAYS( 1 );
        }
    }

    const int remainder = divider ? turns % divider : 0;
    if( remainder != 0 ) {
        //~ %1$s - greater units of time (e.g. 3 hours), %2$s - lesser units of time (e.g. 11 minutes).
        return string_format( _( "%1$s and %2$s" ),
                              print_clipped_duration( turns ).c_str(),
                              print_clipped_duration( remainder ).c_str() );
    }

    return print_clipped_duration( turns );
}
コード例 #20
0
void 
udtourny(void)
{
    int     trem;
    char    buf[120];
    if (!status2->league)
	return;

    /* server is configured for league play */

    if (status2->league == 1)
	return;			/* we're still prepping */

    trem = --status2->leagueticksleft;


    switch (status2->league) {
    case 2:			/* the 1-minute pre tourney warm up. */
	if (trem == SECONDS(5))
	    pmessage("5 seconds to tournament start", -1, MALL, UMPIRE);
	else if (trem == SECONDS(2))
	    pmessage("Hold on to your hats.  Everybody dies!", -1, MALL, UMPIRE);
	else if (trem <= 0) {
	    starttourn();
	}
	break;

    case 3:			/* full-on T-mode */

	buf[0] = 0;
	if (trem % MINUTES(20) == 0 ||
	    (trem < MINUTES(20) && 0 == trem % MINUTES(5)) ||
	    (trem < MINUTES(5) && 0 == trem % MINUTES(1))) {
	    sprintf(buf, "There are %d minutes remaining in regulation play",
		    trem / MINUTES(1));
	}
	else if (trem < MINUTES(1) && 0 == trem % SECONDS(10)) {
	    sprintf(buf, "There are %d seconds remaining in regulation play",
		    trem / SECONDS(1));
	}
	if (buf[0])
	    pmessage(buf, -1, MALL, UMPIRE);
	if (trem <= 0)
	    /* maybe go into overtime */
	    endtourn();
	break;
    case 4:
	/* overtime, not implemented */
	break;
    }
}
コード例 #21
0
std::string construction::get_time_string() const
{
    const int turns = adjusted_time() / 100;
    std::string text;
    if( turns < MINUTES( 1 ) ) {
        const int seconds = std::max( 1, turns * 6 );
        text = string_format( ngettext( "%d second", "%d seconds", seconds ), seconds );
    } else {
        const int minutes = ( turns % HOURS( 1 ) ) / MINUTES( 1 );
        const int hours = turns / HOURS( 1 );
        if( hours == 0 ) {
            text = string_format( ngettext( "%d minute", "%d minutes", minutes ), minutes );
        } else if( minutes == 0 ) {
            text = string_format( ngettext( "%d hour", "%d hours", hours ), hours );
        } else {
            const std::string h = string_format( ngettext( "%d hour", "%d hours", hours ), hours );
            const std::string m = string_format( ngettext( "%d minute", "%d minutes", minutes ), minutes );
            //~ A time duration: first is hours, second is minutes, e.g. "4 hours" "6 minutes"
            text = string_format( _( "%1$s and %2$s" ), h.c_str(), m.c_str() );
        }
    }
    text = string_format( _( "Time to complete: %s" ), text.c_str() );
    return text;
}
コード例 #22
0
ファイル: ween-time.c プロジェクト: crpalmer/halloween
int
ween_time_is_valid(ween_time_constraint_t *c, size_t n)
{
    time_t now = time(NULL);
    struct tm tm;
    size_t i;

    if (! localtime_r(&now, &tm)) {
	return true;
    }

    for (i = 0; i < n; i++) {
	if (day_is_valid(&tm, c[i].within_days_of)) {
	    unsigned now = MINUTES(tm.tm_hour, tm.tm_min);
	    unsigned start = MINUTES(c[i].start_h, c[i].start_m);
	    unsigned end = MINUTES(c[i].end_h, c[i].end_m);
	    if (start <= now && now < end) {
		return true;
	    }
	}
    }

    return false;
}
コード例 #23
0
ファイル: calendar.cpp プロジェクト: Madnus/Cataclysm-DDA
void calendar::sync()
{
    const int sl = season_length();
    year = turn_number / DAYS(sl * 4);

    if( eternal_season ) {
        season = initial_season;
    } else {
        season = season_type(turn_number / DAYS(sl) % 4);
    }

    day = turn_number / DAYS(1) % sl;
    hour = turn_number / HOURS(1) % 24;
    minute = turn_number / MINUTES(1) % 60;
    second = (turn_number * 6) % 60;
}
コード例 #24
0
ファイル: mongroupdef.cpp プロジェクト: Justice-/MGSmod
mon_id MonsterGroupManager::GetMonsterFromGroup(std::string group, std::vector <mtype*> *mtypes, int turn)
{
    int roll = rng(1, 1000);
    MonsterGroup g = monsterGroupMap[group];
    for (FreqDef_iter it = g.monsters.begin(); it != g.monsters.end(); ++it)
    {
        if((turn == -1 || (turn + 900 >= MINUTES(STARTING_MINUTES) + (*mtypes)[it->first]->difficulty)) &&
           (!OPTIONS[OPT_CLASSIC_ZOMBIES] ||
            (*mtypes)[it->first]->in_category(MC_CLASSIC) ||
            (*mtypes)[it->first]->in_category(MC_WILDLIFE)))
        {   //Not too hard for us (or we dont care)
            if(it->second >= roll) return it->first;
            else roll -= it->second;
        }
    }
    return g.defaultMonster;
}
コード例 #25
0
ファイル: battery.c プロジェクト: epsilonrt/avrio
/* internal public functions ================================================ */
void
vBatInit (void) {

  vBatChargeInit();
  vAdcInit();

  if (xTaskProcess == 0) {
    xTaskProcess = xTaskCreate (
                        xTaskConvertMs (MINUTES(BAT_PROCESS_INTERVAL_MIN)),
                        prvvTaskProcess);
  }
  if (xTaskMonitor == 0) {
    xTaskMonitor = xTaskCreate (xTaskConvertMs (BAT_MONITOR_INTERVAL_MS),
                                prvvTaskMonitor);
  }
  prvvSetToIdle();
  vTaskStart (xTaskMonitor);
}
コード例 #26
0
ファイル: calendar.cpp プロジェクト: alapazam/Cataclysm-DDA
void calendar::sync()
{
    const int sl = to_days<int>( season_length() );
    year = turn_number / DAYS(sl * 4);

    if( eternal_season() ) {
        // If we use calendar::start to determine the initial season, and the user shortens the season length
        // mid-game, the result could be the wrong season!
        season = initial_season;
    } else {
        season = season_type(turn_number / DAYS(sl) % 4);
    }

    day = turn_number / DAYS(1) % sl;
    hour = turn_number / HOURS(1) % 24;
    minute = turn_number / MINUTES(1) % 60;
    second = (turn_number * 6) % 60;
}
コード例 #27
0
void activity_handlers::burrow_do_turn(player_activity *act, player *p)
{
    if( calendar::turn % MINUTES(1) == 0 ) { // each turn is too much
        //~ Sound of a Rat mutant burrowing!
        sounds::sound( act->placement, 10, _("ScratchCrunchScrabbleScurry.") );
        if( act->moves_left <= 91000 && act->moves_left > 89000 ) {
            p->add_msg_if_player(m_info, _("You figure it'll take about an hour and a half at this rate."));
        }
        if( act->moves_left <= 71000 && act->moves_left > 69000 ) {
            p->add_msg_if_player(m_info, _("About an hour left to go."));
        }
        if( act->moves_left <= 31000 && act->moves_left > 29000 ) {
            p->add_msg_if_player(m_info, _("Shouldn't be more than half an hour or so now!"));
        }
        if( act->moves_left <= 11000 && act->moves_left > 9000 ) {
            p->add_msg_if_player(m_info, _("Almost there! Ten more minutes of work and you'll be through."));
        }
    }
}
コード例 #28
0
ファイル: calendar.cpp プロジェクト: CoderDuan/Cataclysm-DDA
std::string calendar::print_clipped_duration( int turns )
{
    if( turns >= INDEFINITELY_LONG ) {
        return _( "forever" );
    }

    if( turns < MINUTES( 1 ) ) {
        const int sec = FULL_SECONDS_IN( turns );
        return string_format( ngettext( "%d second", "%d seconds", sec ), sec );
    } else if( turns < HOURS( 1 ) ) {
        const int min = FULL_MINUTES_IN( turns );
        return string_format( ngettext( "%d minute", "%d minutes", min ), min );
    } else if( turns < DAYS( 1 ) ) {
        const int hour = FULL_HOURS_IN( turns );
        return string_format( ngettext( "%d hour", "%d hours", hour ), hour );
    }
    const int day = FULL_DAYS_IN( turns );
    return string_format( ngettext( "%d day", "%d days", day ), day );
}
コード例 #29
0
ファイル: calendar.cpp プロジェクト: CoderDuan/Cataclysm-DDA
void calendar::sync()
{
    const int sl = season_length();
    year = turn_number / DAYS(sl * 4);

    static const std::string eternal = "ETERNAL_SEASON";
    if( get_option<bool>( eternal ) ) {
        // If we use calendar::start to determine the initial season, and the user shortens the season length
        // mid-game, the result could be the wrong season!
        season = initial_season;
    } else {
        season = season_type(turn_number / DAYS(sl) % 4);
    }

    day = turn_number / DAYS(1) % sl;
    hour = turn_number / HOURS(1) % 24;
    minute = turn_number / MINUTES(1) % 60;
    second = (turn_number * 6) % 60;
}
コード例 #30
0
void activity_handlers::game_do_turn( player_activity *act, player *p )
{
    //Gaming takes time, not speed
    act->moves_left -= 100;

    item &game_item = p->i_at(act->position);

    //Deduct 1 battery charge for every minute spent playing
    if( calendar::once_every(MINUTES(1)) ) {
        game_item.charges--;
        p->add_morale(MORALE_GAME, 1, 100); //1 points/min, almost 2 hours to fill
    }
    if( game_item.charges == 0 ) {
        act->moves_left = 0;
        add_msg(m_info, _("The %s runs out of batteries."), game_item.tname().c_str());
    }

    p->rooted();
    p->pause();
}