Increase chance of damage when traversing long links.

This commit is contained in:
Tim Young 2018-03-07 13:51:29 -06:00
parent 2713d6156b
commit d72ccee22f
2 changed files with 53 additions and 8 deletions

View File

@ -1830,6 +1830,10 @@ namespace EduNetworkBuilder
{ {
return Math.Sqrt(Math.Pow((start.X - dest.X),2) + Math.Pow((start.Y - dest.Y),2)) / 5; //use grid size... return Math.Sqrt(Math.Pow((start.X - dest.X),2) + Math.Pow((start.Y - dest.Y),2)) / 5; //use grid size...
} }
public double pixeldistance(Point start, Point dest)
{
return Math.Sqrt(Math.Pow((start.X - dest.X), 2) + Math.Pow((start.Y - dest.Y), 2)); //pixel size, not grid size
}
public double distance(NetworkDevice start, NetworkDevice dest) public double distance(NetworkDevice start, NetworkDevice dest)
{ {

View File

@ -366,6 +366,24 @@ namespace EduNetworkBuilder
} }
public void TakeDamageIfNeeded(Point location, Packet tPacket)
{
Network myNet = NB.GetNetwork();
if (myNet.DeviceIsOverDamaging(theLinkType, location))
{
tPacket.health -= 10;
//Console.WriteLine(" health=" + tPacket.health.ToString());
}
if (theLinkType == LinkType.wireless)
{
if (myNet.DeviceInTree(theLinkType, location))
{
tPacket.health -= 60;
}
}
}
/// <summary> /// <summary>
/// Have the packet traverse the network /// Have the packet traverse the network
/// </summary> /// </summary>
@ -375,22 +393,45 @@ namespace EduNetworkBuilder
NetworkDevice movingTo = null; NetworkDevice movingTo = null;
Network myNet = NB.GetNetwork(); Network myNet = NB.GetNetwork();
HostNicID target; HostNicID target;
int oldpercent = tPacket.myLinkPercent;
Point oldLocation = PositionOnLine(tPacket.myDirection, tPacket.myLinkPercent);
tPacket.IncrementDistance(); tPacket.IncrementDistance();
Point newLocation = PositionOnLine(tPacket.myDirection, tPacket.myLinkPercent); Point newLocation = PositionOnLine(tPacket.myDirection, tPacket.myLinkPercent);
if (myNet.DeviceIsOverDamaging(theLinkType, newLocation)) List<Point> PointsToCheck = new List<Point>();
PointsToCheck.Add(newLocation);
double distance = myNet.pixeldistance(oldLocation, newLocation);
if(distance > (double)myNet.itemsize / 2)
{ {
tPacket.health -= 10; //We are traveling too fast to accurately take damage. take some snapshot point along the way
//Console.WriteLine(" health=" + tPacket.health.ToString()); int count = (int)(distance / ((double)myNet.itemsize / 2));
int newpercent = tPacket.myLinkPercent;
int delta = Math.Abs(newpercent - oldpercent) / (count +1);
if (delta < 1) count = 1;
if (delta > 5) count = 5;
int start = newpercent + delta;
int end = oldpercent;
if(oldpercent - newpercent < 0)
{
start = oldpercent + delta;
end = newpercent;
}
for(int percent = start; percent < end; percent+= delta )
{
Point next = PositionOnLine(tPacket.myDirection, percent);
PointsToCheck.Add(next);
}
} }
foreach(Point one in PointsToCheck)
TakeDamageIfNeeded(one, tPacket);
if(theLinkType == LinkType.wireless) if(theLinkType == LinkType.wireless)
{ {
if(myNet.DeviceInTree(theLinkType, newLocation))
{
tPacket.health -= 60;
}
NetworkDevice sDev = myNet.GetDeviceFromID(SrcNic); NetworkDevice sDev = myNet.GetDeviceFromID(SrcNic);
NetworkDevice dDev = myNet.GetDeviceFromID(DstNic); NetworkDevice dDev = myNet.GetDeviceFromID(DstNic);
double distance = myNet.distance(sDev, dDev) * (tPacket.myLinkPercent * 0.01); distance = myNet.distance(sDev, dDev) * (tPacket.myLinkPercent * 0.01);
if(distance > NB.WirelessMaxSuccessfulLink) if(distance > NB.WirelessMaxSuccessfulLink)
{ {
//The wireless link is too far. Drop the packet //The wireless link is too far. Drop the packet