本文整理汇总了C#中CSharpAI.Float3类的典型用法代码示例。如果您正苦于以下问题:C# Float3类的具体用法?C# Float3怎么用?C# Float3使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Float3类属于CSharpAI命名空间,在下文中一共展示了Float3类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetNearestReclaim
public static Float3 GetNearestReclaim(Float3 mypos, int constructorid)
{
if( CSAI.GetInstance().aicallback.GetCurrentFrame() == 0 )// check ticks first, beacuse metal shows as zero at start
{
return null;
}
LogFile logfile = LogFile.GetInstance();
IAICallback aicallback = CSAI.GetInstance().aicallback;
IUnitDef unitdef = UnitController.GetInstance().UnitDefByDeployedId[ constructorid ];
if (!new UnitDefHelp(aicallback).IsMobile(unitdef))
{
return null;
}
//Float3 mypos = aicallback.GetUnitPos( constructorid );
MovementMaps movementmaps = MovementMaps.GetInstance();
int currentarea = movementmaps.GetArea( unitdef, mypos );
//double nearestreclaimdistancesquared = 1000000;
//Float3 nearestreclaimpos = null;
double bestmetaldistanceratio = 0;
int bestreclaimid = 0;
int metalspace = (int)( aicallback.GetMetalStorage() - aicallback.GetMetal() );
logfile.WriteLine( "available space in metal storage: " + metalspace );
int[] nearbyfeatures = aicallback.GetFeatures( mypos, maxreclaimradius );
bool reclaimfound = false;
foreach( int feature in nearbyfeatures )
{
IFeatureDef featuredef = aicallback.GetFeatureDef( feature );
if( featuredef.metal > 0 && featuredef.metal <= metalspace )
{
Float3 thisfeaturepos = aicallback.GetFeaturePos( feature );
double thisdistance = Math.Sqrt( Float3Helper.GetSquaredDistance( thisfeaturepos, mypos ) );
double thismetaldistanceratio = featuredef.metal / thisdistance;
if( thismetaldistanceratio > bestmetaldistanceratio && movementmaps.GetArea( unitdef, thisfeaturepos ) == currentarea )
{
logfile.WriteLine( "Potential reclaim, distance = " + thisdistance + " metal = " + featuredef.metal + " ratio = " + thismetaldistanceratio );
bestmetaldistanceratio = thismetaldistanceratio;
bestreclaimid = feature;
// nearestreclaimpo
reclaimfound = true;
}
}
}
if( reclaimfound && ( bestmetaldistanceratio > ( 1.0 / ( 100 * reclaimradiusperonehundredmetal ) ) ) )
{
Float3 reclaimpos = aicallback.GetFeaturePos( bestreclaimid );
logfile.WriteLine( "Reclaim found, pos " + reclaimpos.ToString() );
if( CSAI.GetInstance().DebugOn )
{
aicallback.DrawUnit( "ARMMEX", reclaimpos, 0.0f, 200, aicallback.GetMyAllyTeam(), true, true);
}
return reclaimpos;
//aicallback.GiveOrder( constructorid, new Command( Command.CMD_RECLAIM,
// new double[]{ reclaimpos.x, reclaimpos.y, reclaimpos.z, 10 } ) );
}
else
{
//logfile.WriteLine( "No reclaim within parameters" );
return null;
}
}
开发者ID:hughperkins,项目名称:SpringRTS-CSharpAI,代码行数:60,代码来源:ReclaimHelper.cs
示例2: Float3
public static Float3 operator *( double multiplier, Float3 a )
{
Float3 result = new Float3();
result.x = a.x * multiplier;
result.y = a.y * multiplier;
result.z = a.z * multiplier;
return result;
}
开发者ID:achoum,项目名称:spring,代码行数:8,代码来源:Float3.cs
示例3: Float3
public static Float3 operator-( Float3 a, Float3 b )
{
Float3 result = new Float3();
result.x = a.x - b.x;
result.y = a.y - b.y;
result.z = a.z - b.z;
return result;
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:8,代码来源:Float3.cs
示例4: csai_UnitDamagedEvent
// cheap hack to respond to enemy shooting us
void csai_UnitDamagedEvent(int damaged, int attacker, float damage, Float3 dir)
{
/*
if (!EnemyUnitDefByDeployedId.ContainsKey(attacker))
{
EnemyUnitDefByDeployedId.Add(attacker, aicallback.GetUnitDef(attacker));
}
*/
//if (!EnemyStaticPosByDeployedId.ContainsKey(attacker))
//{
Float3 enemypos = aicallback.GetUnitPos(attacker);
if (enemypos != null &&
Float3Helper.GetSquaredDistance(enemypos, new Float3(0, 0, 0)) > 10 * 10)
{
logfile.WriteLine("unitdamaged, attacker " + attacker + " pos " + enemypos);
if (!EnemyStaticPosByDeployedId.ContainsKey(attacker))
{
EnemyStaticPosByDeployedId.Add(attacker, enemypos);
}
else
{
EnemyStaticPosByDeployedId[attacker] = enemypos;
}
if (NewStaticEnemyAddedEvent != null)
{
NewStaticEnemyAddedEvent(attacker, enemypos, null);
}
}
else // else we guess...
{
if (FriendlyUnitPositionObserver.GetInstance().PosById.ContainsKey(damaged))
{
Float3 ourunitpos = FriendlyUnitPositionObserver.GetInstance().PosById[damaged];
if (ourunitpos != null)
{
Float3 guessvectortotarget = dir * 300.0;
logfile.WriteLine("vectortotarget guess: " + guessvectortotarget.ToString());
Float3 possiblepos = ourunitpos + guessvectortotarget;
if (!EnemyStaticPosByDeployedId.ContainsKey(attacker))
{
EnemyStaticPosByDeployedId.Add(attacker, possiblepos);
}
else
{
EnemyStaticPosByDeployedId[attacker] = possiblepos;
}
if (NewStaticEnemyAddedEvent != null)
{
NewStaticEnemyAddedEvent(attacker, possiblepos, null);
}
logfile.WriteLine("unitdamaged, attacker " + attacker + " our unit pos " + ourunitpos + " dir " + dir.ToString() + " guess: " + possiblepos.ToString());
}
}
}
//}
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:59,代码来源:EnemyController.cs
示例5: DrawCircle
public static void DrawCircle( Float3 pos, double radius )
{
IAICallback aicallback = CSAI.GetInstance().aicallback;
Float3 lastpos = null;
for( int angle = 0; angle <= 360; angle += 10 )
{
int x = (int)( (double)radius * Math.Cos ( (double)angle * Math.PI / 180 ) );
int y = (int)( (double)radius * Math.Sin ( (double)angle * Math.PI / 180 ) );
Float3 thispos = new Float3( x, 0, y ) + pos;
if( lastpos != null )
{
aicallback.CreateLineFigure( thispos,lastpos,10,false,200,0);
}
lastpos = thispos;
}
}
开发者ID:hughperkins,项目名称:SpringRTS-CSharpAI,代码行数:16,代码来源:DrawingUtils.cs
示例6: Regroup
void Regroup( Float3 regouppos )
{
// logfile.WriteLine( "AttackPackCoordinator regrouping to " + regouppos.ToString() );
// if( debugon )
// {
// aicallback.SendTextMsg( "AttackPackCoordinator regrouping to " + regouppos.ToString(), 0 );
// }
MoveTo( regouppos );
}
开发者ID:achoum,项目名称:spring,代码行数:9,代码来源:AttackPackCoordinatorUseGroup.cs
示例7: GetClosestUnits
UnitInfo[] GetClosestUnits( Hashtable UnitDefListByDeployedId, Float3 targetpos, int numclosestunits )
{
UnitInfo[] closestunits = new UnitInfo[ numclosestunits ];
double worsttopfivesquareddistance = 0; // got to get better than this to enter the list
int numclosestunitsfound = 0;
foreach( DictionaryEntry de in UnitDefListByDeployedId )
{
int deployedid = (int)de.Key;
IUnitDef unitdef = de.Value as IUnitDef;
Float3 unitpos = aicallback.GetUnitPos( deployedid );
double unitsquareddistance = Float3Helper.GetSquaredDistance( unitpos, targetpos );
if( numclosestunitsfound < numclosestunits )
{
UnitInfo unitinfo = new UnitInfo( deployedid, unitpos, unitdef, unitsquareddistance );
InsertIntoArray( closestunits, unitinfo, numclosestunitsfound );
numclosestunitsfound++;
worsttopfivesquareddistance = closestunits[ numclosestunitsfound - 1 ].squareddistance;
}
else if( unitsquareddistance < worsttopfivesquareddistance )
{
UnitInfo unitinfo = new UnitInfo( deployedid, unitpos, unitdef, unitsquareddistance );
InsertIntoArray( closestunits, unitinfo, numclosestunits );
worsttopfivesquareddistance = closestunits[ numclosestunits - 1 ].squareddistance;
}
}
return closestunits;
}
开发者ID:achoum,项目名称:spring,代码行数:27,代码来源:AttackPackCoordinatorUseGroup.cs
示例8: GetRandomDestination
Float3 GetRandomDestination()
{
Float3 destination = new Float3();
destination.x = random.Next(0, aicallback.GetMapWidth() * MovementMaps.SQUARE_SIZE );
destination.z = random.Next( 0, aicallback.GetMapHeight() * MovementMaps.SQUARE_SIZE );
destination.y = aicallback.GetElevation( destination.x, destination.y );
return destination;
}
开发者ID:achoum,项目名称:spring,代码行数:8,代码来源:SpreadSearchPackCoordinator.cs
示例9: EnemyDamaged
//called when an enemy inside los or radar is damaged
public void EnemyDamaged(int damaged,int attacker,float damage, Float3 dir)
{
}
开发者ID:hughperkins,项目名称:SpringRTS-CSharpAI,代码行数:4,代码来源:csai.cs
示例10: ExploreWith
void ExploreWith( int unitid )
{
Float3 destination = new Float3();
// if( PriorityTargets.Count > 0 )
// {
// destination = PriorityTargets.Dequeue() as Float3;
// logfile.WriteLine( "dequeued next destination: " + destination.ToString() );
// }
// else
// {
destination.x = random.Next(0, aicallback.GetMapWidth() * MovementMaps.SQUARE_SIZE );
destination.z = random.Next( 0, aicallback.GetMapHeight() * MovementMaps.SQUARE_SIZE );
destination.y = aicallback.GetElevation( destination.x, destination.y );
logfile.WriteLine( "mapwidth: " + aicallback.GetMapWidth() + " squaresize: " + MovementMaps.SQUARE_SIZE );
logfile.WriteLine( "ScoutController sending scout " + unitid + " to " + destination.ToString() );
// }
//aicallback.GiveOrder( unitid, new Command( Command.CMD_MOVE, destination.ToDoubleArray() ) );
GiveOrderWrapper.GetInstance().MoveTo(unitid, destination);
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:19,代码来源:ScoutControllerRaider.cs
示例11: BuildUnit
public void BuildUnit(int builderid, string targetunitname, Float3 pos)
{
int targetunittypeid = BuildTable.GetInstance().UnitDefByName[targetunitname.ToLower()].id;
GiveOrder( new BuildCommand( builderid, targetunittypeid, pos ) );
}
开发者ID:hughperkins,项目名称:SpringRTS-CSharpAI,代码行数:5,代码来源:GiveOrderWrapper.cs
示例12: MetalSpot
public MetalSpot( int amount, Float3 pos, bool isoccupied )
{
Amount = amount;
IsOccupied = isoccupied;
Pos = pos;
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:6,代码来源:Metal.cs
示例13: GetNearestMetalSpot
public Float3 GetNearestMetalSpot( Float3 mypos )
{
if( !isMetalMap )
{
double closestdistancesquared = 1000000000000;
Float3 bestpos = null;
MetalSpot bestspot = null;
foreach( MetalSpot metalspot in MetalSpots )
{
if( !MetalSpotsUsed.Contains( metalspot ) )
{
if( bestpos == null )
{
bestpos = metalspot.Pos;
}
double thisdistancesquared = Float3Helper.GetSquaredDistance( mypos, metalspot.Pos );
//logfile.WriteLine( "thisdistancesquared = " + thisdistancesquared + " closestdistancesquared= " + closestdistancesquared );
if( thisdistancesquared < closestdistancesquared )
{
closestdistancesquared = thisdistancesquared;
bestpos = metalspot.Pos;
bestspot = metalspot;
}
}
}
return bestspot.Pos;
}
else
{
return mypos; // if metal map just return passed-in pos
}
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:32,代码来源:Metal.cs
示例14: Reclaim
public void Reclaim(int unitid, Float3 pos, double radius)
{
GiveOrder(new ReclaimCommand(unitid, pos, radius));
}
开发者ID:hughperkins,项目名称:SpringRTS-CSharpAI,代码行数:4,代码来源:GiveOrderWrapper.cs
示例15: Attack
public void Attack(int unitid, Float3 pos)
{
GiveOrder( new AttackCommand( unitid, new PositionTarget( pos ) ) );
}
开发者ID:hughperkins,项目名称:SpringRTS-CSharpAI,代码行数:4,代码来源:GiveOrderWrapper.cs
示例16: LoadCache
// loads cache file
// returns true if cache loaded ok, otherwise false if not found, out-of-date, etc
// we check the version and return false if out-of-date
bool LoadCache()
{
string MapName = aicallback.GetMapName();
string cachefilepath = Path.Combine( csai.CacheDirectoryPath, MapName + "_metal.xml" );
if( !File.Exists( cachefilepath ) )
{
logfile.WriteLine( "cache file doesnt exist -> building" );
return false;
}
XmlDocument cachedom = XmlHelper.OpenDom( cachefilepath );
XmlElement metadata = cachedom.SelectSingleNode( "/root/metadata" ) as XmlElement;
string cachemetalclassversion = metadata.GetAttribute( "version" );
if( cachemetalclassversion != MetalClassVersion )
{
logfile.WriteLine( "cache file out of date ( " + cachemetalclassversion + " vs " + MetalClassVersion + " ) -> rebuilding" );
return false;
}
logfile.WriteLine( cachedom.InnerXml );
isMetalMap = Convert.ToBoolean( metadata.GetAttribute( "ismetalmap" ) );
if( isMetalMap )
{
logfile.WriteLine( "metal map" );
return true;
}
XmlElement metalspots = cachedom.SelectSingleNode( "/root/metalspots" ) as XmlElement;
ArrayList metalspotsal = new ArrayList();
foreach( XmlElement metalspot in metalspots.SelectNodes( "metalspot" ) )
{
int amount = Convert.ToInt32( metalspot.GetAttribute("amount") );
Float3 pos = new Float3();
Float3Helper.WriteXmlElementToFloat3( metalspot, pos );
//pos.LoadCsv( metalspot.GetAttribute("pos") );
MetalSpot newmetalspot = new MetalSpot( amount, pos );
metalspotsal.Add( newmetalspot );
// logfile.WriteLine( "metalspot xml: " + metalspot.InnerXml );
logfile.WriteLine( "metalspot: " + newmetalspot.ToString() );
}
MetalSpots = (MetalSpot[])metalspotsal.ToArray( typeof( MetalSpot ) );
logfile.WriteLine( "cache file loaded" );
return true;
}
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:52,代码来源:Metal.cs
示例17: UnitInCreation
public UnitInCreation(IUnitRequester requester, IUnitDef unitdef, Float3 pos)
{
this.unitrequester = requester;
this.unitdef = unitdef;
this.pos = pos;
}
开发者ID:hughperkins,项目名称:SpringRTS-CSharpAI,代码行数:6,代码来源:Builder.cs
示例18: SearchMetalSpots
//.........这里部分代码省略.........
// IUnitDef biggestmex = BuildTable.GetInstance().GetBiggestMexUnit();
// logfile.WriteLine( "biggestmex is " + biggestmex.name + " " + biggestmex.humanName );
for (int spotindex = 0; spotindex < MaxSpots && !Stopme; spotindex++)
{
logfile.WriteLine( "spotindex: " + spotindex );
int bestspotx = 0, bestspoty = 0;
int actualmetalatbestspot = 0; // use to try to put extractors over spot itself
//finds the best spot on the map and gets its coords
int BestNormalizedAvailableSpotAmount = 0;
for (int y = 0; y < mapheight; y++)
{
for (int x = 0; x < mapwidth; x++)
{
if( NormalizedSpotAvailableMetal[ x, y ] > BestNormalizedAvailableSpotAmount ||
( NormalizedSpotAvailableMetal[ x, y ] == BestNormalizedAvailableSpotAmount &&
metalremaining[ x, y ] > actualmetalatbestspot ) )
{
BestNormalizedAvailableSpotAmount = NormalizedSpotAvailableMetal[ x, y ];
bestspotx = x;
bestspoty = y;
actualmetalatbestspot = metalremaining[ x, y ];
}
}
}
logfile.WriteLine( "BestNormalizedAvailableSpotAmount: " + BestNormalizedAvailableSpotAmount );
if( BestNormalizedAvailableSpotAmount < MinMetalForSpot )
{
Stopme = true; // if the spots get too crappy it will stop running the loops to speed it all up
logfile.WriteLine( "Remaining spots too small; stopping search" );
}
if( !Stopme )
{
Float3 pos = new Float3();
pos.x = bestspotx * 2 * MovementMaps.SQUARE_SIZE;
pos.z = bestspoty * 2 * MovementMaps.SQUARE_SIZE;
pos.y = aicallback.GetElevation( pos.x, pos.z );
//pos = Map.PosToFinalBuildPos( pos, biggestmex );
logfile.WriteLine( "Metal spot: " + pos + " " + BestNormalizedAvailableSpotAmount );
MetalSpot thismetalspot = new MetalSpot( (int)( ( BestNormalizedAvailableSpotAmount * mapmaxmetal * maxmetalspotamount ) / 255 ), pos );
// if (aicallback.CanBuildAt(biggestmex, pos) )
// {
// pos = Map.PosToBuildMapPos( pos, biggestmex );
// logfile.WriteLine( "Metal spot: " + pos + " " + BestNormalizedAvailableSpotAmount );
// if(pos.z >= 2 && pos.x >= 2 && pos.x < mapwidth -2 && pos.z < mapheight -2)
// {
// if(CanBuildAt(pos.x, pos.z, biggestmex.xsize, biggestmex.ysize))
// {
metalspotsal.Add( thismetalspot );
SpotsFound++;
//if(pos.y >= 0)
//{
// SetBuildMap(pos.x-2, pos.z-2, biggestmex.xsize+4, biggestmex.ysize+4, 1);
//}
//else
//{
//SetBuildMap(pos.x-2, pos.z-2, biggestmex.xsize+4, biggestmex.ysize+4, 5);
//}
// }
// }
// }
开发者ID:genxinzou,项目名称:svn-spring-archive,代码行数:67,代码来源:Metal.cs
示例19: ChooseAttackPoint
// this is going to have to interact with all sorts of stuff in the future
// for now keep it simple
// for now we look for nearby buildings, then nearby enemy units with low speed, then anything
public Float3 ChooseAttackPoint( Float3 ourpos )
{
bool gotbuilding = false;
bool gotknownunit = false;
double BestSquaredDistance = 100000000000;
int bestid = 0;
IUnitDef defforbestid = null;
Float3 posforbestid = null;
// logfile.WriteLine( "EnemySelector: checking mobile... " );
foreach( DictionaryEntry de in enemycontroller.EnemyUnitDefByDeployedId )
{
int thisenemyid = (int)de.Key;
IUnitDef unitdef = de.Value as IUnitDef;
Float3 enemypos = aicallback.GetUnitPos( thisenemyid );
// logfile.WriteLine( "Found building " +
double thissquareddistance = Float3Helper.GetSquaredDistance( ourpos, enemypos );
// logfile.WriteLine( "EnemySelector: Potential enemy at " + enemypos.ToString() + " squareddistance: " + thissquareddistance );
if( unitdef != null )
{
// logfile.WriteLine( "unitdef not null " + unitdef.humanName + " ismobile: " + unitdefhelp.IsMobile( unitdef ).ToString() );
// logfile.WriteLine( "gotbuilding = " + gotbuilding.ToString() );
if( gotbuilding )
{
if( !unitdefhelp.IsMobile( unitdef ) )
{
if( thissquareddistance < BestSquaredDistance )
{
// logfile.WriteLine( "best building so far" );
bestid = thisenemyid;
gotbuilding = true;
gotknownunit = true;
posforbestid = enemypos;
defforbestid = unitdef;
BestSquaredDistance = thissquareddistance;
}
}
}
else
{
if( unitdef.speed < maxenemyspeed ) // if we already have building we dont care
{
if( thissquareddistance < BestSquaredDistance )
{
// logfile.WriteLine( "best known so far" );
bestid = thisenemyid;
gotknownunit = true;
posforbestid = enemypos;
defforbestid = unitdef;
BestSquaredDistance = thissquareddistance;
}
}
}
}
else // if unitdef unknown
{
// logfile.WriteLine( "gotknownunit = " + gotknownunit.ToString() );
if( !gotknownunit ) // otherwise just ignore unknown units
{
if( thissquareddistance < BestSquaredDistance )
{
// logfile.WriteLine( "best unknown so far" );
bestid = thisenemyid;
posforbestid = enemypos;
defforbestid = unitdef;
BestSquaredDistance = thissquareddistance;
}
}
}
}
foreach( DictionaryEntry de in enemycontroller.EnemyStaticPosByDeployedId )
{
// logfile.WriteLine( "EnemySelector: checking static... " );
int thisenemyid = (int)de.Key;
Float3 enemypos = de.Value as Float3;
double thissquareddistance = Float3Helper.GetSquaredDistance( ourpos, enemypos );
// logfile.WriteLine( "EnemySelector: Potential enemy at " + enemypos.ToString() + " squareddistance: " + thissquareddistance );
if( thissquareddistance < BestSquaredDistance )
{
// logfile.WriteLine( "EnemySelector: best distance so far" );
bestid = thisenemyid;
gotbuilding = true;
gotknownunit = true;
posforbestid = enemypos;
//defforbestid = unitdef;
}
}
//if( enemycontroller.EnemyStaticPosByDeployedId.Contains( bestid ) )
// {
// enemycontroller.EnemyStaticPosByDeployedId.Remove( bestid );
// }
return posforbestid;
}
开发者ID:hughperkins,项目名称:SpringRTS-CSharpAI,代码行数:99,代码来源:EnemySelector.cs
示例20: SetTarget
public void SetTarget( Float3 target )
{
//this.targetid = targetid;
//Activate();
}
开发者ID:achoum,项目名称:spring,代码行数:5,代码来源:GuardPackCoordinator.cs
注:本文中的CSharpAI.Float3类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论