Esempio n. 1
0
bool CEconomy::BuildMetalStorage(bool extreme){
	NLOG("CEconomy::BuildMetalStorage");
	float x = (float)atof(G->Get_mod_tdf()->SGetValueDef("0.8","ECONOMY\\RULES\\metalstorage").c_str());
	x = max(x,0.01f);
	if(G->cb->GetMetal() >G->cb->GetMetalStorage () * x){
		int randnum = G->mrand()%4;
		randnum = max(1,randnum);
		if(G->cb->GetCurrentFrame()%randnum == 0){
			return true;
		}else{
			return false;
		}
	}else{
		return false;
	}
	// for now I've used a half fudged rule I took from JCAI
	// erm, take the amount of metal currently being used, then see how long it would take to drain away to zero if there was no metal income and if it's smaller than a threshold then say yes, else say no
}
Esempio n. 2
0
	float3 CMap::Pos2BuildPos(float3 pos, const UnitDef* ud){
		NLOG("CMap::Pos2BuildPos");
		if(ud->xsize&2)
			pos.x=floor((pos.x)/(SQUARE_SIZE*2))*SQUARE_SIZE*2+8;
		else
			pos.x=floor((pos.x+8)/(SQUARE_SIZE*2))*SQUARE_SIZE*2;

		if(ud->ysize&2)
			pos.z=floor((pos.z)/(SQUARE_SIZE*2))*SQUARE_SIZE*2+8;
		else
			pos.z=floor((pos.z+8)/(SQUARE_SIZE*2))*SQUARE_SIZE*2;

		pos.y=GetBuildHeight(pos,ud);
		if(ud->floater && pos.y<0)
			pos.y = -ud->waterline;

		return pos;
	}
Esempio n. 3
0
bool CActions::DGun(int uid,int enemy){
	NLOG("CActions::DGun");
	TCommand TCS(tc,"cmd_attack chaser::update every 4 secs");
	tc.ID(CMD_DGUN);
	tc.Push(enemy);
	tc.c.timeOut = 3 SECONDS+(G->cb->GetCurrentFrame()%300) + G->cb->GetCurrentFrame(); // dont let this command get in the way of the commanders taskqueue with a never ending vendetta that can never be fulfilled

	tc.created = G->cb->GetCurrentFrame();
	tc.unit = uid;
	if(G->OrderRouter->GiveOrder(tc,true)==false){
		return false; // GiveOrder returned an error
	}else{
		G->Ch->dgunning.insert(uid); 
		// Command successful, This unit is now dgunning, so add it to this container so that next time it
		// dguns we can prevent it from doing so because it's already dgunning
		return true;
	}
}
void COrderRouter::CleanUpOrders(){
    NLOG("COrderRouter::CleanUpOrders()");
    if(CommandCache.empty() == false){
        int hg = CommandCache.size();
        if( hg >20){
            for(int j = 2;  j <(hg/2) ; j++){
                if(CommandCache.empty() == false){
                    for(vector<TCommand>::iterator i = CommandCache.begin(); i != CommandCache.end();++i){
                        if(i->clear == true){
                            CommandCache.erase(i);
                            break;
                        }
                    }
                }
            }
        }
    }
}
Esempio n. 5
0
bool CEconomy::BuildEnergyStorage(bool extreme){
	NLOG("CEconomy::BuildEnergyStorage");
	float x = (float)atof(G->Get_mod_tdf()->SGetValueDef("0.8","ECONOMY\\RULES\\energystorage").c_str());
	if(G->cb->GetEnergy() > G->cb->GetEnergyStorage () * x){
		// randomly do this so there's a 1/3 chance
		int randnum = G->mrand()%4;
		randnum = max(randnum,1);
		if(G->cb->GetCurrentFrame()%randnum == 0){
			return true;
		}else{
			return false;
		}
	}else{
		return false;
	}
	// for now I've used a half fudged rule I took from JCAI
	// erm, take the amount of energy currently being used, then see how long ti would take to drain away to zero if there was no energy income and if it's smaller than a threshold then say yes, else say no
}
Esempio n. 6
0
	string CUBuild::GetESTORE(){
		NLOG("CUBuild::GetESTORE");
		list<string> possibles;
		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
		if(di == 0) return string("");

		int randnum = 0;
		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
			if(is->id<0){

				// retrieve the unit type information
				CUnitTypeData* p =G->UnitDefLoader->GetUnitTypeDataByName(is->name);
				const UnitDef* pd = p->GetUnitDef();

				if(pd->energyStorage >100){
					if(G->Pl->feasable(pd->name,uid)==false) continue;
					if(pd->floater == true){
						if((G->info->spacemod == true)||(water == true)){
							possibles.push_back(pd->name);
							randnum++;
						}
					} else{
						possibles.push_back(pd->name);
						randnum++;
					}
				}
			}
		}

		if(possibles.empty() == false){
			randnum = G->mrand()%randnum;
			int j = 0;
			for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
				if(j == randnum){
					return *k;
				}else{
					j++;
				}
			}
			return possibles.front();
		}

		return string("");
	}
Esempio n. 7
0
	string CUBuild::GetANTIMISSILE(){
		NLOG("CUBuild::GetANTIMISSILE");

		list<string> possibles;
		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
		if(di == 0) return string("");
		int randnum = 0;

		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
			if(is->id<0){

				// retrieve the unit type information
				CUnitTypeData* p =G->UnitDefLoader->GetUnitTypeDataByName(is->name);
				const UnitDef* pd = p->GetUnitDef();

				if(pd->weapons.empty() != true){
					if(G->Pl->feasable(pd->name,uid)==false) continue;
					for(vector<UnitDef::UnitDefWeapon>::const_iterator i = pd->weapons.begin(); i != pd->weapons.end(); ++i){
						//
						if(i->def->interceptor == 1){
							possibles.push_back(pd->name);
							randnum++;
							break;
						}
					}
				}
			}
		}

		if(possibles.empty() == false){
			randnum = G->mrand()%randnum;
			int j = 0;
			for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
				if(j == randnum){
					return *k;
				}else{
					j++;
				}
			}
			return possibles.front();
		}
		return string("");
	}
Esempio n. 8
0
static void
wwvb_control(
	int unit,
	struct refclockstat *in_st,
	struct refclockstat *out_st,
	struct peer *peer
	)
{
	register struct wwvbunit *up;
	struct refclockproc *pp;
	
	pp = peer->procptr;
	up = pp->unitptr;

	if (!(pp->sloppyclockflag & CLK_FLAG1)) {
		if (!up->ppsapi_tried)
			return;
		up->ppsapi_tried = 0;
		if (!up->ppsapi_lit)
			return;
		peer->flags &= ~FLAG_PPS;
		peer->precision = PRECISION;
		time_pps_destroy(up->atom.handle);
		up->atom.handle = 0;
		up->ppsapi_lit = 0;
		return;
	}

	if (up->ppsapi_tried)
		return;
	/*
	 * Light up the PPSAPI interface.
	 */
	up->ppsapi_tried = 1;
	if (refclock_ppsapi(pp->io.fd, &up->atom)) {
		up->ppsapi_lit = 1;
		return;
	}

	NLOG(NLOG_CLOCKINFO)
		msyslog(LOG_WARNING, "%s flag1 1 but PPSAPI fails",
			refnumtoa(&peer->srcadr));
}
Esempio n. 9
0
	string CUBuild::GetMISSILE_UNIT(){
		NLOG("CUBuild::GetMISSILE_UNIT");
		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
		if(di == 0) return string("");
		list<string> possibles;
		float best_score = 0;
		string best = "";
		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
			if(is->id<0){

				CUnitTypeData* p =G->UnitDefLoader->GetUnitTypeDataByName(is->name);

				if(p->GetUnitDef()->metalCost+p->GetUnitDef()->energyCost > (G->cb->GetEnergyStorage()+G->cb->GetMetalStorage())*atof(G->Get_mod_tdf()->SGetValueDef("2.1", "AI\\cheap_multiplier").c_str())) continue;
				bool good = true;
				if(p->GetUnitDef()->canfly == false) good = false;
				if(p->GetUnitDef()->weapons.empty() == true) good = false;
				if(p->GetUnitDef()->builder == true) good = false;
				if(p->GetUnitDef()->transportCapacity > 0) good = false;
				bool found = false;
				for(vector<UnitDef::UnitDefWeapon>::const_iterator i = p->GetUnitDef()->weapons.begin(); i != p->GetUnitDef()->weapons.end(); ++i){
					if(i->def->interceptor > 0){
						continue;
					}
					if(i->def->type == string("StarburstLauncher")){
						found = true;
						break;
					}
				}
				if(found == false) good = false;
				if(good == true){
					float temp = G->efficiency->GetEfficiency(p->GetName());
					temp /= (p->GetUnitDef()->energyCost+(p->GetUnitDef()->metalCost*45));
					temp = temp - G->mrand()%min((int)(temp/3),1);
					if(temp > best_score){
						best_score = temp;
						best = p->GetName();
					}
				}
			}
		}
		return best;
	}
Esempio n. 10
0
	float3 CMap::distfrom(float3 Start, float3 Target, float distance){
		NLOG("CMap::distfrom");

		if(!CheckFloat3(Start)){
			return UpVector;
		}

		if(!CheckFloat3(Target)){
			return UpVector;
		}

		float p = distance/Start.distance2D(Target);
		if(p < 0) p *= -1;

		float dx = Start.x-Target.x;
		if(dx < 0) dx *= -1;

		float dz = Start.z-Target.z;
		if(dz < 0) dz *= -1;

		dz *= p;
		dx *= p;

		float x = Target.x;

		if(Start.x > Target.x){
			x += dx;
		} else{
			x -= dx;
		}

		float z = Target.z;

		if(Start.z > Target.z){
			z += dz;
		}else{
			z -= dz;
		}

		return float3(x,0,z);

	}
Esempio n. 11
0
string CUBuild::GetMISSILE_UNIT(){
	NLOG("CUBuild::GetMISSILE_UNIT");
	const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
	if(di == 0) return string("");
	list<string> possibles;
	float best_score = 0;
	string best = "";
	for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
		if(is->id<0){
			const UnitDef* pd = G->GetUnitDef(is->name);
			if(pd == 0) continue;
			if(pd->metalCost+pd->energyCost > (G->cb->GetEnergyStorage()+G->cb->GetMetalStorage())*atof(G->Get_mod_tdf()->SGetValueDef("2.1", "AI\\cheap_multiplier").c_str())) continue;
			bool good = true;
			if(pd->canfly ==false) good = false;
			if(pd->weapons.empty() == true) good = false;
			if(pd->builder == true) good = false;
			if(pd->transportCapacity > 0) good = false;
			bool found = false;
			for(vector<UnitDef::UnitDefWeapon>::const_iterator i = pd->weapons.begin(); i != pd->weapons.end(); ++i){
				if(i->def->interceptor > 0){
					continue;
				}
				if(i->def->vlaunch == true){
					found = true;
					break;
				}
			}
			if(found == false) good = false;
			if(good == true){
				srand(uint(time(NULL) + G->Cached->randadd));
				G->Cached->randadd++;
				float temp = G->GetEfficiency(pd->name);
				temp = temp - rand()%(int)(temp/3);
				if(temp > best_score){
					best_score = temp;
					best = pd->name;
				}
			}
		}
	}
	return best;
}
Esempio n. 12
0
	float CMap::GetBuildHeight(float3 pos, const UnitDef* unitdef){
		NLOG("CMap::GetBuildHeight");
		float minh=-5000;
		float maxh=5000;
		int numBorder=0;
		float borderh=0;

		float maxDif=unitdef->maxHeightDif;
		int x1 = (int)max(0.f,(pos.x-(unitdef->xsize*0.5f*SQUARE_SIZE))/SQUARE_SIZE);
		int x2 = min(G->cb->GetMapWidth()*SQUARE_SIZE,x1+unitdef->xsize);
		int z1 = (int)max(0.f,(pos.z-(unitdef->ysize*0.5f*SQUARE_SIZE))/SQUARE_SIZE);
		int z2 = min(G->cb->GetMapHeight()*SQUARE_SIZE,z1+unitdef->ysize);

		if (x1 > G->cb->GetMapWidth()*SQUARE_SIZE) x1 = G->cb->GetMapWidth()*SQUARE_SIZE;
		if (x2 < 0) x2 = 0;
		if (z1 > G->cb->GetMapHeight()*SQUARE_SIZE) z1 = G->cb->GetMapHeight()*SQUARE_SIZE;
		if (z2 < 0) z2 = 0;

		const float* heightmap = G->cb->GetHeightMap();
		for(int x=x1; x<=x2; x++){
			for(int z=z1; z<=z2; z++){
				float orgh=heightmap[z*(G->cb->GetMapWidth()*SQUARE_SIZE+1)+x];
				float h=heightmap[z*(G->cb->GetMapWidth()*SQUARE_SIZE+1)+x];
				if(x==x1 || x==x2 || z==z1 || z==z2){
					numBorder++;
					borderh+=h;
				}
				if(minh<min(h,orgh)-maxDif)
					minh=min(h,orgh)-maxDif;
				if(maxh>max(h,orgh)+maxDif)
					maxh=max(h,orgh)+maxDif;
			}
		}
		float h=borderh/numBorder;

		if(h<minh && minh<maxh)
			h=minh+0.01f;
		if(h>maxh && maxh>minh)
			h=maxh-0.01f;

		return h;
	}
Esempio n. 13
0
bool CActions::SeekOutNearestInterest(int unit){
	NLOG("CActions::SeekOutNearestInterest");
	if(unit < 1) return false;
	if(points.empty() == true) return false;
	float3 pos = G->GetUnitPos(unit);
	if(G->Map->CheckFloat3(pos) == false) return false;
	if(points.empty() == false){
		float3 destination = UpVector;
		float shortest = 2000000.0f;
		for(vector<float3>::iterator i = points.begin(); i != points.end(); ++i){
			if(pos.distance2D(*i) < shortest){
				destination = *i;
			}
		}
		if(G->Map->CheckFloat3(destination)==true){
			return Move(unit,destination);
		}
	}
	return false;
}
Esempio n. 14
0
/*
 * Initialize the logging
 */
void
init_logging(
	char const *name,
	int log_version
	)
{
	const char *cp;

	/*
	 * Logging.  This may actually work on the gizmo board.  Find a name
	 * to log with by using the basename
	 */
	cp = strrchr(name, '/');
	if (cp == 0)
		cp = name;
	else
		cp++;

#if !defined(VMS)

# ifndef LOG_DAEMON
	openlog(cp, LOG_PID);
# else /* LOG_DAEMON */

#  ifndef LOG_NTP
#	define	LOG_NTP LOG_DAEMON
#  endif
	openlog(cp, LOG_PID | LOG_NDELAY, LOG_NTP);
#  ifdef DEBUG
	if (debug)
		setlogmask(LOG_UPTO(LOG_DEBUG));
	else
#  endif /* DEBUG */
		setlogmask(LOG_UPTO(LOG_DEBUG)); /* @@@ was INFO */
# endif /* LOG_DAEMON */
#endif	/* !VMS */

	if (log_version)
	    NLOG(NLOG_SYSINFO) /* 'if' clause for syslog */
		msyslog(LOG_NOTICE, "%s", Version);
}
Esempio n. 15
0
string CUBuild::GetFACTORY(){
	NLOG("CUBuild::GetFACTORY");
	const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
	if(di == 0) return string("");
	list<string> possibles;
	// Find all factories this unit can build and add them to a list.
	int facnum = 0;
	for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
		if(is->id<0){
			const UnitDef* pd = G->GetUnitDef(is->name);
			if(pd == 0) continue;
			if(G->UnitDefHelper->IsFactory(pd)==true){
				if(G->Pl->feasable(pd->name,uid)==false) continue;
				if(pd->floater == true){
					if((G->info->spacemod == true)||(water == true)){
						possibles.push_back(pd->name);
						facnum++;
					}
				} else{
					possibles.push_back(pd->name);
					facnum++;
				}
			}
		}
	}
	if(possibles.empty() == false){
		srand(uint(time(NULL) +G->Cached->team +  G->Cached->randadd));
		G->Cached->randadd++;
		facnum = rand()%facnum;
		int j = 0;
		for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
			if(j == facnum){
				return *k;
			}else{
				j++;
			}
		}
		return possibles.front();
	}
	return string("");
}
Esempio n. 16
0
string CUBuild::GetMSTORE(){
	NLOG("CUBuild::GetMSTORE");
	list<string> possibles;
	const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
	if(di == 0) return string("");
	
	int randnum = 0;
	for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
		if(is->id<0){
			const UnitDef* pd = G->GetUnitDef(is->name);
			if(pd == 0) continue;
			if(pd->metalStorage >100){
				if(G->Pl->feasable(pd->name,uid)==false) continue;
				if(pd->floater == true){
					if((G->info->spacemod == true)||(water == true)){
						possibles.push_back(pd->name);
						randnum++;
					}
				} else{
					possibles.push_back(pd->name);
					randnum++;
				}
			}
		}
	}
	if(possibles.empty() == false){
		srand(uint(time(NULL) +G->Cached->team +  G->Cached->randadd));
		G->Cached->randadd++;
		randnum = rand()%randnum;
		int j = 0;
		for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
			if(j == randnum){
				return *k;
			}else{
				j++;
			}
		}
		return possibles.front();
	}
	return string("");
}
Esempio n. 17
0
bool CActions::RessurectNearby(int uid){
	NLOG("CActions::RessurectNearby");
	float3 upos = G->GetUnitPos(uid);
	if(G->Map->CheckFloat3(upos)){
		int* f = new int[1000];
		int fc = G->cb->GetFeatures(f,99,upos,700);
		delete [] f;
		if(fc >0){
			TCommand TCS(tc,"ressurect nearby CActions");
			tc.ID(CMD_RESURRECT);
			tc.PushFloat3(upos);
			tc.Push(700);
			tc.created = G->cb->GetCurrentFrame();
			tc.unit = uid;
			return G->OrderRouter->GiveOrder(tc,true);
		}else{
			return false;
		}
	}
	return false;
}
Esempio n. 18
0
	t_direction CMap::WhichCorner(float3 pos){
		NLOG("CMap::WhichCorner");

		if ((pos.x<(G->cb->GetMapWidth()*4))&&(pos.z<(G->cb->GetMapHeight()*SQUARE_SIZE*4))){
			return t_NW;
		}

		if ((pos.x>(G->cb->GetMapWidth()*4))&&(pos.z<(G->cb->GetMapHeight()*SQUARE_SIZE*4))){
			return t_NE;
		}

		if ((pos.x<(G->cb->GetMapWidth()*4))&&(pos.z>(G->cb->GetMapHeight()*SQUARE_SIZE*4))){
			return t_SW;
		}

		if ((pos.x>(G->cb->GetMapWidth()*4))&&(pos.z>(G->cb->GetMapHeight()*SQUARE_SIZE*4))){
			return t_SE;
		}

		return t_NA;
	}
Esempio n. 19
0
void Scouter::UnitDestroyed(int unit){
	NLOG("Scouter::UnitDestroyed");
	if(cp.empty() == false){
		for(map< int, list<float3> >::iterator q = cp.begin(); q != cp.end();++q){
			if(q->first == unit){
				cp.erase(q);
				break;
			}
		}
	}
	const UnitDef* ud = G->cb->GetUnitDef(unit);
	if(ud == 0) return;
	float3 dpos = G->cb->GetUnitPos(unit);
	if((ud->extractsMetal >0)&&(cp.empty() == false)){
		for(map<int, list<float3> >::iterator i = cp.begin(); i != cp.end(); ++i){
			i->second.push_back(dpos);
		}
		mexes.push_back(dpos);
	}
	
}
Esempio n. 20
0
string CUBuild::GetMEX(){
	NLOG("CUBuild::GetMEX");
	// Find all metal extractors this unit can build and add them to a list.
	float highscore= 0;
	string highest="";
	for(map<int,string>::const_iterator is = ud->buildOptions.begin(); is != ud->buildOptions.end();++is){
		const UnitDef* pd = G->GetUnitDef(is->second);
		if(pd == 0) continue;
		if(pd->type == string("MetalExtractor")){
			if(Useless(pd)==true) continue;
			float score = (pd->extractsMetal+1)*1000;
			if(pd->weapons.empty()==false){
				score *= 1.2f;
			}
			if(pd->canCloak==true){
				score *= 1.2f;
			}
			if(score > highscore){
				highscore = score;
				highest = pd->name;
			}
			continue;
		}
		if((pd->metalMake > 5)&&(pd->builder == false)&&(pd->movedata == 0 )&&(pd->canfly == false)){
			float score = pd->metalMake;
			if(pd->weapons.empty()==false){
				score *= 1.2f;
			}
			if(pd->canCloak==true){
				score *= 1.2f;
			}
			if(score > highscore){
				highscore = score;
				highest = pd->name;
			}
			continue;
		}
	}
	return highest;
}
Esempio n. 21
0
string CUBuild::GetFACTORY_CHEAP(){
	NLOG("CUBuild::GetFACTORY_CHEAP");
	const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
	if(di == 0) return string("");
	list<string> possibles;
	// Find all factories this unit can build and add them to a list.
	float multiplier = (float)atof(G->Get_mod_tdf()->SGetValueMSG("AI\\cheap_multiplier").c_str());
	if(multiplier == 0) multiplier = 1.7f;
	for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
		if(is->id<0){
			//if(G->Pl->feasable(is->name,uid) == false) continue;
			const UnitDef* pd = G->GetUnitDef(is->name);
			if(pd == 0) continue;
			if((pd->builder == true)&&(pd->movedata == 0)&&(pd->canfly == false)){
				if(G->info->spacemod == true){
					if(pd->metalCost+pd->energyCost < (G->cb->GetEnergyStorage()+1+G->cb->GetMetalStorage())*multiplier) possibles.push_back(pd->name);
				}else if(water == true){
					if(pd->metalCost+pd->energyCost < (G->cb->GetEnergyStorage()+1+G->cb->GetMetalStorage())*multiplier) possibles.push_back(pd->name);
				}else if(pd->floater == false){
					if(pd->metalCost+pd->energyCost < (G->cb->GetEnergyStorage()+1+G->cb->GetMetalStorage())*multiplier) possibles.push_back(pd->name);
				}
			}
		}
	}
	if(possibles.empty() == false){
		srand(uint(time(NULL) +G->Cached->team +  G->Cached->randadd));
		G->Cached->randadd++;
		int facnum = rand()%possibles.size();
		int j = 0;
		for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
			if(j == facnum){
				return *k;
			}else{
				j++;
			}
		}
		return possibles.front();
	}
	return string("");
}
Esempio n. 22
0
/*
 * refclock_report - note the occurance of an event
 *
 * This routine presently just remembers the report and logs it, but
 * does nothing heroic for the trap handler. It tries to be a good
 * citizen and bothers the system log only if things change.
 */
void
refclock_report(
	struct peer *peer,
	int code
	)
{
	struct refclockproc *pp;

	if (!(pp = peer->procptr))
		return;
	if (code == CEVNT_BADREPLY)
		pp->badformat++;
	if (code == CEVNT_BADTIME)
		pp->baddata++;
	if (code == CEVNT_TIMEOUT)
		pp->noreply++;
	if (pp->currentstatus != code) {
		pp->currentstatus = code;
		pp->lastevent = code;
		if (code == CEVNT_FAULT)
			msyslog(LOG_ERR,
				"clock %s event '%s' (0x%02x)",
				refnumtoa(peer->srcadr.sin_addr.s_addr),
				ceventstr(code), code);
		else {
			NLOG(NLOG_CLOCKEVENT)
				msyslog(LOG_INFO,
				"clock %s event '%s' (0x%02x)",
				refnumtoa(peer->srcadr.sin_addr.s_addr),
				ceventstr(code), code);
		}
	}
#ifdef DEBUG
	if (debug)
		printf("clock %s event '%s' (0x%02x)\n",
			refnumtoa(peer->srcadr.sin_addr.s_addr),
			ceventstr(code), code);
#endif
}
Esempio n. 23
0
	string CUBuild::GetSHIELD(){
		NLOG("CUBuild::GetSHIELD");
		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
		if(di == 0) return string("");
		list<string> possibles;
		float best_score = 0;
		string best = "";
		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
			if(is->id<0){

				CUnitTypeData* p =G->UnitDefLoader->GetUnitTypeDataByName(is->name);


				if(G->Pl->feasable(p,utd)) continue;

				if(p->GetUnitDef()->metalCost+p->GetUnitDef()->energyCost > (G->cb->GetEnergyStorage()+G->cb->GetMetalStorage())*atof(G->Get_mod_tdf()->SGetValueDef("2.1", "AI\\cheap_multiplier").c_str())) continue;

				bool found = false;
				if(p->GetUnitDef()->weapons.empty() == false){
					for(vector<UnitDef::UnitDefWeapon>::const_iterator i = p->GetUnitDef()->weapons.begin(); i != p->GetUnitDef()->weapons.end(); ++i){
						if(i->def->isShield){
							found = true;
							break;
						}
					}
				}
				if(found == true){
					float temp = G->efficiency->GetEfficiency(p->GetName());
					temp /= (p->GetUnitDef()->energyCost+(p->GetUnitDef()->metalCost*45));
					temp = temp - G->mrand()%max(int(temp/4),1);
					if(temp > best_score){
						best_score = temp;
						best = p->GetName();
					}
				}
			}
		}
		return best;
	}
Esempio n. 24
0
	bool CMap::CheckFloat3(float3 pos){
		NLOG("CMap::CheckFloat3");
		if(pos == UpVector){ //error codes
			return false;
		}else if(pos == ZeroVector){ //error codes
			return false;
		}else if(pos == float3(-1,0,0)){ //error codes
			return false;
		}else if(pos.distance2D(UpVector) <50){ // top corner!!!!!
			return false;
		}/*else if(pos.x > G->cb->GetMapWidth()*SQUARE_SIZE){ // offmap
			return false;
		}else if(pos.z > G->cb->GetMapHeight()*SQUARE_SIZE){ // offmap
			return false;
		}else if(pos.x < 0){ // offmap
			return false;
		}else if(pos.z < 0){ // offmap
			return false;
		}*/else{
			return true;
		}
	}
Esempio n. 25
0
string CUBuild::GetANTIMISSILE(){
	NLOG("CUBuild::GetANTIMISSILE");
	list<string> possibles;
	const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
	if(di == 0) return string("");
	int randnum = 0;
	for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
		if(is->id<0){
			const UnitDef* pd = G->GetUnitDef(is->name);
			if(pd == 0) continue;
			if(pd->weapons.empty() != true){
				if(G->Pl->feasable(pd->name,uid)==false) continue;
				for(vector<UnitDef::UnitDefWeapon>::const_iterator i = pd->weapons.begin(); i != pd->weapons.end(); ++i){
					//
					if(i->def->interceptor == 1){
						possibles.push_back(pd->name);
						randnum++;
						break;
					}
				}
			}
		}
	}
	if(possibles.empty() == false){
		srand(uint(time(NULL) +G->Cached->team +  G->Cached->randadd));
		G->Cached->randadd++;
		randnum = rand()%randnum;
		int j = 0;
		for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
			if(j == randnum){
				return *k;
			}else{
				j++;
			}
		}
		return possibles.front();
	}
	return string("");
}
Esempio n. 26
0
	string CUBuild::GetFORTIFICATION(){
		NLOG("CUBuild::GetFORTIFICATION");

		if(G->DTHandler->DTNeeded() == false) return string("");

		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
		if(di == 0) return string("");

		list<string> possibles;

		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
			if(is->id<0){

				// retrieve the unit type information
				CUnitTypeData* p =G->UnitDefLoader->GetUnitTypeDataByName(is->name);
				const UnitDef* pd = p->GetUnitDef();

				if(G->DTHandler->IsDragonsTeeth(pd)){
					possibles.push_back(pd->name);
				}

			}
		}

		if(possibles.empty() == false){
			int randnum = G->mrand()%possibles.size();
			int j = 0;
			for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
				if(j == randnum){
					return *k;
				}else{
					j++;
				}
			}
			return possibles.front();
		}
		return string("");
	}
Esempio n. 27
0
string CUBuild::GetRANDOM(){
	NLOG("CUBuild::GetRANDOM");
	const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
	if(di == 0) return string("");
	list<string> possibles;
	int randnum = 0;
	for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
		if(is->id<0){
			const UnitDef* pd = G->GetUnitDef(is->name);
			if(pd == 0) continue;
			if((pd->canKamikaze)&&((pd->canfly == false)&&(pd->movedata == 0))) continue; // IT'S A MINE!!!! We dont want nonblocking mines built ontop of eachother next to the factory!!!!!!!!!!!
			if((pd->radarRadius > 10)&&((pd->builder == false)||(pd->isAirBase == true))) continue; // no radar towers!!!!
			if((pd->energyStorage > 100)||(pd->metalStorage > 100)) continue; // no resource storage!!!!!!!!
			if(pd->isMetalMaker == true) continue; // no metal makers
			if(Useless(pd)==true) continue;
			if((pd->metalCost+pd->energyCost < (G->cb->GetEnergy()+G->cb->GetMetal())*0.9)&&(((pd->floater == false)&&(water == false)&&(G->info->spacemod == false))||((G->info->spacemod == true)||(water == true)))){
				if(G->Pl->feasable(pd->name,uid)==false) continue;
				possibles.push_back(pd->name);
				randnum++;
			}
		}
	}
	if(possibles.empty() == false){
		srand(uint(time(NULL) +G->Cached->team +  G->Cached->randadd));
		G->Cached->randadd++;
		randnum = rand()%randnum;
		int j = 0;
		for(list<string>::iterator k = possibles.begin(); k != possibles.end(); ++k){
			if(j == randnum){
				return *k;
			}else{
				j++;
			}
		}
		return possibles.front();
	}
	return string("");
}
Esempio n. 28
0
	string CUBuild::GetBUILDER(){
		NLOG("CUBuild::GetBUILDER");
		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);
		if(di == 0) return string("");
		list<string> possibles;
		float best_score = 0;
		string best = "";
		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
			if(is->id<0){
				
				CUnitTypeData* p =G->UnitDefLoader->GetUnitTypeDataByName(is->name);


				if(p->GetUnitDef()->builder&&((p->GetUnitDef()->movedata !=0)||p->GetUnitDef()->canfly)){
					if(G->Pl->feasable(p,utd)==false) continue;
					if(p->GetUnitDef()->floater){
						if(G->info->spacemod||water){
							float temp = G->efficiency->GetEfficiency(p->GetUnitDef()->name);
							if(!p->GetUnitDef()->buildOptions.empty()){
								for(map<int,std::string>::const_iterator i = p->GetUnitDef()->buildOptions.begin(); i != p->GetUnitDef()->buildOptions.end(); ++i){
									temp += G->efficiency->GetEfficiency(i->second);
								}
							}
							temp*=p->GetUnitDef()->buildSpeed;
							temp /= (p->GetUnitDef()->energyCost+(p->GetUnitDef()->metalCost*45));
							temp = temp - G->mrand()%max(int(temp/4),1);
							if(temp > best_score){
								best_score = temp;
								best = p->GetName();
							}
						}
					}
				}
			}
		}
		return best;
	}
Esempio n. 29
0
	bool CEconomy::BuildMex(bool extreme){
		NLOG("CEconomy::BuildMex");

		if(extreme){
			float x = (float)atof(G->Get_mod_tdf()->SGetValueDef("0.4","ECONOMY\\RULES\\EXTREME\\mex").c_str());
			
			// if below 20% metal stored then yah we need mexes!!
			if(G->cb->GetMetal() < G->cb->GetMetalStorage()*x){
				return true;
			}else{
				if(G->cb->GetMetal() < 400.0f){
					return true;
				}
				if(G->Pl->GetMetalIncome() < G->cb->GetMetalUsage()*(1-x)){
					return true;
				}
				return false;
			}
		}else{

			float x = (float)atof(G->Get_mod_tdf()->SGetValueDef("0.5","ECONOMY\\RULES\\mex").c_str());
			
			// if below 50% metal stored then yah we need mexes!!
			if(G->cb->GetMetal() < G->cb->GetMetalStorage()*x){ 
				return true;
			}else{
				if(G->cb->GetMetal() < 500.0f){
					return true;
				}
				if(G->Pl->GetMetalIncome() < G->cb->GetMetalUsage()*(1-x)){
					return true;
				}
				return false;
			}
		}
		return false;
	}
Esempio n. 30
0
	string CUBuild::GetSCOUT(){
		NLOG("CUBuild::GetSCOUT");

		const vector<CommandDescription>* di = G->cb->GetUnitCommands(uid);

		if(di == 0) return string("");

		list<string> possibles;

		for(vector<CommandDescription>::const_iterator is = di->begin(); is != di->end();++is){
			if(is->id<0){

				CUnitTypeData* p =G->UnitDefLoader->GetUnitTypeDataByName(is->name);


				//if(Useless(ud)) continue;
				if((p->GetUnitDef()->speed > G->info->scout_speed)&&(p->GetUnitDef()->movedata != 0)&&(p->GetUnitDef()->canfly == false)&&(p->GetUnitDef()->transportCapacity == 0)&&(p->GetUnitDef()->isCommander == false)&&(p->GetUnitDef()->builder == false))  possibles.push_back(p->GetName());
				if((p->GetUnitDef()->weapons.empty() == true)&&(p->GetUnitDef()->canfly == true)&&(p->GetUnitDef()->transportCapacity == 0)&&(p->GetUnitDef()->isCommander == false)&&(p->GetUnitDef()->builder == false))  possibles.push_back(p->GetName());
				if((p->GetUnitDef()->weapons.empty()==true)&&(p->GetUnitDef()->canResurrect == false)&&(p->GetUnitDef()->canCapture == false)&&(p->GetUnitDef()->builder == false)&& ((p->GetUnitDef()->canfly==true)||(p->GetUnitDef()->movedata != 0)) &&((p->GetUnitDef()->radarRadius > 10)||(p->GetUnitDef()->sonarRadius > 10)))  possibles.push_back(p->GetName());
			}
		}
		if(possibles.empty() == false) return possibles.front();
		return string("");
	}