/*
 * The function 'adjust_position()' adjusts the position depending on the
 * acceleration and velocity.
 */
 INT16U adjust_position(INT16U position, INT16S velocity,
                        INT8S acceleration, INT16U time_interval)
{
  INT16S new_position = position + velocity * time_interval / 1000
    + acceleration / 2  * (time_interval / 1000) * (time_interval / 1000);

  if (new_position > 24000) {
    new_position -= 24000;
  } else if (new_position < 0){
    new_position += 24000;
  }
  
  show_position(new_position);
  return new_position;
}
Example #2
0
static int
get_position(NCURSES_CONST char *text,
	     NCURSES_CONST char *also,
	     int which,
	     int *xpos,
	     int *ypos)
{
    int result = 0;
    int x1, y1;
    char cmd;

    getyx(stdscr, y1, x1);
    (void) statusline();

    show_position(text, also, which, y1, x1);

    if (log_in != 0) {
	if (fscanf(log_in, "%c%d,%d\n", &cmd, &y1, &x1) == 3) {
	    switch (cmd) {
	    case LAST_POS:
		result = 1;
		(void) wgetch(stdscr);
		break;
	    case TEMP_POS:
		result = 0;
		wrefresh(stdscr);
		napms(100);
		break;
	    default:
		result = -1;
		break;
	    }
	} else {
	    result = -1;
	}
    } else {

	switch (wgetch(stdscr)) {
	case QUIT:
	case ESCAPE:
	case ERR:
	    result = -1;
	    break;
	case ' ':
	    result = 1;
	    break;
	case KEY_UP:
	    if (y1 > 0) {
		--y1;
	    } else {
		beep();
	    }
	    break;
	case KEY_DOWN:
	    if (y1 < getmaxy(stdscr)) {
		++y1;
	    } else {
		beep();
	    }
	    break;
	case KEY_LEFT:
	    if (x1 > 0) {
		--x1;
	    } else {
		beep();
	    }
	    break;
	case KEY_RIGHT:
	    if (x1 < getmaxx(stdscr)) {
		++x1;
	    } else {
		beep();
	    }
	    break;
	}
    }

    wmove(stdscr, y1, x1);
    *ypos = y1;
    *xpos = x1;

    if (result >= 0) {
	if (log_out)
	    fprintf(log_out, "%c%d,%d\n",
		    ((result > 0)
		     ? LAST_POS
		     : TEMP_POS),
		    y1, x1);
    }
    return result;
}
/*
 * The task 'VehicleTask' updates the current velocity of the vehicle
 */
void VehicleTask(void* pdata)
{ 
  INT8U err, err_tmr_1, err_tmr_start, err_sem;  
  void* msg;
  INT8U* throttle; 
  INT8S acceleration;  /* Value between 40 and -20 (4.0 m/s^2 and -2.0 m/s^2) */
  INT8S retardation;   /* Value between 20 and -10 (2.0 m/s^2 and -1.0 m/s^2) */
  INT16U position = 0; /* Value between 0 and 20000 (0.0 m and 2000.0 m)  */
  INT16S wind_factor;   /* Value between -10 and 20 (2.0 m/s^2 and -1.0 m/s^2) */

  Sem_VehicleTask = OSSemCreate(0);
  //OSSemPend(Sem_VehicleTask,0,&err_sem);

  printf("Vehicle task created!\n");
   
  
    SWTimer_VehicleTask = OSTmrCreate(0, VEHICLE_PERIOD, OS_TMR_OPT_PERIODIC, Tmr_Callback_Vehicle_Task, (void *)0,"S/W Timer 2",&err_tmr_1);
    if(err_tmr_1 == OS_ERR_NONE){
        if(DEBUG)
        printf("Timer for VECHICLE TASK is created\n"); 
        
        OSTmrStart(SWTimer_VehicleTask, &err_tmr_start);
        
        if(err_tmr_start == OS_ERR_NONE){
            if(DEBUG)
            printf("Timer started in VEHICLE TASK \n");
        }
        else {
            printf("Problem starting timer in VEHICLE TASK \n");
        }       
      }
      else {
      printf("Error while creating Vehicle task timer \n");     
     
      if(err_tmr_1 == OS_ERR_TMR_INVALID_DLY)
      printf(" Delay INVALID : VEHICLE TASK\n");
      
      }

  while(1)
    {
        // Wait for user inputs
        OSSemPend(Sem_SwitchIO_IP , 0, &err_sem);
        OSSemPend(Sem_ButtonIO_IP, 0, &err_sem);
        
        if((brake_pedal == on) && (CUR_VELOCITY > 0)){
            CUR_VELOCITY = CUR_VELOCITY - 10;
            
           // if(CUR_VELOCITY < -200)         // Max value for velocity
            //CUR_VELOCITY = -200; 
            
            if(DEBUG_IO)
            printf("********** Brake brake_pedal : %d ********** \n", CUR_VELOCITY);
        }
        
      err = OSMboxPost(Mbox_Velocity, (void *) &CUR_VELOCITY);
      
      if(DEBUG)
      printf("Vehicle task Posted MBoxPost_Velocity \n");

        if(DEBUG)
        printf("SEM ACCESS VEHICLE TASK\n\n");
        
        OSSemPend(Sem_VehicleTask,0,&err_sem);
        
      /* Non-blocking read of mailbox: 
       - message in mailbox: update throttle
       - no message:         use old throttle
      */
      if(DEBUG)
      printf("Vehicle task waiting for MBoxPost_Throttle for 1 unit time \n");
      
      msg = OSMboxPend(Mbox_Throttle, 1, &err); 
      if (err == OS_NO_ERR) 
         throttle = (INT8U*) msg;

      if(DEBUG)
      printf("Vehicle task GOT MBoxPost_Throttle \n");
      
      /* Retardation : Factor of Terrain and Wind Resistance */
      if (CUR_VELOCITY > 0)
         wind_factor = CUR_VELOCITY * CUR_VELOCITY / 10000 + 1;
      else 
         wind_factor = (-1) * CUR_VELOCITY * CUR_VELOCITY / 10000 + 1;
         
      if (position < 4000) 
         retardation = wind_factor; // even ground
      else if (position < 8000)
          retardation = wind_factor + 15; // traveling uphill
        else if (position < 12000)
            retardation = wind_factor + 25; // traveling steep uphill
          else if (position < 16000)
              retardation = wind_factor; // even ground
            else if (position < 20000)
                retardation = wind_factor - 10; //traveling downhill
              else
                  retardation = wind_factor - 5 ; // traveling steep downhill
                  
      acceleration = *throttle / 2 - retardation;     
      position = adjust_position(position, CUR_VELOCITY, acceleration, 300); 
      CUR_VELOCITY = adjust_velocity(CUR_VELOCITY, acceleration, brake_pedal, 300); 
      printf("Position: %dm\n", position / 10);
      printf("Velocity: %4.1fm/s\n", CUR_VELOCITY /10.0);
      printf("Throttle: %dV Time : %d \n\n", *throttle / 10, (int) (alt_timestamp() / (alt_timestamp_freq()/1000)));
      alt_timestamp_start();
     /* 
      INT32U stk_size;
  err = OSTaskStkChk(16, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used OverLoadDetection : %d \n", stk_size);
      
      err = OSTaskStkChk(14, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used DYNAMIV_UTI : %d \n", stk_size);
      
      err = OSTaskStkChk(12, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used CONTROLTASK: %d \n", stk_size);
      
      err = OSTaskStkChk(10, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used VehicleTask: %d \n", stk_size);
      
      err = OSTaskStkChk(8, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used SwitchIO: %d \n", stk_size);
      
      err = OSTaskStkChk(7, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used ButtonIO: %d \n", stk_size);
      
      err = OSTaskStkChk(6, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used WatchDog: %d \n", stk_size);
      
      err = OSTaskStkChk(5, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used Start Task: %d \n", stk_size);
*/
      show_velocity_on_sevenseg((INT8S) (CUR_VELOCITY / 10));
      show_active_signals();
      show_position(position);
      
     // OSSemPend(Sem_VehicleTask,0,&err_sem);
    }
} 
Example #4
0
File: talk.c Project: icewwn/fbbs-1
int tui_query_result(const char *userid)
{
	struct userec user;
	int unum = getuserec(userid, &user);
	if (!unum)
		return -1;

	screen_move(0, 0);
	screen_clrtobot();

	int color = 2;
	if (HAS_DEFINE(user.userdefine, DEF_COLOREDSEX))
		color = (user.gender == 'F') ? 5 : 6;
	char horo[32] = "";
	if (HAS_DEFINE(user.userdefine, DEF_S_HOROSCOPE)
			&& strcasecmp(user.userid, "guest") != 0) {
		snprintf(horo, sizeof(horo), "[\033[1;3%dm%s\033[m] ",
				color, horoscope(user.birthmonth, user.birthday));
	}
	//% prints("\033[0;1;37m%s \033[m(\033[1;33m%s\033[m) 共上站 \033[1;32m%d\033[m "
	prints("\033[0;1;37m%s \033[m(\033[1;33m%s\033[m) \xb9\xb2\xc9\xcf\xd5\xbe \033[1;32m%d\033[m "
			//% "次  %s\n", user.userid, user.username, user.numlogins, horo);
			"\xb4\xce  %s\n", user.userid, user.username, user.numlogins, horo);

	bool self = !strcmp(currentuser.userid, user.userid);
	const char *host;
	if (user.lasthost[0] == '\0') {
		//% host = "(不详)";
		host = "(\xb2\xbb\xcf\xea)";
	} else {
		if (self || HAS_PERM2(PERM_OCHAT, &currentuser))
			host = user.lasthost;
		else 
			host = mask_host(user.lasthost);
	}
	//% prints("进站 [\033[1;32m%s\033[m] %s[\033[1;32m%s\033[m]\n",
	prints("\xbd\xf8\xd5\xbe [\033[1;32m%s\033[m] %s[\033[1;32m%s\033[m]\n",
			format_time(user.lastlogin, TIME_FORMAT_ZH),
			//% strlen(host) > IPADDR_OMIT_THRES ? "" : "来自 ", host);
			strlen(host) > IPADDR_OMIT_THRES ? "" : "\xc0\xb4\xd7\xd4 ", host);

	user_id_t uid = get_user_id(userid);
	session_basic_info_t *res = get_sessions(uid);

	bool any_session_visible = false;
	for (int i = 0; i < (res ? session_basic_info_count(res) : 0); ++i) {
		if (HAS_PERM(PERM_SEECLOAK) || session_basic_info_visible(res, i)) {
			any_session_visible = true;
			break;
		}
	}

	if (any_session_visible) {
		//% prints("在线 [\033[1;32m讯息器:(\033[36m%s\033[32m)\033[m] ",
		prints("\xd4\xda\xcf\xdf [\033[1;32m\xd1\xb6\xcf\xa2\xc6\xf7:(\033[36m%s\033[32m)\033[m] ",
				//% "打开");
				"\xb4\xf2\xbf\xaa");
	} else {
		fb_time_t t = user.lastlogout;
		if (user.lastlogout < user.lastlogin)
			t = ((fb_time() - user.lastlogin) / 120) % 47 + 1 + user.lastlogin;
		//% prints("离站 [\033[1;32m%s\033[m] ", format_time(t, TIME_FORMAT_ZH));
		prints("\xc0\xeb\xd5\xbe [\033[1;32m%s\033[m] ", format_time(t, TIME_FORMAT_ZH));
	}

	char path[HOMELEN];
	snprintf(path, sizeof(path), "mail/%c/%s/%s",
			toupper(user.userid[0]), user.userid, DOT_DIR);
	int perf = countperf(&user);
	//% prints("表现值 "
	prints("\xb1\xed\xcf\xd6\xd6\xb5 "
#ifdef SHOW_PERF
			"%d(\033[1;33m%s\033[m)"
#else
			"[\033[1;33m%s\033[m]"
#endif
			//% " 信箱 [\033[1;5;32m%2s\033[m]\n"
			" \xd0\xc5\xcf\xe4 [\033[1;5;32m%2s\033[m]\n"
#ifdef SHOW_PERF
			, perf
#endif
			//% , cperf(perf), (check_query_mail(path) == 1) ? "信" : "  ");
			, cperf(perf), (check_query_mail(path) == 1) ? "\xd0\xc5" : "  ");

	int exp = countexp(&user);

	uinfo_t u;
	uinfo_load(user.userid, &u);

#ifdef ENABLE_BANK
	//% prints("贡献 [\033[1;32m%d\033[m", TO_YUAN_INT(u.contrib));
	prints("\xb9\xb1\xcf\xd7 [\033[1;32m%d\033[m", TO_YUAN_INT(u.contrib));
	if (self || HAS_PERM2(PERM_OCHAT, &currentuser)) {
		prints("/\033[1;33m%d\033[m", TO_YUAN_INT(u.money));
	}
	{
		char rank_buf[8];
		snprintf(rank_buf, sizeof(rank_buf), "%.1f%%", PERCENT_RANK(u.rank));
		prints("](%s) ", rank_buf);
	}

#endif

#ifdef ALLOWGAME
	//% prints("存贷款 [\033[1;32m%d\033[m/\033[1;32m%d\033[m]"
	prints("\xb4\xe6\xb4\xfb\xbf\xee [\033[1;32m%d\033[m/\033[1;32m%d\033[m]"
			//% "(\033[1;33m%s\033[m) 经验值 [\033[1;32m%d\033[m]\n",
			"(\033[1;33m%s\033[m) \xbe\xad\xd1\xe9\xd6\xb5 [\033[1;32m%d\033[m]\n",
			user.money, user.bet, cmoney(user.money - user.bet), exp);
	//% prints("发文 [\033[1;32m%d\033[m] 奖章 [\033[1;32m%d\033[m]"
	prints("\xb7\xa2\xce\xc4 [\033[1;32m%d\033[m] \xbd\xb1\xd5\xc2 [\033[1;32m%d\033[m]"
			//% "(\033[1;33m%s\033[m) 生命力 [\033[1;32m%d\033[m]\n",
			"(\033[1;33m%s\033[m) \xc9\xfa\xc3\xfc\xc1\xa6 [\033[1;32m%d\033[m]\n",
			user.numposts, user.nummedals, cnummedals(user.nummedals),
			compute_user_value(&user));
#else
	//% prints("发文 [\033[1;32m%d\033[m] ", user.numposts);
	prints("\xb7\xa2\xce\xc4 [\033[1;32m%d\033[m] ", user.numposts);
	//% prints("经验值 [\033[1;33m%-10s\033[m]", cexpstr(exp));
	prints("\xbe\xad\xd1\xe9\xd6\xb5 [\033[1;33m%-10s\033[m]", cexpstr(exp));
#ifdef SHOWEXP
	prints("(%d)", exp);
#endif
	//% prints(" 生命力 [\033[1;32m%d\033[m]\n", compute_user_value(&user));
	prints(" \xc9\xfa\xc3\xfc\xc1\xa6 [\033[1;32m%d\033[m]\n", compute_user_value(&user));
#endif

	char buf[160];
	show_position(&user, buf, sizeof(buf), u.title);
	//% prints("身份 %s\n", buf);
	prints("\xc9\xed\xb7\xdd %s\n", buf);
	
	uinfo_free(&u);

	if (any_session_visible)
		show_statuses(res);
	session_basic_info_clear(res);

	show_user_plan(userid);
	return 0;
}