Пример #1
0
 // throws incompatibleUnits exceptions
 double conversion_factor(const std::string& s1, const std::string& s2, bool strict)
 {
   // assert for same units
   if (s1 == s2) return 1;
   // get unit enum from string
   UnitType u1 = string_to_unit(s1);
   UnitType u2 = string_to_unit(s2);
   // query unit group types
   UnitClass t1 = get_unit_type(u1);
   UnitClass t2 = get_unit_type(u2);
   // get absolute offset
   // used for array acces
   size_t i1 = u1 - t1;
   size_t i2 = u2 - t2;
   // error if units are not of the same group
   // don't error for multiplication and division
   if (strict && t1 != t2) throw incompatibleUnits(u1, u2);
   // only process known units
   if (u1 != UNKNOWN && u2 != UNKNOWN) {
     switch (t1) {
       case UnitClass::LENGTH:            return size_conversion_factors[i1][i2]; break;
       case UnitClass::ANGLE:             return angle_conversion_factors[i1][i2]; break;
       case UnitClass::TIME:              return time_conversion_factors[i1][i2]; break;
       case UnitClass::FREQUENCY:         return frequency_conversion_factors[i1][i2]; break;
       case UnitClass::RESOLUTION:        return resolution_conversion_factors[i1][i2]; break;
       // ToDo: should we throw error here?
       case UnitClass::INCOMMENSURABLE:   return 0; break;
     }
   }
   // fallback
   return 0;
 }
Пример #2
0
/****************************************************************
...
*****************************************************************/
void buy_callback(Widget w, XtPointer client_data, XtPointer call_data)
{
  struct city_dialog *pdialog;
  int value;
  char *name;
  char buf[512];
  
  pdialog=(struct city_dialog *)client_data;

  if(pdialog->pcity->is_building_unit) {
    name=get_unit_type(pdialog->pcity->currently_building)->name;
  }
  else {
    name=get_improvement_name(pdialog->pcity->currently_building);
  }
  value=build_cost(pdialog->pcity);
 
  if(game.player_ptr->economic.gold>=value) {
    sprintf(buf, "Buy %s for %d gold?\nTreasure %d gold.", 
	    name, value, game.player_ptr->economic.gold);
    popup_message_dialog(pdialog->shell, "buydialog", buf,
			 buy_callback_yes, pdialog,
			 buy_callback_no, 0, 0);
  }
  else {
    sprintf(buf, "%s costs %d gold.\nTreasure %d gold.", 
	    name, value, game.player_ptr->economic.gold);
    popup_message_dialog(pdialog->shell, "buynodialog", buf,
			 buy_callback_no, 0, 0);
  }
  
}
void print_device_list(){
	device *dev;
	for(dev = list_head(device_table);
		dev!= NULL;
		dev = list_item_next(dev)){
		printf("Device %d: %s\n", dev->deviceId, dev->deviceName);
		printf("Icon: %s, Type: %d\n", dev->icon, dev->type);
		printf("Unit: %s, Max: %s, Min: %s\n", get_unit_type(dev), dev->min, dev->max);
		printf("Display: %s, Sensor: %s\n", get_interface_type(dev), get_sensor_type(dev));
		printf("--------\t--------\t--------\n");
	}
	printf("End print \t ------------------------------\n");
}
Пример #4
0
void city_dialog_update_building(struct city_dialog *pdialog)
{
  char buf[512], buf2[512];
  struct city *pcity=pdialog->pcity;
  
  if(pcity->is_building_unit) {
    sprintf(buf, "%3d/%3d", pcity->shield_stock, 
	    get_unit_type(pcity->currently_building)->build_cost);
    sprintf(buf2, "%s", get_unit_type(pcity->currently_building)->name);
  }
  else {
    sprintf(buf, "%3d/%3d", pcity->shield_stock, 
	    get_improvement_type(pcity->currently_building)->build_cost);
    sprintf(buf2, "%s", 
	    get_improvement_name(pcity->currently_building));
  }
    
  XtSetSensitive(pdialog->buy_command, !pcity->did_buy);
  XtSetSensitive(pdialog->sell_command, !pcity->did_sell);

  xaw_set_label(pdialog->building_label, buf2);
  xaw_set_label(pdialog->progress_label, buf);
}
void register_device_on_server(device *newDevice){
	char jsonString[256];
	create_device_register_call(jsonString,"addDevice",
			newDevice->deviceId,
			newDevice->deviceName,
			newDevice->icon,
			get_type_in_int(newDevice),
			get_unit_type(newDevice),
			newDevice->min,
			newDevice->max,
			get_interface_type_int(newDevice),
			newDevice->logTime,
			get_sensor_type_int(newDevice));
	send_to_server(jsonString);
	printf("Complete json String: %s\n", jsonString);
}
Пример #6
0
int __cdecl
#else
int
#endif
re_name_main(int argc, char **argv)
{
   int ret = 0;
   char c;
   uchar devrec[16];
   uchar chstatus[4];
   char *s1;
   int loops = 1;
   int nsec = 10;
   char *nodefile = NULL;
   int done = 0;
   FILE *fp = NULL;
   char nod[40]; char usr[24]; char psw[24];
   char drvtyp[10];
   int n;
#ifdef GET_SENSORS
   uchar *sdrlist;
#endif

   printf("%s ver %s\n", progname,progver);

   while ((c = getopt( argc, argv,"i:l:m:f:s:t:xEF:N:P:R:T:U:V:YZ:?")) != EOF ) 
      switch(c) {
          case 'm': /* specific IPMB MC, 3-byte address, e.g. "409600" */
                    g_bus = htoi(&optarg[0]);  /*bus/channel*/
                    g_sa  = htoi(&optarg[2]);  /*device slave address*/
                    g_lun = htoi(&optarg[4]);  /*LUN*/
                    g_addrtype = ADDR_IPMB;
                    if (optarg[6] == 's') {
                             g_addrtype = ADDR_SMI;  s1 = "SMI";
                    } else { g_addrtype = ADDR_IPMB; s1 = "IPMB"; }
                    fset_mc = 1;
                    ipmi_set_mc(g_bus,g_sa,g_lun,g_addrtype);
                    printf("Use MC at %s bus=%x sa=%x lun=%x\n",
                            s1,g_bus,g_sa,g_lun);
                    break;
          case 'f': nodefile = optarg; break; /* specific sensor tag */
          case 'l': loops = atoi(optarg); break; 
          case 'i': nsec = atoi(optarg); break;  /*interval in sec*/
          case 's': sdrfile = optarg; break; 
          case 't': mytag = optarg; break; /* specific sensor tag */
          case 'x': fdebug = 1;     break;  /* debug messages */
          case 'N':    /* nodename */
          case 'U':    /* remote username */
          case 'P':    /* remote password */
          case 'R':    /* remote password */
          case 'E':    /* get password from IPMI_PASSWORD environment var */
          case 'F':    /* force driver type */
          case 'T':    /* auth type */
          case 'V':    /* priv level */
          case 'Y':    /* prompt for remote password */
          case 'Z':    /* set local MC address */
                parse_lan_options(c,optarg,fdebug);
		if (c == 'F') strncpy(drvtyp,optarg,sizeof(drvtyp));
                break;
	  default:
                printf("Usage: %s [-filmstx -NUPREFTVY]\n", progname);
                printf(" where -x       show eXtra debug messages\n");
                printf("       -f File  use list of remote nodes from File\n");
                printf("       -i 10    interval for each loop in seconds\n");
                printf("       -l 10    loops sensor readings 10 times\n");
		printf("       -m002000 specific MC (bus 00,sa 20,lun 00)\n");
                printf("       -s File  loads SDRs from File\n");
                printf("       -t tag   search for 'tag' in SDRs\n");
		print_lan_opt_usage();
                exit(1);
      }
   /* Rather than parse_lan_options above, the set_lan_options function 
    * could be used if the program already knows the nodename, etc. */

 while(!done)
 {
   if (nodefile != NULL) {
      /* This will loop for each node in the file if -f was used.
       * The file should contain one line per node: 
       *    node1 user1 password1
       *    node2 user2 password2
       */
      if (fp == NULL) {
         fp = fopen(nodefile,"r");
         if (fp == NULL) {
            printf("Cannot open file %s\n",nodefile);
            ret = ERR_FILE_OPEN;
	    goto do_exit;
         }
         if (fdebug) printf("opened file %s ok\n",nodefile);
      }
      n = fscanf(fp,"%s %s %s", nod, usr, psw);
      if (fdebug) printf("fscanf returned %d \n",n);
      if (n == EOF || n <= 0) {
        fclose(fp);
	done = 1;
	goto do_exit;
      }
      printf("Using -N %s -U %s -P %s ...\n",nod,usr,psw);
      if (n > 0) parse_lan_options('N',nod,0);
      if (n > 1) parse_lan_options('U',usr,0);
      if (n > 2) parse_lan_options('P',psw,0);
      if (drvtyp != NULL) parse_lan_options('F',drvtyp,0);
   }

   ret = ipmi_getdeviceid(devrec,16,fdebug);
   if (ret != 0) {
	printf("Cannot do ipmi_getdeviceid, ret = %d\n",ret);
	goto do_exit;
   } else {  /*success*/
       uchar ipmi_maj, ipmi_min;
       ipmi_maj = devrec[4] & 0x0f;
       ipmi_min = devrec[4] >> 4;
       show_devid( devrec[2],  devrec[3], ipmi_maj, ipmi_min);
   }

   ret = get_chassis_status(chstatus,4);
   if (ret == 0) {
        if (chstatus[0] & 0x01) s1 = "on";
        else s1 = "off";
	printf("Chassis Status = %02x (%s)\n",chstatus[0],s1);
   }

#ifdef GET_FRU
   {
      uchar  *fru_data = NULL;
      printf("Getting FRU ...\n");
      ret = load_fru(0x20,0,0x07, &fru_data);
      if (ret == 0) 
	 ret = show_fru(0x20,0,0x07,fru_data);
      if (fru_data != NULL)
         free_fru(fru_data);
   }
#endif
#ifdef GET_SENSORS
   printf("Getting SDRs ...\n");
   if (sdrfile != NULL) {
      ret = get_sdr_file(sdrfile,&sdrlist);
   } else {
      ret = get_sdr_cache(&sdrlist);
   }
   printf("get_sdr_cache ret = %d\n",ret);
   if (ret == 0) {
	uchar sdrbuf[SDR_SZ];
	uchar reading[4];
	uchar snum = 0;
	ushort id;
	double val;
	char *typestr;
	char tag[17];
	int j;

	for (j = 0; j < loops; j++) 
	{
	 if (j > 0) {
	    printf("loop %d: wait %d seconds ...\n",j,nsec);
	    os_usleep(nsec,0);  /*sleep 5 sec between loops*/
	 }
	 id = 0;
	 /* Get sensor readings for all full SDRs */
         while(find_sdr_next(sdrbuf,sdrlist,id) == 0) {
           id = sdrbuf[0] + (sdrbuf[1] << 8); /*this SDR id*/
	   if (sdrbuf[3] != 0x01) continue; /*full SDR*/
	   strncpy(tag,&sdrbuf[48],16);
	   tag[16] = 0;
	   snum = sdrbuf[7];
           ret = GetSensorReading(snum, sdrbuf, reading);
	   if (ret == 0) { 
	      val = RawToFloat(reading[0], sdrbuf);
              typestr = get_unit_type( sdrbuf[20], sdrbuf[21], sdrbuf[22],0);
	   } else {
	      val = 0;
	      typestr = "na";
	      printf("%04x: get sensor %x reading ret = %d\n",id,snum,ret);
	   }
           printf("%04x: sensor %x %s  \treading = %.2f %s\n",
			id,snum,tag,val,typestr);
	   memset(sdrbuf,0,SDR_SZ);
         } /*end while*/
        } /*end for(loops) */

	/* Find a specific sensor by its tag and get a reading */
	if (mytag != NULL) {
	   /* see option -t, mytag = "System";  or "System Temp" */
	   memset(sdrbuf,0,SDR_SZ);
           ret = find_sdr_by_tag(sdrbuf, sdrlist, mytag, fdebug);
           printf("find_sdr_by_tag(%s) ret = %d\n",mytag,ret);
	   strncpy(tag,&sdrbuf[48],16); /*assume full sdr tag offset*/
	   tag[16] = 0;
	   snum = sdrbuf[7];
           ret = GetSensorReading(snum, sdrbuf, reading);
           printf("get sensor %x reading ret = %d\n",snum,ret);
	   if (sdrbuf[3] == 0x01) { /*full SDR*/
	      if (ret == 0) { 
	         val = RawToFloat(reading[0], sdrbuf);
                 typestr = get_unit_type(sdrbuf[20],sdrbuf[21],sdrbuf[22],0);
	      } else {
	         val = 0;
	         typestr = "na";
	      }
              printf("sensor %x %s reading = %.2f %s\n",snum,tag,val,typestr);
	   } else printf("sensor %x type %x reading = %02x\n",
			snum,sdrbuf[3],reading[2]);
	}

	free_sdr_cache(sdrlist);
   } /*endif sdr_cache is valid*/
#endif
   ipmi_close_();
   if (nodefile == NULL) done = 1;
  } /*end while not done */

do_exit:
   show_outcome(progname,ret);
   exit (ret);
}  /* end main()*/
Пример #7
0
/****************************************************************
...
*****************************************************************/
void change_callback(Widget w, XtPointer client_data, XtPointer call_data)
{
  Widget cshell, cform, clabel, cview, button_change, button_cancel;
  Position x, y;
  Dimension width, height;
  struct city_dialog *pdialog;
  int i, n;
  
  pdialog=(struct city_dialog *)client_data;
  
  cshell=XtCreatePopupShell("changedialog", transientShellWidgetClass,
			    pdialog->shell, NULL, 0);
  
  cform=XtVaCreateManagedWidget("dform", formWidgetClass, cshell, NULL);
  
  clabel=XtVaCreateManagedWidget("dlabel", labelWidgetClass, cform, 
				 NULL);   

  cview=XtVaCreateManagedWidget("dview", viewportWidgetClass,
				cform,
				XtNfromVert, 
				clabel,
				NULL);

  pdialog->change_list=XtVaCreateManagedWidget("dlist", listWidgetClass, 
					       cview, 
					       XtNforceColumns, 1,
					       XtNdefaultColumns,1, 
					       XtNlist, 
					       (XtArgVal)dummy_change_list,
					       XtNverticalList, False,
					       NULL);

  
  button_change=XtVaCreateManagedWidget("buttonchange",
					commandWidgetClass,
					cform,
					XtNfromVert, 
					cview,
					NULL);

  button_cancel=XtVaCreateManagedWidget("buttoncancel",
				    commandWidgetClass,
				    cform,
				    XtNfromVert, 
				    cview,
				    XtNfromHoriz,
				    button_change,
				    NULL);

  

  XtAddCallback(button_change, XtNcallback, 
		change_to_callback, (XtPointer)pdialog);
  XtAddCallback(button_cancel, XtNcallback, 
		change_no_callback, (XtPointer)pdialog);
  

  XtVaGetValues(pdialog->shell, XtNwidth, &width, XtNheight, &height, NULL);
  XtTranslateCoords(pdialog->shell, (Position) width/3, (Position) height/3,
		    &x, &y);
  XtVaSetValues(cshell, XtNx, x, XtNy, y, NULL);
  
  XtPopup(cshell, XtGrabNone);
  
  XtSetSensitive(pdialog->shell, FALSE);

  for(i=0, n=0; i<B_LAST; i++)
    if(can_build_improvement(pdialog->pcity, i)) {
      sprintf(pdialog->change_list_names[n], "%s (%d)", get_improvement_name(i),get_improvement_type(i)->build_cost);
      
      pdialog->change_list_names_ptrs[n]=pdialog->change_list_names[n];
      pdialog->change_list_ids[n++]=i;
    }
  
  pdialog->change_list_no_improvements=n;


  for(i=0; i<U_LAST; i++)
    if(can_build_unit(pdialog->pcity, i)) {
      sprintf(pdialog->change_list_names[n],"%s (%d)", get_unit_type(i)->name, get_unit_type(i)->build_cost);
      pdialog->change_list_names_ptrs[n]=pdialog->change_list_names[n];
      pdialog->change_list_ids[n++]=i;
    }
  
  pdialog->change_list_names_ptrs[n]=0;

  XawListChange(pdialog->change_list, pdialog->change_list_names_ptrs, 
		0, 0, False);
  /* force refresh of viewport so the scrollbar is added.
   * Buggy sun athena requires this */
  XtVaSetValues(cview, XtNforceBars, True, NULL);
}
Пример #8
0
void MatchScene::do_handle_command_result(const CommandResult& cr, bool is_enemy_notification)
{

  CommandResult::ResultInformation inf = cr.result_information;
  auto p = cr.result_point;
  switch ( inf )
  {
  case CommandResult::ResultInformation::COLLISION:
    for ( auto p : cr.result_collidables )
    {
      ICollidable::ICollidableType c_type = ICollidable::extract_type(p.second);
      if ( c_type == ICollidable::MINE )
      {
        auto unit = gs->get_unit_by_id(cr.id);
        //Mine Layers cannot explode a mine
        if ( unit->get_unit_type() == Unit::UnitClass::BOAT &&  dynamic_cast<Boat &>( *unit ).get_boat_type() == Boat::MINE_LAYER )
        {
          Stage::get_instance()->notify("Collided with Mine!", 4000);
        }
        else
        {
          Stage::get_instance()->notify("Mine Exploded!", 4000);
        }
      }
      else if ( c_type == ICollidable::BASE )
      {
        Stage::get_instance()->notify("Collision with Base!", 4000);
      }
      else if ( c_type == ICollidable::BOAT )
      {
        Stage::get_instance()->notify("Collision with Boat!", 4000);
      }
      else if ( c_type == ICollidable::REEF )
      {
        Stage::get_instance()->notify("Collision with Reef!", 4000);
      }
    }
    break;
  case CommandResult::ResultInformation::HIT:
    if ( cr.action == Action::Action_enum::FIRE_CANNON )
    {
      Stage::get_instance()->notify("Cannon Shell Exploded!", 4000);
    }
    else if ( cr.action == Action::Action_enum::FIRE_TORPEDO )
    {
      Stage::get_instance()->notify("Torpedo Exploded!", 4000);
    }
    for ( auto p : cr.result_collidables )
    {
      ICollidable::ICollidableType c_type = ICollidable::extract_type(p.second);
      if ( c_type == ICollidable::MINE )
      {
        Stage::get_instance()->notify("Mine Exploded!", 4000);
      }
      else if ( c_type == ICollidable::BASE )
      {
        if ( dynamic_cast<Base &>( *p.second ).is_sunk() )
        {
          Stage::get_instance()->notify("Base Destroyed!", 4000);
        }
        else
        {
          Stage::get_instance()->notify("Hit Base!", 4000);
        }
      }
      else if ( c_type == ICollidable::BOAT )
      {
        if ( dynamic_cast<Boat &>( *p.second ).is_sunk() )
        {
          std::string boat_type = Boat::convert_boat_type_to_string(dynamic_cast<Boat &>( *p.second ).get_boat_type());
          Stage::get_instance()->notify(boat_type + " Sunk!", 4000);
          Player::Side winning_side;
          if (gs->is_won(winning_side))
          {
            if (!is_local_play)
            {
              if (!is_enemy_notification)
              {
                //BattleshipsRCP rcp(message_sender);
                //rcp.won_game();
              }
            }
            else
            {
              // End play locally.
            }
          }
        }
        else
        {
          Stage::get_instance()->notify("Hit Boat!", 4000);
        }
      }
      else if ( c_type == ICollidable::REEF )
      {
        Stage::get_instance()->notify("Hit Reef!", 4000);
      }
    }
    break;
  case CommandResult::ResultInformation::MISS:
    if ( cr.action == Action::Action_enum::FIRE_CANNON )
    {
      Stage::get_instance()->notify("Miss! Shot fell in water.", 4000);
    }
    else if ( cr.action == Action::Action_enum::FIRE_TORPEDO && !is_enemy_notification )
    {
      Stage::get_instance()->notify("Miss! Torpedo did not hit anything.", 4000);
    }
    break;
  case CommandResult::ResultInformation::NO_INFORMATION:
    break;
  }
  for ( auto p : cr.result_collidables )
  {
    Stage::get_instance()->ping(p.first, 3000);
  }
}