Exemple #1
0
uint Aligner::checkBeginGreedy(const string& read, pair<kmer, uint>& overlap, vector<uNumber>& path, uint errors){
	if(overlap.second==0){path.push_back(0);return 0;}
	string readLeft(read.substr(0,overlap.second)),unitig;
	auto rangeUnitigs(getEnd(overlap.first));
	uint minMiss(errors+1),indiceMinMiss(0);
	bool ended(false);
	int offset(0);
	kmer nextOverlap(0);

	for(uint i(0); i<rangeUnitigs.size(); ++i){
		unitig=(rangeUnitigs[i].first);
		if(unitig.size()-k+1>=readLeft.size()){
			uint miss(missmatchNumber(unitig.substr(unitig.size()-readLeft.size()-k+1,readLeft.size()),readLeft, errors));
			// if(miss==0){
			// 	path.push_back(unitig.size()-readLeft.size()-k+1);
			// 	path.push_back(rangeUnitigs[i].second);
			// 	return 0;
			// }
			if(miss<minMiss){
				minMiss=miss;
				indiceMinMiss=i;
				ended=true;
				offset=unitig.size()-readLeft.size()-k+1;
			}
		}else{
			uint miss(missmatchNumber(unitig.substr(0,unitig.size()-k+1), readLeft.substr(readLeft.size()+k-1-unitig.size()), errors));
			// if(miss==0){
			// 	minMiss+=mapOnLeftEndGreedy(read, path, {nextOverlap,overlap.second-(nextUnitig.size()-k+1)},errors);
			// 	if(minMiss<=errors){
			// 		path.push_back(rangeUnitigs[indiceMinMiss].second);
			// 		sucessML++;
			// 	}
			// }
			if(miss<minMiss){
				kmer overlapNum(str2num(unitig.substr(0,k-1)));
				if(miss<minMiss){
					ended=false;
					minMiss=miss;
					indiceMinMiss=i;
					nextOverlap=overlapNum;
				}
			}

		}
	}

	if(minMiss<=errors){
		if(ended){
			path.push_back(offset);
			path.push_back(rangeUnitigs[indiceMinMiss].second);
			return minMiss;
		}
		minMiss+=mapOnLeftEndGreedy(read, path, {nextOverlap,overlap.second-(rangeUnitigs[indiceMinMiss].first.size()-k+1)},errors-minMiss);
		if(minMiss<=errors){
			path.push_back(rangeUnitigs[indiceMinMiss].second);
			sucessML++;
		}
	}
	return minMiss;
}
Exemple #2
0
t_hitpoint		hitcone(t_ray *r, t_cone *c)
{
	t_hitpoint	h;
	t_param		p;
	double		k;
	t_vec3		e;

	e = VEC3(r->o.x - c->p.x, r->o.y - c->p.y, r->o.z - c->p.z);
	k = c->r / c->h;
	k = k * k;
	p.a = r->dir.x * r->dir.x + r->dir.z * r->dir.z - r->dir.y * r->dir.y * k;
	p.b = 2 * (r->dir.x * e.x + r->dir.z * e.z - r->dir.y * e.y * k);
	p.c = e.x * e.x + e.z * e.z - e.y * e.y * k;
	if ((p.det = p.b * p.b - 4 * p.a * p.c) < EPSILON)
		return (miss());
	p.det = sqrt(p.det);
	h.t = (-p.b - p.det) / (2 * p.a);
	if (h.t < EPSILON)
		h.t = (-p.b + p.det) / (2 * p.a);
	if (h.t < EPSILON)
		return (miss());
	h.p = vec_add(r->o, vec_scalar(r->dir, h.t));
	h.n = normalize((t_vec3){h.p.x - c->p.x, 0, h.p.z - c->p.z});
	h.c = c->color;
	// h.m = p->m;
	return (h);
}
uint Aligner::mapOnRightEndGreedy(const string &read, vector<uNumber>& path, const pair<kmer, uint>& overlap , uint errors){
	// cout<<"moreg"<<endl;
	string unitig,readLeft(read.substr(overlap.second)),nextUnitig;
	// auto rangeUnitigs(getBeginOpti(overlap.first,path.back()));
	auto rangeUnitigs(getBegin(overlap.first));
	uint miniMiss(errors+1), miniMissIndice(9);
	bool ended(false);
	// int offset(0);
	kmer nextOverlap(0);
	// cout<<"go"<<endl;
	// for(uint i(0); i<rangeUnitigs2.size(); ++i){
	// 	cout<<(rangeUnitigs2[i].first)<<endl;
	// }
	// cout<<"true"<<endl;
	for(uint i(0); i<rangeUnitigs.size(); ++i){
		unitig=(rangeUnitigs[i].first);
		// bool stop(false);
		// if(rangeUnitigs[i].first!=rangeUnitigs2[i].first){
		// 	cout<<read<<endl;
		// 	cout<<"lol2"<<endl;
		// 	cout<<rangeUnitigs[i].first<<endl<<rangeUnitigs2[i].first<<endl;
		// 	cout<<rangeUnitigs[i].second<<" "<<rangeUnitigs2[i].second<<endl;
		// 	stop=true;
		// }
		// if(stop){cin.get();}
		// cout<<unitig<<endl;
		// cout<<rangeUnitigs[i].first<<endl;
		//case the rest of the read is too small
		if(readLeft.size()<=unitig.size()){
			uint miss(missmatchNumber(unitig.substr(0,readLeft.size()), readLeft, errors));
			if(miss<miniMiss){
				miniMiss=miss;
				miniMissIndice=i;
				ended=true;
				// offset=unitig.size()-readLeft.size()-k+1;
			}
		}else{
			//case the read is big enough we want to recover a true overlap
			uint miss(missmatchNumber(unitig, read.substr(overlap.second,unitig.size()), errors));
			if(miss<miniMiss){
				if(miss<miniMiss){
					kmer overlapNum(str2num(unitig.substr(unitig.size()-k+1,k-1)));
					miniMiss=miss;
					miniMissIndice=i;
					nextUnitig=unitig;
					nextOverlap=overlapNum;
				}
			}
		}
	}
	// cout<<"end"<<endl;
	if(miniMiss<=errors){
		path.push_back(rangeUnitigs[miniMissIndice].second);
		if (ended){return miniMiss;}
		miniMiss+=mapOnRightEndGreedy(read , path, {nextOverlap,overlap.second+(nextUnitig.size()-k+1)}, errors-miniMiss);
	}
	return miniMiss;
}
Exemple #4
0
uint Aligner::checkEndExhaustive(const string& read, pair<kmer, uint>& overlap, vector<uNumber>& path, uint errors){
	string readLeft(read.substr(overlap.second+k-1)),unitig;
	vector<uNumber> path2keep;
	if(readLeft.empty()){
		path.push_back(0);
		return 0;
	}
	auto rangeUnitigs(getBegin(overlap.first));
	uint minMiss(errors+1),indiceMinMiss(9);
	bool ended(false);
	int offset(-2);
	if(partial & rangeUnitigs.empty()){
		//if(!path.empty()){
			return 0;
		//}
	}

	for(uint i(0); i<rangeUnitigs.size(); ++i){
		unitig=(rangeUnitigs[i].first);
		if(unitig.size()-k+1>=readLeft.size()){
			uint miss(missmatchNumber(unitig.substr(k-1,readLeft.size()),readLeft, errors));
			if(miss<minMiss){
				minMiss=miss;
				indiceMinMiss=i;
				ended=true;
				offset=readLeft.size()+k-1;
			}
		}else{
			uint miss(missmatchNumber(unitig.substr(k-1),readLeft.substr(0,unitig.size()-k+1), errors));
			if(miss<minMiss){
				kmer overlapNum(str2num(unitig.substr(unitig.size()-k+1,k-1)));
				vector<uNumber> possiblePath;
				miss+=mapOnRightEndExhaustive(read, possiblePath, {overlapNum,overlap.second+(unitig.size()-k+1)},errors-miss);
				if(miss<minMiss){
					path2keep=possiblePath;
					minMiss=miss;
					indiceMinMiss=i;
					ended=false;
				}
			}
		}
	}

	if(minMiss<=errors){
		if(ended){
			path.push_back(rangeUnitigs[indiceMinMiss].second);
			path.push_back(offset);
		}else{
			path.push_back(rangeUnitigs[indiceMinMiss].second);
			path.insert(path.end(), path2keep.begin(),path2keep.end());
		}
	}
	return minMiss;
}
Exemple #5
0
pair<uint,uint> Aligner::mapOnRightCache(const string &read, vector<uNumber>& path, const overlapStruct& overlap, const  vector<overlapStruct>& listOverlap, bool& ended,uint start, uint errors){
	string unitig, readLeft(read.substr(overlap.pos+k-1)),nextUnitig;
	if(readLeft.empty()){cout<<"should not appears"<<endl;exit(0);return {start,0};}
	auto rangeUnitigs(overlap.unitig);
	uint miniMiss(errors+1),miniMissIndice(9);
	uint next(start);
	kmer nextOverlapNum(0);

	for(uint i(0); i<rangeUnitigs.size(); ++i){
		unitig=(rangeUnitigs[i]);
		//case the rest of the read is too small
		if(readLeft.size() <= unitig.size()-k+1){
			uint miss(missmatchNumber(unitig.substr(k-1,readLeft.size()), readLeft, errors));
			if(miss<miniMiss){
				ended=true;
				miniMiss=miss;
				miniMissIndice=i;
			}
		}else{
			//case the read is big enough we want to recover a true overlap
			uint miss(missmatchNumber(unitig.substr(k-1), readLeft.substr(0,unitig.size()-k+1), errors));
			if(miss<miniMiss){
				kmer overlapNum(str2num(unitig.substr(unitig.size()-k+1,k-1)));
				if(miss<miniMiss){
					ended=false;
					miniMiss=miss;
					miniMissIndice=i;
					nextOverlapNum=overlapNum;
					nextUnitig=unitig;
					next=start;
					for(uint j(start+1); j<listOverlap.size(); ++j){
						if(overlapNum==listOverlap[j].seq and listOverlap[j].pos==overlap.pos+unitig.size()-k+1){
							next=j;
						}
					}
				}
			}
		}
	}
	if(ended){
		path.push_back(overlap.unitigNumbers[miniMissIndice]);
		return {start,miniMiss};
	}
	if(miniMiss<=errors){
		path.push_back(overlap.unitigNumbers[miniMissIndice]);
		if(next>start){
			return {next,miniMiss};
		}
		auto res(mapOnRightCache(read , path, {nextOverlapNum,overlap.pos+((uint)nextUnitig.size()-k+1)},listOverlap,ended,start, errors-miniMiss));
		return {res.first,res.second+miniMiss};
	}
	return {start,errors+1};
}
int main(){
	S=0, E=0, B=0, m=0, h=0, p=0, t=0, s=0, b=0, tag=0, setIndex=0, blockOffset=0;
	hits=0, misses=0, counter=0;
	scanf("%d %d %d %d",&S,&E,&B,&m);
	scanf("%s",rpolicy);
	scanf("%d %d",&h,&p);
	initCache();
	readAddress();
	int found, i;				
	while(address != -1){
		//set selection
		Set set = cache.sets[setIndex];
		//line matching
		found = 0;
		for(i=0;i<E;i++){
			if(set.lines[i].valid && set.lines[i].tag == tag){
				hit(&set.lines[i]);
				found = 1;
				break;
			}				
		}
		if(!found)
			miss(&set);
		readAddress();		
	}
	freeMemory();
	statistics();
	return 0;
}
Exemple #7
0
uint Aligner::mapOnLeftEndGreedy(const string &read, vector<uNumber>& path, const pair<kmer, uint>& overlap , uint errors){
	// if(overlap.second==0){path.push_back(0);return 0;}
	string unitig,readLeft(read.substr(0,overlap.second)),nextUnitig;
	auto rangeUnitigs(getEnd(overlap.first));
	uint miniMiss(errors+1),miniMissIndice(9);
	bool ended(false);
	int offset(0);
	kmer nextOverlap(0);

	for(uint i(0); i<rangeUnitigs.size(); ++i){
		unitig=(rangeUnitigs[i].first);
		//case the rest of the read is too small
		if(readLeft.size()+k-1 <= unitig.size()){
			uint miss(missmatchNumber(unitig.substr(unitig.size()-readLeft.size()-k+1,readLeft.size()), readLeft, errors));
			if(miss<miniMiss){
				miniMiss=miss;
				miniMissIndice=i;
				ended=true;
				offset=unitig.size()-readLeft.size()-k+1;
			}
		}else{
			//case the read is big enough we want to recover a true overlap
			uint miss(missmatchNumber(unitig.substr(0,unitig.size()-k+1), readLeft.substr(readLeft.size()-(unitig.size()-k+1)), errors));
			if(miss<miniMiss){
				kmer overlapNum(str2num(unitig.substr(0,k-1)));
				if(miss<miniMiss){
					ended=false;
					miniMiss=miss;
					miniMissIndice=i;
					nextUnitig=unitig;
					nextOverlap=overlapNum;
				}
			}
		}
	}

	if (miniMiss<=errors){
		if(ended){
			path.push_back(offset);
			path.push_back(rangeUnitigs[miniMissIndice].second);
			return miniMiss;
		}
		miniMiss+=mapOnLeftEndGreedy(read , path, {nextOverlap,overlap.second-(nextUnitig.size()-k+1)}, errors-miniMiss);
		path.push_back(rangeUnitigs[miniMissIndice].second);
	}
	return miniMiss;
}
Exemple #8
0
uint Aligner::mapOnLeftEndExhaustive(const string &read, vector<uNumber>& path, const pair<kmer, uint>& overlap , uint errors){
	string unitig, readLeft(read.substr(0,overlap.second));
	vector<uNumber> path2keep;
	if(readLeft.size()==0){return 0;}
	auto rangeUnitigs(getEnd(overlap.first));
	uint miniMiss(errors+1),miniMissIndice(9);
	int offset(-2);
	bool ended(false);

	for(uint i(0); i<rangeUnitigs.size(); ++i){
		unitig=(rangeUnitigs[i].first);
		//case the rest of the read is too small
		if(readLeft.size()+k-1 <= unitig.size()){
			uint miss(missmatchNumber(unitig.substr(unitig.size()-readLeft.size()-k+1,readLeft.size()), readLeft, errors));
			if(miss<miniMiss){
				miniMiss=miss;
				miniMissIndice=i;
				offset=unitig.size()-readLeft.size()-k+1;
				ended=true;
			}
		}else{
			//case the read is big enough we want to recover a true overlap
			uint miss(missmatchNumber(unitig.substr(0,unitig.size()-k+1), readLeft.substr(readLeft.size()-(unitig.size()-k+1)), errors));
			if(miss<miniMiss){
				kmer overlapNum(str2num(unitig.substr(0,k-1)));
				vector<uNumber> possiblePath;
				miss+=mapOnLeftEndExhaustive(read , possiblePath, {overlapNum,overlap.second-(unitig.size()-k+1)}, errors-miss);
				if(miss<miniMiss){
					path2keep=possiblePath;
					miniMiss=miss;
					miniMissIndice=i;
					offset=-1;
					ended=false;
				}
			}
		}
	}
	if (miniMiss<=errors){
		if(ended){
			path.push_back(offset);
		}else{
			path.insert(path.end(), path2keep.begin(),path2keep.end());
		}
		path.push_back(rangeUnitigs[miniMissIndice].second);
	}
	return miniMiss;
}
Exemple #9
0
	void Logger::read_miss()
	{
		read();
		miss();
		num_read_misses += 1;

		cur_num_read_misses += 1;
	}
Exemple #10
0
	void Logger::write_miss()
	{
		write();
		miss();
		num_write_misses += 1;

		cur_num_write_misses += 1;
	}
ImageFactoryThumbnail::ImageFactoryThumbnail(ConfigDbEntry *config)
    : m_config(config)
    , m_cycle(0)
{
    connect( m_config, SIGNAL(rawChanged(QString)), this, SLOT(onRawChanged(QString)) );
    connect( &m_config->db()->cache(), SIGNAL(miss(QString)), this, SLOT(onCacheMiss(QString)) );
    connect( &m_config->db()->cache(), SIGNAL(cached(ImageCacheGroup::Action,QString)), this, SLOT(onCacheChanged(ImageCacheGroup::Action,QString)) );
    setUrl( m_cycle );
}
Exemple #12
0
bool Player::attack(Troll& troll) const
{
    if (die_.roll() >= 13)
    {
        return hit(troll);
    }
    else
        return miss();
}
Exemple #13
0
int
verify(void)
{
	int rval;

	root = spec(stdin);
	rval = vwalk();
	miss(root, path);
	return (rval);
}
Exemple #14
0
int
mtree_verifyspec(FILE *fi)
{
        int rval;

        root = mtree_readspec(fi);
        rval = vwalk();
        miss(root, path);
        return (rval);
}
Exemple #15
0
int
verify()
{
	int rval;

	root = spec();
	rval = vwalk();
	miss(root, path);
	return (rval);
}
Exemple #16
0
uint Aligner::checkEndGreedy(const string& read, pair<kmer, uint>& overlap, vector<uNumber>& path, uint errors){
	string readLeft(read.substr(overlap.second+k-1)),unitig,nextUnitig;
	if(readLeft.size()<=k-1){return 0;}
	auto rangeUnitigs(getBegin(overlap.first));
	uint minMiss(errors+1),indiceMinMiss(9);
	bool ended(false);
	kmer nextOverlap(0);

	for(uint i(0); i<rangeUnitigs.size(); ++i){
		unitig=(rangeUnitigs[i].first);
		if(unitig.size()-k+1>=readLeft.size()){
			uint miss(missmatchNumber(unitig.substr(k-1,readLeft.size()),readLeft, errors));
			if(miss<minMiss){
				minMiss=miss;
				indiceMinMiss=i;
				ended=true;
			}
		}else{
			uint miss(missmatchNumber(unitig.substr(k-1),readLeft.substr(0,unitig.size()-k+1), errors));
			if(miss<minMiss){
				if(miss<minMiss){
					kmer overlapNum(str2num(unitig.substr(unitig.size()-k+1,k-1)));
					minMiss=miss;
					indiceMinMiss=i;
					nextOverlap=overlapNum;
					nextUnitig=unitig;
				}
			}
		}
	}

	if(minMiss<=errors){
		path.push_back(rangeUnitigs[indiceMinMiss].second);
		if(ended){
			return minMiss;
		}
		minMiss+=mapOnRightEndGreedy(read, path, {nextOverlap,overlap.second+(nextUnitig.size()-k+1)},errors-minMiss);
		if(minMiss<=errors){
			successMR++;
		}
	}
	return minMiss;
}
Exemple #17
0
/* bhitm: monster mtmp was hit by the effect of wand otmp */
static void
bhitm(struct monst *mtmp, struct obj *otmp)
{
	wakeup(mtmp);
	switch (otmp->otyp) {
	case WAN_STRIKING:
		if (u.uswallow || rnd(20) < 10 + mtmp->data->ac) {
			int tmp = d(2, 12);
			hit("wand", mtmp, exclam(tmp));
			mtmp->mhp -= tmp;
			if (mtmp->mhp < 1)
				killed(mtmp);
		} else
			miss("wand", mtmp);
		break;
	case WAN_SLOW_MONSTER:
		mtmp->mspeed = MSLOW;
		break;
	case WAN_SPEED_MONSTER:
		mtmp->mspeed = MFAST;
		break;
	case WAN_UNDEAD_TURNING:
		if (strchr(UNDEAD, mtmp->data->mlet)) {
			mtmp->mhp -= rnd(8);
			if (mtmp->mhp < 1)
				killed(mtmp);
			else
				mtmp->mflee = 1;
		}
		break;
	case WAN_POLYMORPH:
		if (newcham(mtmp, &mons[rn2(CMNUM)]))
			objects[otmp->otyp].oc_name_known = 1;
		break;
	case WAN_CANCELLATION:
		mtmp->mcan = 1;
		break;
	case WAN_TELEPORTATION:
		rloc(mtmp);
		break;
	case WAN_MAKE_INVISIBLE:
		mtmp->minvis = 1;
		break;
#ifdef WAN_PROBING
	case WAN_PROBING:
		mstatusline(mtmp);
		break;
#endif /* WAN_PROBING */
	default:
		impossible("What an interesting wand (%u)", otmp->otyp);
	}
}
Exemple #18
0
int
mtree_verifyspec(FILE *fi)
{
	int rval, mval;

	root = mtree_readspec(fi);
	rval = vwalk();
	mval = miss(root, path);
	
	if (rval != 0)
		return rval;
	else
		return mval;
}
Exemple #19
0
void			Game::ennemiesShoot()
{
	int		index;

	if (_enemyId)
		index = rand() % _enemyId;
	else
		index = 0;
	Missile miss(_enemy[index].getPosX() - 1, _enemy[index].getPosY(), LEFT, 10, _missileId);
	_missile[_missileId] = miss;
	_missileId++;
	_board.setMatriceValueAt(miss.getPosX(),
			miss.getPosY(), &miss);
}
Exemple #20
0
t_hitpoint		hitplane(t_ray *r, t_plane *p)
{
	double		t;
	t_hitpoint	h;
	
	h.n = p->n;
	t = -(p->d - vec_dot(h.n, r->o)) / vec_dot(h.n, r->dir);
	if (t < EPSILON)
		return(miss());
	h.t = t;
	h.p = vec_add(r->o, vec_scalar(r->dir, h.t));
	h.c = p->color;
	// h.m = p->m;
	return (h);
}
Exemple #21
0
  void SICGenHelper::memOop_prologue(mapOop receiverMapOop,
                                     char* missHandler) {
    //   andcc rr, Mem_Tag, g0
    //   bne,a _check_receiver_map
    //   load rr, map_offset - Mem_Tag, t3
    // _miss:
    //   sethi missHandler, t3
    //   jmpl t3, missHandler, g0
    // _check_receiver_map:
    //   <loadImmediateOop receiver_map, t4>
    //   subcc t3, t4, g0
    //   bne  _miss
    //   nop
    // _cache_hit:

    if (FastMapTest) {
      a->LoadI(LReceiverReg, map_offset(), Temp1);   // load map
      loadImmediateOop(receiverMapOop, Temp2);   // load customization map
      a->SubCCR(Temp1, Temp2, G0);      // compare against actual map
      Label* ok = a->BeqForward(false); // jump to body of nmethod
      jumpTo(missHandler, Temp2, G0);
      if (SICCountTypeTests) {
        a->endTypeTest();
      } else {
        a->Nop();       // must be here in case next instr is a save
      }
      ok->define();
    } else {
      Label* checkMap = NULL;
      a->AndCCI(LReceiverReg, Mem_Tag, G0);  // test for mem tag
      checkMap = a->BneForward(true);       // branch if receiver is a mem oop
      a->LoadI(LReceiverReg, map_offset(), Temp1);   // load map in delay slot
      DefinedLabel miss(a->printing);
      jumpTo(missHandler, Temp2, G0);
      if (checkMap) checkMap->define();
      loadImmediateOop(receiverMapOop, Temp2);   // load customization map
      a->SubCCR(Temp1, Temp2, G0);      // compare against actual map
      a->Bne(&miss, false);             // jump to miss if no match
      if (SICCountTypeTests) {
        a->endTypeTest();
      } else {
        a->Nop();       // must be here in case next instr is a save
      }
    }
  }
Exemple #22
0
  void CodeGen::memOop_prologue(pc_t missHandler) {
    //   andcc rr, Mem_Tag, g0
    //   bne,a _check_receiver_map
    //   load rr, map_offset - Mem_Tag, t3
    // _miss:
    //   sethi missHandler, t3
    //   jmpl t3, missHandler, g0
    // _check_receiver_map:
    //   <loadOop receiver_map, t4>
    //   subcc t3, t4, g0
    //   bne  _miss
    //   nop
    // _cache_hit:

    if (FastMapTest) {
      a.LoadI(ReceiverReg, map_offset(), Temp1);  // load map
      loadOop(Temp2, L->receiverMapOop());        // load customization map
      a.SubCCR(Temp1, Temp2, G0);                 // compare against actual map
      Label* ok = a.BeqForward(false);            // jump to body of nmethod
      jumpTo(missHandler, Temp2, G0);
      if (SICCountTypeTests) {
        a.endTypeTest();
      } else {
        a.Nop();
      }
      ok->define();
    } else {
      a.AndCCI(ReceiverReg, Mem_Tag, G0);         // test for mem tag
      Label* checkMap = a.BneForward(true);       // branch if rcvr is mem oop
      a.LoadI(ReceiverReg, map_offset(), Temp1);  // load map in delay slot
      DefinedLabel miss(a.printing);
      jumpTo(missHandler, Temp2, G0);
      checkMap->define();
      loadOop(Temp2, L->receiverMapOop());      // load customized map
      a.SubCCR(Temp1, Temp2, G0);               // compare against actual map
      a.Bne(&miss, false);                      // jump to miss if no match
      if (SICCountTypeTests) {
        a.endTypeTest();
      } else {
        a.Nop();
      }
    }
  }
Exemple #23
0
int main(int argc, char * tab[])
{
    QApplication app(argc, tab);

        QWidget* window = new QWidget;
    window -> setWindowTitle(QObject::tr("Main Application window"));

        main_widget* main_button = new main_widget();
        //QObject::connect(main_button, SIGNAL(clicked()), &app, SLOT(quit()));

        QVBoxLayout* v_layout = new QVBoxLayout;
        QHBoxLayout* h_layout = new QHBoxLayout;

        QPushButton* pause_button = new QPushButton("PAUSE");
        pause_button ->setCheckable(true);
        QPushButton* reset_button = new QPushButton("RESET");
        QPushButton* quit_button = new QPushButton("QUIT");
        QLabel* hitsNumber = new QLabel;
        QLabel * missesNumber = new QLabel;
        QObject::connect(main_button,SIGNAL(hit(QString)), hitsNumber, SLOT(setText(QString)));
        QObject::connect(main_button,SIGNAL(miss(QString)), missesNumber, SLOT(setText(QString)));
        QObject::connect(quit_button, SIGNAL(clicked()), &app, SLOT(quit()));
        QObject::connect(pause_button,SIGNAL(toggled(bool)),main_button,SLOT(setActive(bool)));
       // QObject::connect(pause_button,SIGNAL(released()),main_button,SLOT(setActive(true)));
        QObject::connect(reset_button, SIGNAL(clicked()), main_button, SLOT(reset()));
        v_layout->addWidget(new QLabel("SUCCESSSES"));
        v_layout ->addWidget(hitsNumber);
        v_layout ->addWidget(new QLabel("FAILURES"));
        v_layout ->addWidget(missesNumber);
        v_layout ->addStretch();
        v_layout -> addWidget(pause_button);
        v_layout -> addWidget(reset_button);
        v_layout -> addWidget(quit_button);
        h_layout -> addWidget(main_button);
        h_layout -> addLayout(v_layout);

        window -> setLayout(h_layout);
        window -> show();
        main_button -> setActive(false);
        return app.exec();
}
Exemple #24
0
/* called with dx = dy = 0 with vertical bolts */
void
buzz(int type, xchar sx, xchar sy, int dx, int dy)
{
	int abstype = abs(type);
	const char *fltxt = (type == -1) ? "blaze of fire" : fl[abstype];
	struct rm *lev;
	xchar range;
	struct monst *mon;

	if(u.uswallow) {
		int tmp;

		if(type < 0) return;
		tmp = zhit(u.ustuck, type);
		pline("The %s rips into %s%s",
			fltxt, monnam(u.ustuck), exclam(tmp));
		return;
	}
	if(type < 0) pru();
	range = rn1(7,7);
	Tmp_at(-1, dirlet(dx,dy));	/* open call */
	while(range-- > 0) {
		sx += dx;
		sy += dy;
		if((lev = &levl[sx][sy])->typ) Tmp_at(sx,sy);
		else {
			int bounce = 0;
			if(cansee(sx-dx,sy-dy))
				pline("The %s bounces!", fltxt);
			if(ZAP_POS(levl[sx][sy-dy].typ))
				bounce = 1;
			if(ZAP_POS(levl[sx-dx][sy].typ)) {
				if(!bounce || rn2(2)) bounce = 2;
			}
			switch(bounce){
			case 0:
				dx = -dx;
				dy = -dy;
				continue;
			case 1:
				dy = -dy;
				sx -= dx;
				break;
			case 2:
				dx = -dx;
				sy -= dy;
				break;
			}
			Tmp_at(-2,dirlet(dx,dy));
			continue;
		}
		if(lev->typ == POOL && abstype == 1 /* fire */) {
			range -= 3;
			lev->typ = ROOM;
			if(cansee(sx,sy)) {
				mnewsym(sx,sy);
				pline("The water evaporates.");
			} else
				pline("You hear a hissing sound.");
		}
		if((mon = m_at(sx,sy)) &&
		   (type != -1 || mon->data->mlet != 'D')) {
			wakeup(mon);
			if(rnd(20) < 18 + mon->data->ac) {
				int tmp = zhit(mon,abstype);
				if(mon->mhp < 1) {
					if(type < 0) {
					    if(cansee(mon->mx,mon->my))
					      pline("%s is killed by the %s!",
						Monnam(mon), fltxt);
					    mondied(mon);
					} else
					    killed(mon);
				} else
					hit(fltxt, mon, exclam(tmp));
				range -= 2;
			} else
				miss(fltxt,mon);
		} else if(sx == u.ux && sy == u.uy) {
			nomul(0);
			if(rnd(20) < 18+u.uac) {
				int dam = 0;
				range -= 2;
				pline("The %s hits you!",fltxt);
				switch(abstype) {
				case 0:
					dam = d(2,6);
					break;
				case 1:
					if(Fire_resistance)
						pline("You don't feel hot!");
					else dam = d(6,6);
					if(!rn2(3))
						burn_scrolls();
					break;
				case 2:
					nomul(-rnd(25)); /* sleep ray */
					break;
				case 3:
					if(Cold_resistance)
						pline("You don't feel cold!");
					else dam = d(6,6);
					break;
				case 4:
					u.uhp = -1;
				}
				losehp(dam,fltxt);
			} else pline("The %s whizzes by you!",fltxt);
			stop_occupation();
		}
		if(!ZAP_POS(lev->typ)) {
			int bounce = 0, rmn;
			if(cansee(sx,sy)) pline("The %s bounces!",fltxt);
			range--;
			if(!dx || !dy || !rn2(20)){
				dx = -dx;
				dy = -dy;
			} else {
			  if(ZAP_POS(rmn = levl[sx][sy-dy].typ) &&
			    (IS_ROOM(rmn) || ZAP_POS(levl[sx+dx][sy-dy].typ)))
				bounce = 1;
			  if(ZAP_POS(rmn = levl[sx-dx][sy].typ) &&
			    (IS_ROOM(rmn) || ZAP_POS(levl[sx-dx][sy+dy].typ)))
				if(!bounce || rn2(2))
					bounce = 2;

			  switch(bounce){
			  case 0:
				dy = -dy;
				dx = -dx;
				break;
			  case 1:
				dy = -dy;
				break;
			  case 2:
				dx = -dx;
				break;
			  }
			  Tmp_at(-2, dirlet(dx,dy));
			}
		}
	}
	Tmp_at(-1,-1);
}
/*
 - longest - longest-preferred matching engine
 ^ static chr *longest(struct vars *, struct dfa *, chr *, chr *, int *);
 */
static chr *			/* endpoint, or NULL */
longest(
    struct vars *v,		/* used only for debug and exec flags */
    struct dfa *d,
    chr *start,			/* where the match should start */
    chr *stop,			/* match must end at or before here */
    int *hitstopp)		/* record whether hit v->stop, if non-NULL */
{
    chr *cp;
    chr *realstop = (stop == v->stop) ? stop : stop + 1;
    color co;
    struct sset *css;
    struct sset *ss;
    chr *post;
    int i;
    struct colormap *cm = d->cm;

    /*
     * Initialize.
     */

    css = initialize(v, d, start);
    cp = start;
    if (hitstopp != NULL) {
	*hitstopp = 0;
    }

    /*
     * Startup.
     */

    FDEBUG(("+++ startup +++\n"));
    if (cp == v->start) {
	co = d->cnfa->bos[(v->eflags&REG_NOTBOL) ? 0 : 1];
	FDEBUG(("color %ld\n", (long)co));
    } else {
	co = GETCOLOR(cm, *(cp - 1));
	FDEBUG(("char %c, color %ld\n", (char)*(cp-1), (long)co));
    }
    css = miss(v, d, css, co, cp, start);
    if (css == NULL) {
	return NULL;
    }
    css->lastseen = cp;

    /*
     * Main loop.
     */

    if (v->eflags&REG_FTRACE) {
	while (cp < realstop) {
	    FDEBUG(("+++ at c%d +++\n", css - d->ssets));
	    co = GETCOLOR(cm, *cp);
	    FDEBUG(("char %c, color %ld\n", (char)*cp, (long)co));
	    ss = css->outs[co];
	    if (ss == NULL) {
		ss = miss(v, d, css, co, cp+1, start);
		if (ss == NULL) {
		    break;	/* NOTE BREAK OUT */
		}
	    }
	    cp++;
	    ss->lastseen = cp;
	    css = ss;
	}
    } else {
	while (cp < realstop) {
	    co = GETCOLOR(cm, *cp);
	    ss = css->outs[co];
	    if (ss == NULL) {
		ss = miss(v, d, css, co, cp+1, start);
		if (ss == NULL) {
		    break;	/* NOTE BREAK OUT */
		}
	    }
	    cp++;
	    ss->lastseen = cp;
	    css = ss;
	}
    }

    /*
     * Shutdown.
     */

    FDEBUG(("+++ shutdown at c%d +++\n", css - d->ssets));
    if (cp == v->stop && stop == v->stop) {
	if (hitstopp != NULL) {
	    *hitstopp = 1;
	}
	co = d->cnfa->eos[(v->eflags&REG_NOTEOL) ? 0 : 1];
	FDEBUG(("color %ld\n", (long)co));
	ss = miss(v, d, css, co, cp, start);

	/*
	 * Special case: match ended at eol?
	 */

	if (ss != NULL && (ss->flags&POSTSTATE)) {
	    return cp;
	} else if (ss != NULL) {
	    ss->lastseen = cp;	/* to be tidy */
	}
    }

    /*
     * Find last match, if any.
     */

    post = d->lastpost;
    for (ss = d->ssets, i = d->nssused; i > 0; ss++, i--) {
	if ((ss->flags&POSTSTATE) && (post != ss->lastseen) &&
		(post == NULL || post < ss->lastseen)) {
	    post = ss->lastseen;
	}
    }
    if (post != NULL) {		/* found one */
	return post - 1;
    }

    return NULL;
}
Exemple #26
0
int
dothrow()
{
	struct obj *obj;
	struct monst *mon;
	int tmp;

	obj = getobj("#)", "throw");   /* it is also possible to throw food */
				       /* (or jewels, or iron balls ... ) */
	if(!obj || !getdir(1))	       /* ask "in what direction?" */
		return(0);
	if(obj->owornmask & (W_ARMOR | W_RING)){
		pline("You can't throw something you are wearing.");
		return(0);
	}

	u_wipe_engr(2);

	if(obj == uwep){
		if(obj->cursed){
			pline("Your weapon is welded to your hand.");
			return(1);
		}
		if(obj->quan > 1)
			setuwep(splitobj(obj, 1));
		else
			setuwep((struct obj *) 0);
	}
	else if(obj->quan > 1)
		(void) splitobj(obj, 1);
	freeinv(obj);
	if(u.uswallow) {
		mon = u.ustuck;
		bhitpos.x = mon->mx;
		bhitpos.y = mon->my;
	} else if(u.dz) {
	  if(u.dz < 0) {
	    pline("%s hits the ceiling, then falls back on top of your head.",
		Doname(obj));		/* note: obj->quan == 1 */
	    if(obj->olet == POTION_SYM)
		potionhit(&youmonst, obj);
	    else {
		if(uarmh) pline("Fortunately, you are wearing a helmet!");
		losehp(uarmh ? 1 : rnd((int)(obj->owt)), "falling object");
		dropy(obj);
	    }
	  } else {
	    pline("%s hits the floor.", Doname(obj));
	    if(obj->otyp == EXPENSIVE_CAMERA) {
		pline("It is shattered in a thousand pieces!");
		obfree(obj, Null(obj));
	    } else if(obj->otyp == EGG) {
		pline("\"Splash!\"");
		obfree(obj, Null(obj));
	    } else if(obj->olet == POTION_SYM) {
		pline("The flask breaks, and you smell a peculiar odor ...");
		potionbreathe(obj);
		obfree(obj, Null(obj));
	    } else {
		dropy(obj);
	    }
	  }
	  return(1);
	} else if(obj->otyp == BOOMERANG) {
		mon = boomhit(u.dx, u.dy);
		if(mon == &youmonst) {		/* the thing was caught */
			(void) addinv(obj);
			return(1);
		}
	} else {
		if(obj->otyp == PICK_AXE && shkcatch(obj))
		    return(1);

		mon = bhit(u.dx, u.dy, (obj->otyp == ICE_BOX) ? 1 :
			(!Punished || obj != uball) ? 8 : !u.ustuck ? 5 : 1,
			obj->olet, NULL, NULL, obj);
	}
	if(mon) {
		/* awake monster if sleeping */
		wakeup(mon);

		if(obj->olet == WEAPON_SYM) {
			tmp = -1+u.ulevel+mon->data->ac+abon();
			if(obj->otyp < ROCK) {
				if(!uwep ||
				    uwep->otyp != obj->otyp+(BOW-ARROW))
					tmp -= 4;
				else {
					tmp += uwep->spe;
				}
			} else
			if(obj->otyp == BOOMERANG) tmp += 4;
			tmp += obj->spe;
			if(u.uswallow || tmp >= rnd(20)) {
				if(hmon(mon,obj,1) == TRUE){
				  /* mon still alive */
#ifndef NOWORM
				  cutworm(mon,bhitpos.x,bhitpos.y,obj->otyp);
#endif /* NOWORM */
				} else mon = 0;
				/* weapons thrown disappear sometimes */
				if(obj->otyp < BOOMERANG && rn2(3)) {
					/* check bill; free */
					obfree(obj, (struct obj *) 0);
					return(1);
				}
			} else miss(objects[obj->otyp].oc_name, mon);
		} else if(obj->otyp == HEAVY_IRON_BALL) {
			tmp = -1+u.ulevel+mon->data->ac+abon();
			if(!Punished || obj != uball) tmp += 2;
			if(u.utrap) tmp -= 2;
			if(u.uswallow || tmp >= rnd(20)) {
				if(hmon(mon,obj,1) == FALSE)
					mon = 0;	/* he died */
			} else miss("iron ball", mon);
		} else if(obj->olet == POTION_SYM && u.ulevel > rn2(15)) {
			potionhit(mon, obj);
			return(1);
		} else {
			if(cansee(bhitpos.x,bhitpos.y))
				pline("You miss %s.",monnam(mon));
			else pline("You miss it.");
			if(obj->olet == FOOD_SYM && mon->data->mlet == 'd')
				if(tamedog(mon,obj)) return(1);
			if(obj->olet == GEM_SYM && mon->data->mlet == 'u' &&
				!mon->mtame){
			 if(obj->dknown && objects[obj->otyp].oc_name_known){
			  if(objects[obj->otyp].g_val > 0){
			    u.uluck += 5;
			    goto valuable;
			  } else {
			    pline("%s is not interested in your junk.",
				Monnam(mon));
			  }
			 } else { /* value unknown to @ */
			    u.uluck++;
			valuable:
			    if(u.uluck > LUCKMAX)	/* dan@ut-ngp */
				u.uluck = LUCKMAX;
			    pline("%s graciously accepts your gift.",
				Monnam(mon));
			    mpickobj(mon, obj);
			    rloc(mon);
			    return(1);
			 }
			}
		}
	}
		/* the code following might become part of dropy() */
	if(obj->otyp == CRYSKNIFE)
		obj->otyp = WORM_TOOTH;
	obj->ox = bhitpos.x;
	obj->oy = bhitpos.y;
	obj->nobj = fobj;
	fobj = obj;
	/* prevent him from throwing articles to the exit and escaping */
	/* subfrombill(obj); */
	stackobj(obj);
	if(Punished && obj == uball &&
		(bhitpos.x != u.ux || bhitpos.y != u.uy)){
		freeobj(uchain);
		unpobj(uchain);
		if(u.utrap){
			if(u.utraptype == TT_PIT)
				pline("The ball pulls you out of the pit!");
			else {
			    long side =
				rn2(3) ? LEFT_SIDE : RIGHT_SIDE;
			    pline("The ball pulls you out of the bear trap.");
			    pline("Your %s leg is severely damaged.",
				(side == LEFT_SIDE) ? "left" : "right");
			    set_wounded_legs(side, 500+rn2(1000));
			    losehp(2, "thrown ball");
			}
			u.utrap = 0;
		}
		unsee();
		uchain->nobj = fobj;
		fobj = uchain;
		u.ux = uchain->ox = bhitpos.x - u.dx;
		u.uy = uchain->oy = bhitpos.y - u.dy;
		setsee();
		(void) inshop();
	}
	if(cansee(bhitpos.x, bhitpos.y)) prl(bhitpos.x,bhitpos.y);
	return(1);
}
Exemple #27
0
static void
miss(NODE *p, char *tail)
{
	int create;
	char *tp;
	const char *type;

	for (; p; p = p->next) {
		if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
			continue;
		strcpy(tail, p->name);
		if (!(p->flags & F_VISIT)) {
			/* Don't print missing message if file exists as a
			   symbolic link and the -q flag is set. */
			struct stat statbuf;
 
			if (qflag && stat(path, &statbuf) == 0)
				p->flags |= F_VISIT;
			else
				printf("%s missing", path);
		}
		if (p->type != F_DIR && p->type != F_LINK) {
			putchar('\n');
			continue;
		}

		create = 0;
		if (p->type == F_LINK)
			type = "symlink";
		else
			type = "directory";
		if (!(p->flags & F_VISIT) && uflag) {
			if (!(p->flags & (F_UID | F_UNAME)))
				printf(" (%s not created: user not specified)", type);
			else if (!(p->flags & (F_GID | F_GNAME)))
				printf(" (%s not created: group not specified)", type);
			else if (p->type == F_LINK) {
				if (symlink(p->slink, path))
					printf(" (symlink not created: %s)\n",
					    strerror(errno));
				else
					printf(" (created)\n");
				if (lchown(path, p->st_uid, p->st_gid))
					printf("%s: user/group not modified: %s\n",
					    path, strerror(errno));
				continue;
			} else if (!(p->flags & F_MODE))
			    printf(" (directory not created: mode not specified)");
			else if (mkdir(path, S_IRWXU))
				printf(" (directory not created: %s)",
				    strerror(errno));
			else {
				create = 1;
				printf(" (created)");
			}
		}
		if (!(p->flags & F_VISIT))
			putchar('\n');

		for (tp = tail; *tp; ++tp);
		*tp = '/';
		miss(p->child, tp + 1);
		*tp = '\0';

		if (!create)
			continue;
		if (chown(path, p->st_uid, p->st_gid)) {
			printf("%s: user/group/mode not modified: %s\n",
			    path, strerror(errno));
			printf("%s: warning: file mode %snot set\n", path,
			    (p->flags & F_FLAGS) ? "and file flags " : "");
			continue;
		}
		if (chmod(path, p->st_mode))
			printf("%s: permissions not set: %s\n",
			    path, strerror(errno));
		if ((p->flags & F_FLAGS) && p->st_flags &&
		    chflags(path, p->st_flags))
			printf("%s: file flags not set: %s\n",
			    path, strerror(errno));
	}
}
Exemple #28
0
static void
miss(NODE *p, char *tail)
{
	int create;
	char *tp;
	const char *type;
	u_int32_t flags;

	for (; p; p = p->next) {
		if (p->flags & F_OPT && !(p->flags & F_VISIT))
			continue;
		if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
			continue;
		strcpy(tail, p->name);
		if (!(p->flags & F_VISIT))
			printf("missing: %s", path);
		switch (p->type) {
		case F_BLOCK:
		case F_CHAR:
			type = "device";
			break;
		case F_DIR:
			type = "directory";
			break;
		case F_LINK:
			type = "symlink";
			break;
		default:
			putchar('\n');
			continue;
		}

		create = 0;
		if (!(p->flags & F_VISIT) && uflag) {
			if (mtree_Wflag || p->type == F_LINK)
				goto createit;
			if (!(p->flags & (F_UID | F_UNAME)))
			    printf(
				" (%s not created: user not specified)", type);
			else if (!(p->flags & (F_GID | F_GNAME)))
			    printf(
				" (%s not created: group not specified)", type);
			else if (!(p->flags & F_MODE))
			    printf(
				" (%s not created: mode not specified)", type);
			else
 createit:
			switch (p->type) {
			case F_BLOCK:
			case F_CHAR:
				if (mtree_Wflag)
					continue;
				if (!(p->flags & F_DEV))
					printf(
				    " (%s not created: device not specified)",
					    type);
				else if (mknod(path,
				    p->st_mode | nodetoino(p->type),
				    p->st_rdev) == -1)
					printf(" (%s not created: %s)\n",
					    type, strerror(errno));
				else
					create = 1;
				break;
			case F_LINK:
				if (!(p->flags & F_SLINK))
					printf(
				    " (%s not created: link not specified)\n",
					    type);
				else if (symlink(p->slink, path))
					printf(
					    " (%s not created: %s)\n",
					    type, strerror(errno));
				else
					create = 1;
				break;
			case F_DIR:
				if (mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO))
					printf(" (not created: %s)",
					    strerror(errno));
				else
					create = 1;
				break;
			default:
				mtree_err("can't create create %s",
				    nodetype(p->type));
			}
		}
		if (create)
			printf(" (created)");
		if (p->type == F_DIR) {
			if (!(p->flags & F_VISIT))
				putchar('\n');
			for (tp = tail; *tp; ++tp)
				continue;
			*tp = '/';
			miss(p->child, tp + 1);
			*tp = '\0';
		} else
			putchar('\n');

		if (!create || mtree_Wflag)
			continue;
		if ((p->flags & (F_UID | F_UNAME)) &&
		    (p->flags & (F_GID | F_GNAME)) &&
		    (lchown(path, p->st_uid, p->st_gid))) {
			printf("%s: user/group/mode not modified: %s\n",
			    path, strerror(errno));
			printf("%s: warning: file mode %snot set\n", path,
			    (p->flags & F_FLAGS) ? "and file flags " : "");
			continue;
		}
		if (p->flags & F_MODE) {
			if (lchmod(path, p->st_mode))
				printf("%s: permissions not set: %s\n",
				    path, strerror(errno));
		}
#if HAVE_STRUCT_STAT_ST_FLAGS
		if ((p->flags & F_FLAGS) && p->st_flags) {
			if (iflag)
				flags = p->st_flags;
			else
				flags = p->st_flags & ~SP_FLGS;
			if (lchflags(path, flags))
				printf("%s: file flags not set: %s\n",
				    path, strerror(errno));
		}
#endif	/* HAVE_STRUCT_STAT_ST_FLAGS */
	}
}
Exemple #29
0
void nGame::Process()
{
	static float absoluteTime = 0.0f;
	static float absoluteTime2 = 0.0f;

	// Check for pause key
	if(nGetInstance()->GetInput()->GetKeyboard()->GetNewKey(DIK_PAUSE) || nGetInstance()->GetInput()->GetKeyboard()->GetNewKey(DIK_P))
		SetPause(!GetPause());

	// Don't process further if paused
	if(m_Pause)
		return;

	absoluteTime += nGetInstance()->GetElapsedTime();
	absoluteTime2 += nGetInstance()->GetElapsedTime();

	// Create enemy missle if enough time passed
	if(absoluteTime > m_MissleTime)
	{
		// Reset the timer
		absoluteTime = 0.0f;
		
		if(m_MissleTime > 1.0f)
			m_MissleTime -= (double)nGetInstance()->GetElapsedTime() / 4.0f;

		// Create a missle at a random top position going to a random bottom position
		AddMissle(nVector2(randf(0.0f,nGetInstance()->GetGraphics()->GetDisplaySize().cx),0.0f),nVector2(randf(0.0f,nGetInstance()->GetGraphics()->GetDisplaySize().cx),nGetInstance()->GetGraphics()->GetDisplaySize().cy),1.0f,80.0f,GAME_ENEMY_COLOR,false,true);
	}

	// Create child enemy missle if enough time passed
	if(absoluteTime2 > 100.0f)
	{
		// Reset the timer
		absoluteTime2 = 0.0f;

		if(m_Missles.size())
		{
			// Create a missle at a random trail of a nother missle
			unsigned long count = 1 + rand() % 3;

			Missle* missle = &m_Missles[rand() % m_Missles.size()];

			// Find a live enemy missle
			while(missle->frendly || missle->dead > 0.0f)
				missle = &m_Missles[rand() % m_Missles.size()];

			nVector2 dir = missle->position - missle->source;
			float length = dir.Length();
			dir.Normalize();

			nVector2 source = missle->source + dir * randf(0.0f,length);

			for(unsigned long i = 0; i < count; i++)
				AddMissle(source,nVector2(randf(0.0f,nGetInstance()->GetGraphics()->GetDisplaySize().cx),nGetInstance()->GetGraphics()->GetDisplaySize().cy),1.0f,80.0f,GAME_ENEMY_COLOR,false,true);
		}
	}

	// Check left missle silo launch
	if(nGetInstance()->GetInput()->GetMouse()->GetNewButton(nMouse::ButtonLeft))
		FireSilo(m_Silos[0],nGetInstance()->GetInput()->GetMouse()->GetPosition(),20.0f,80.0f,true);
	
	// Check right missle silo launch
	if(nGetInstance()->GetInput()->GetMouse()->GetButton(nMouse::ButtonRight))
	{
		// Get a random vector in a sphere domain
		nVector2 miss(randf(-1.0f,1.0f),randf(-1.0f,1.0f));
		miss.Normalize();
		miss *= randf(0.0f,50.0f);

		FireSilo(m_Silos[1],nGetInstance()->GetInput()->GetMouse()->GetPosition() + miss,30.0f,20.0f,false);
	}

	// Remove silo fire time
	for(unsigned long i = 0; i < m_Silos.size(); i++)
	{
		Silo* silo = &m_Silos[i];

		// Remove some fire time
		silo->time -= nGetInstance()->GetElapsedTime();

		// Check if all/too much fire time was removed
		if(silo->time < 0.0f)
			silo->time = 0.0f;
	}

	// Move missles and remove dead ones
	for(unsigned long i = 0; i < m_Missles.size(); i++)
	{
		Missle* missle = &m_Missles[i];

		if(missle->position == missle->destination || missle->dead > 0.0f)
		{
			if(missle->position == missle->destination && !missle->frendly && missle->dead == 0.0f)
			{
				// Players base got hit	
				SetHealth(GetHealth() - 10);

				// Check if player dead
				if(!GetHealth())
				{
					// Game over
					AddHiScore(m_Score);
					RestartGame();

					return;
				}
			}

			if(missle->dead > 10.0f)
			{
				// Remove missle
				RemoveMissle(i--);
				continue;
			}

			if(missle->dead == 0.0f)
			{
				// Explode
				AddExplosion(missle->position,missle->blast,4.0f,nColor(1.0f,0.1f,1.0f));
			}

			missle->dead += nGetInstance()->GetElapsedTime();
			continue;
		}

		if(missle->target > 0.0f)
			missle->target -= nGetInstance()->GetElapsedTime() / 10.0f;
		else if(missle->target < 0.0f)
			missle->target = 0.0f;

		nVector2 velocity = missle->destination - missle->source;
		velocity.Normalize();

		velocity *= missle->speed * nGetInstance()->GetElapsedTime();

		if(velocity.x > 0.0f && missle->position.x + velocity.x > missle->destination.x)
			missle->position.x = missle->destination.x;
		else if(velocity.x < 0.0f && missle->position.x + velocity.x < missle->destination.x)
			missle->position.x = missle->destination.x;
		else
			missle->position.x += velocity.x;

		if(velocity.y > 0.0f && missle->position.y + velocity.y > missle->destination.y)
			missle->position.y = missle->destination.y;
		else if(velocity.y < 0.0f && missle->position.y + velocity.y < missle->destination.y)
			missle->position.y = missle->destination.y;
		else
			missle->position.y += velocity.y;
	}

	// Expand explosions and remove dead ones
	for(unsigned long i = 0; i < m_Explosions.size(); i++)
	{
		Explosion* explosion = &m_Explosions[i];

		if(explosion->size == explosion->power)
		{
			// Remove it
			RemoveExplosion(i--);
			continue;
		}

		float expansion = explosion->speed * nGetInstance()->GetElapsedTime();

		if(explosion->size + expansion > explosion->power)
			explosion->size = explosion->power;
		else
			explosion->size += expansion;

		// Check if the explosion destroyed any missles
		for(unsigned long j = 0; j < m_Missles.size(); j++)
		{
			Missle* missle = &m_Missles[j];

			// Skip frendly or already dead missles
			if(missle->frendly || missle->dead > 0.0f)
				continue;

			nVector2 dir = missle->position - explosion->position;

			unsigned long points = 0;

			if(dir.Length() < explosion->size)
			{
				// Set death time
				missle->dead += nGetInstance()->GetElapsedTime();

				// Create some particles
				for(unsigned long k = 0; k < 50; k++)
				{
					// Get a random vector in a sphere domain
					nVector2 velocity(randf(-1.0f,1.0f),randf(-1.0f,1.0f));
					velocity.Normalize();
					velocity *= randf(0.0f,5.0f);

					AddParticle(missle->position,velocity,nVector2(0.0f,0.1f),10.0f,GAME_COLOR_PARTICLES);
				}

				// Add player points
				points++;
			}

			// Add score
			if(points > 1)
				SetScore(GetScore() + points + points / 2);
			else
				SetScore(GetScore() + points);
		}
	}

	// Move and remove particles
	for(unsigned long i = 0; i < m_Particles.size(); i++)
	{
		Particle* particle = &m_Particles[i];

		// Remove the particle if it's dead
		if(particle->lived >= particle->life)
		{
			// Remove it
			RemoveParticle(i--);
			continue;
		}

		particle->lived += nGetInstance()->GetElapsedTime();

		particle->velocity += particle->force * nGetInstance()->GetElapsedTime();
		particle->position += particle->velocity * nGetInstance()->GetElapsedTime();
	}
}
Exemple #30
0
static void
miss(NODE *p, char *tail)
{
        int create;
        char *tp;
        const char *type, *what;
        int serr;

        for (; p; p = p->next) {
                if (p->flags & F_OPT && !(p->flags & F_VISIT))
                        continue;
                if (p->type != F_DIR && (dflag || p->flags & F_VISIT))
                        continue;
                (void)strcpy(tail, p->name);
                if (!(p->flags & F_VISIT)) {
                        /* Don't print missing message if file exists as a
                           symbolic link and the -q flag is set. */
                        struct stat statbuf;

                        if (qflag && stat(path, &statbuf) == 0)
                                p->flags |= F_VISIT;
                        else
                                (void)printf("%s missing", path);
                }
                if (p->type != F_DIR && p->type != F_LINK) {
                        putchar('\n');
                        continue;
                }

                create = 0;
                if (p->type == F_LINK)
                        type = "symlink";
                else
                        type = "directory";
                if (!(p->flags & F_VISIT) && uflag) {
                        if (!(p->flags & (F_UID | F_UNAME)))
                                (void)printf(" (%s not created: user not specified)", type);
                        else if (!(p->flags & (F_GID | F_GNAME)))
                                (void)printf(" (%s not created: group not specified)", type);
                        else if (p->type == F_LINK) {
                                if (symlink(p->slink, path))
                                        (void)printf(" (symlink not created: %s)\n",
                                            strerror(errno));
                                else
                                        (void)printf(" (created)\n");
                                if (lchown(path, p->st_uid, p->st_gid) == -1) {
                                        serr = errno;
                                        if (p->st_uid == (uid_t)-1)
                                                what = "group";
                                        else if (lchown(path, (uid_t)-1,
                                            p->st_gid) == -1)
                                                what = "user & group";
                                        else {
                                                what = "user";
                                                errno = serr;
                                        }
                                        (void)printf("%s: %s not modified: %s"
                                            "\n", path, what, strerror(errno));
                                }
                                continue;
                        } else if (!(p->flags & F_MODE))
                            (void)printf(" (directory not created: mode not specified)");
                        else if (mkdir(path, S_IRWXU))
                                (void)printf(" (directory not created: %s)",
                                    strerror(errno));
                        else {
                                create = 1;
                                (void)printf(" (created)");
                        }
                }
                if (!(p->flags & F_VISIT))
                        (void)putchar('\n');

                for (tp = tail; *tp; ++tp);
                *tp = '/';
                miss(p->child, tp + 1);
                *tp = '\0';

                if (!create)
                        continue;
                if (chown(path, p->st_uid, p->st_gid) == -1) {
                        serr = errno;
                        if (p->st_uid == (uid_t)-1)
                                what = "group";
                        else if (chown(path, (uid_t)-1, p->st_gid) == -1)
                                what = "user & group";
                        else {
                                what = "user";
                                errno = serr;
                        }
                        (void)printf("%s: %s not modified: %s\n",
                            path, what, strerror(errno));
                }
                if (chmod(path, p->st_mode))
                        (void)printf("%s: permissions not set: %s\n",
                            path, strerror(errno));
#if 0
                if ((p->flags & F_FLAGS) && p->st_flags &&
                    chflags(path, p->st_flags))
                        (void)printf("%s: file flags not set: %s\n",
                            path, strerror(errno));
#endif
        }
}