コード例 #1
0
void CmpProjectileWeaponUsable::use()
{
	if(m_timeTillCanFire == 0)
	{
		// Determine the character which is firing the projectile (the owner of the weapon).
		ICmpOwnable_CPtr cmpOwnable = m_objectManager->get_component(m_objectID, cmpOwnable);
		ObjectID firer = cmpOwnable->owner();
		if(!firer.valid()) throw Exception("Can't use a projectile weapon when it's not owned");

		// Check that there's enough ammo.
		ICmpInventory_Ptr cmpFirerInventory = m_objectManager->get_component(firer, cmpFirerInventory);
		if(!cmpFirerInventory) throw Exception("The firer must have an inventory component");
		if(cmpFirerInventory->consumables_count(m_ammoType) > 0)
		{
			// Fire a bullet from each hotspot of the weapon (note that this in principle makes it easy to implement things like double-barrelled shotguns).
			const std::vector<std::string>& spots = hotspots();
			for(size_t i=0, size=spots.size(); i<size; ++i)
			{
				boost::optional<Vector3d> pos = hotspot_position(spots[i]);
				boost::optional<Vector3d> ori = hotspot_orientation(spots[i]);
				if(pos && ori)
				{
					ObjectSpecification specification = m_objectManager->get_archetype(m_ammoType);
					specification.set_component_property("Projectile", "Firer", firer);
					specification.set_component_property("Simulation", "Position", *pos);
					specification.set_component_property("Simulation", "Velocity", m_muzzleSpeed * *ori);
					m_objectManager->queue_for_construction(specification);
				}
			}

			cmpFirerInventory->destroy_consumables(m_ammoType, 1);
			m_timeTillCanFire = m_firingInterval;
		}
	}
}
コード例 #2
0
ファイル: CmpScriptedUsable.cpp プロジェクト: galek/hesperus
//#################### PUBLIC METHODS ####################
Properties CmpScriptedUsable::save() const
{
	Properties properties;
	properties.set("Group", usable_group());
	properties.set("Hotspots", hotspots());
	properties.set("Script", m_scriptName);
	return properties;
}
コード例 #3
0
Properties CmpProjectileWeaponUsable::save() const
{
	Properties properties;
	properties.set("AmmoType", m_ammoType);
	properties.set("FiringInterval", m_firingInterval);
	properties.set("Group", usable_group());
	properties.set("Hotspots", hotspots());
	properties.set("MuzzleSpeed", m_muzzleSpeed);
	properties.set("TimeTillCanFire", m_timeTillCanFire);
	return properties;
}
コード例 #4
0
void MyWidget::play(){
	
	//check if we are playing. This may mean we must pause
	if (playing)
	{
		playing = false;
		b_play->setText("Play");
		return;
	}
    //never play an empty file
	if (list->size() == 0)
	{
		return;
	}
	
	QPainter p1;
	QImage pic;
	
	
	int count = frameIndex-1;
	
	status->setText("Calculating");
	
	//find everything there is to know about the person in the video	
	hotspots();
	
	status->setText("Playing");
	
	//initial start time
	double cur = clock();
	
	
	playing = true;
	b_play->setText("Pause");
	//move through all the frames
	while (frameIndex < list->size() && playing)
	{
	
		count++;
		//load a picture
		loadPic(pic,frameIndex);
		//do all tracking
		tracker->trackFrame(pic,frameIndex,edge_t,skin_t,l_algo->currentText());
		//to make sure the frame rate is constant
		while ( (clock() - cur)/CLOCKS_PER_SEC*100 < fps){}
		//draw the frame
		p1.begin(this);
			p1.drawPixmap(0,0,pic);
		p1.end();	
		//get the time now
		cur = clock();
		
		//next frame
		frameIndex++;
		
		s_frame->setValue(count);
		
		qApp->processEvents();
	}
	//check how we stopped playing
	if (playing)
	{
		b_play->setText("Play");
		frameIndex = 1;
		status->setText("Stopped");
	}
	else
	{
		status->setText("Paused");
	}
	playing = false;
}
コード例 #5
0
ファイル: traffic.cpp プロジェクト: pranamibhatt/booksim
TrafficPattern * TrafficPattern::New(string const & pattern, int nodes)
{
  string pattern_name;
  string param_str;
  size_t left = pattern.find_first_of('(');
  if(left == string::npos) {
    pattern_name = pattern;
  } else {
    pattern_name = pattern.substr(0, left);
    size_t right = pattern.find_last_of(')');
    if(right == string::npos) {
      param_str = pattern.substr(left+1);
    } else {
      param_str = pattern.substr(left+1, right-left-1);
    }
  }
  vector<string> params = tokenize(param_str);
  
  TrafficPattern * result = NULL;
  if(pattern_name == "bitcomp") {
    result = new BitCompTrafficPattern(nodes);
  } else if(pattern_name == "transpose") {
    result = new TransposeTrafficPattern(nodes);
  } else if(pattern_name == "bitrev") {
    result = new BitRevTrafficPattern(nodes);
  } else if(pattern_name == "shuffle") {
    result = new ShuffleTrafficPattern(nodes);
  } else if(pattern_name == "randperm") {
    int perm_seed = params.empty() ? 0 : atoi(params[0].c_str());
    result = new RandomPermutationTrafficPattern(nodes, perm_seed);
  } else if(pattern_name == "uniform") {
    result = new UniformRandomTrafficPattern(nodes);
  } else if(pattern_name == "background") {
    vector<string> excludes_str = tokenize(params[0]);
    vector<int> excludes(excludes_str.size());
    for(size_t i = 0; i < excludes.size(); ++i) {
      excludes[i] = atoi(excludes_str[i].c_str());
    }
    result = new UniformBackgroundTrafficPattern(nodes, excludes);
  } else if(pattern_name == "diagonal") {
    result = new DiagonalTrafficPattern(nodes);
  } else if(pattern_name == "asymmetric") {
    result = new AsymmetricTrafficPattern(nodes);
  } else if(pattern_name == "taper64") {
    result = new Taper64TrafficPattern(nodes);
  } else if(pattern_name == "bad_dragon") {
    if(params.size() < 2) {
      cout << "Error: Missing parameters for dragonfly bad permutation traffic pattern: " << pattern << endl;
      exit(-1);
    }
    int k = atoi(params[0].c_str());
    int n = atoi(params[1].c_str());
    result = new BadPermDFlyTrafficPattern(nodes, k, n);
  } else if((pattern_name == "tornado") || (pattern_name == "neighbor") ||
	    (pattern_name == "badperm_yarc")) {
    if(params.size() < 3) {
      cout << "Error: Missing parameters for digit permutation traffic pattern: " << pattern << endl;
      exit(-1);
    }
    int k = atoi(params[0].c_str());
    int n = atoi(params[1].c_str());
    int xr = atoi(params[2].c_str());
    if(pattern_name == "tornado") {
      result = new TornadoTrafficPattern(nodes, k, n, xr);
    } else if(pattern_name == "neighbor") {
      result = new NeighborTrafficPattern(nodes, k, n, xr);
    } else if(pattern_name == "badperm_yarc") {
      result = new BadPermYarcTrafficPattern(nodes, k, n, xr);
    }
  } else if(pattern_name == "hotspot") {
    if(params.empty()) {
      cout << "Error: Missing parameter for hotspot traffic pattern: " << pattern << endl;
      exit(-1);
    } 
    vector<string> hotspots_str = tokenize(params[0]);
    vector<int> hotspots(hotspots_str.size());
    for(size_t i = 0; i < hotspots.size(); ++i) {
      hotspots[i] = atoi(hotspots_str[i].c_str());
    }
    vector<int> rates(hotspots.size(), 1);
    if(params.size() >= 2) {
      vector<string> rates_str = tokenize(params[1]);
      rates_str.resize(hotspots.size(), rates_str.back());
      for(size_t i = 0; i < rates.size(); ++i) {
	rates[i] = atoi(rates_str[i].c_str());
      }
    }
    result = new HotSpotTrafficPattern(nodes, hotspots, rates);
  } else {
    cout << "Error: Unknown traffic pattern: " << pattern << endl;
    exit(-1);
  }
  return result;
}