Example #1
0
void FailureWeaponMissiles(MECH * mech, int weapnum, int weaptype,
						   int section, int critical, int roll, int *modifier,
						   int *type)
{
	SetPartTempNuke(mech, section, critical, failures[Conv(mech, section,
														   critical) +
													  roll].type);
	*type = CRAZY_MISSILES;
	*modifier = failures[Conv(mech, section, critical) + roll].data;
}
Example #2
0
void FailureWeaponDud(MECH * mech, int weapnum, int weaptype, int section,
					  int critical, int roll, int *modifier, int *type)
{
	if(failures[Conv(mech, section, critical) + roll].type == FAIL_NONE) {
		SetRecyclePart(mech, section, critical, MechWeapons[weaptype].vrt);
		return;
	}
	SetPartTempNuke(mech, section, critical, failures[Conv(mech, section,
														   critical) +
													  roll].type);
	*type = WEAPON_DUD;
	if(roll == 6) {
		SetPartTempNuke(mech, section, critical, FAIL_DESTROYED);
	}
	SetRecyclePart(mech, section, critical, 30 + Number(1, 60));
}
Example #3
0
void FailureWeaponHeat(MECH * mech, int weapnum, int weaptype, int section,
					   int critical, int roll, int *modifier, int *type)
{
	*modifier =
		(int) MechWeapons[weaptype].heat * (failures[Conv(mech, section,
														  critical) +
													 roll].data / 100.0);
	*type = HEAT;
}
Example #4
0
void FailureWeaponDamage(MECH * mech, int weapnum, int weaptype,
						 int section, int critical, int roll, int *modifier,
						 int *type)
{
	*modifier =
		(int) (MechWeapons[weaptype].damage * (failures[Conv(mech, section,
															 critical) +
														roll].data / 100.0));
	*type = DAMAGE;
}
Example #5
0
void FailureWeaponJammed(MECH * mech, int weapnum, int weaptype,
						 int section, int critical, int roll, int *modifier,
						 int *type)
{
	SetPartTempNuke(mech, section, critical, failures[Conv(mech, section,
														   critical) +
													  roll].type);
	*type = WEAPON_JAMMED;
	SetRecyclePart(mech, section, critical, Number(20, 40));
}
Example #6
0
void FailureWeaponRange(MECH * mech, int weapnum, int weaptype,
						int section, int critical, int roll, int *modifier,
						int *type)
{
	*modifier =
		(int) (EGunRangeWithCheck(mech, section,
								  weaptype) * (failures[Conv(mech, section,
															 critical) +
														roll].data / 100.0));
	*type = RANGE;
}
Example #7
0
Matrix<T> *MatrixOps<T>::Conv (const Matrix<T> *const vector1, const Matrix<T> *const vector2, MATRIX_DIMENSION dimension) {

	Matrix<T> *resvec;

	if (dimension == MATRIX_DIMENSION_COL) {
		resvec = new Matrix<T> (vector1->rows * vector1->cols + vector2->rows * vector2->cols - 1, 1);
	} else {
		resvec = new Matrix<T> (1, vector1->rows * vector1->cols + vector2->rows * vector2->cols - 1);
	}

	Conv (vector1, vector2, resvec);

	return resvec;
}
Example #8
0
int main ()
{
    GetWn ();
    while (scanf ("%s%s", A, B) != EOF)
    {
        int len;

        Prepare (A, B, a, b, len);
        Conv (a, b, len);
        Transfer (a, len);
        Print (a, len);
    }
    return 0;
}
Example #9
0
void FailureWeaponSpike(MECH * mech, int weapnum, int weaptype,
						int section, int critical, int roll, int *modifier,
						int *type)
{
	SetPartTempNuke(mech, section, critical, failures[Conv(mech, section,
														   critical) +
													  roll].type);
	*type = POWER_SPIKE;
	if(roll == 6) {
		SetPartTempNuke(mech, section, critical, FAIL_DESTROYED);
		return;
	}
	SetRecyclePart(mech, section, critical, Number(20, 40));
}
Example #10
0
/**
 * Converts an arbitrary text buffer to an FString.
 * Supports all combination of ANSI/Unicode files and platforms.
 */
void FFileHelper::BufferToString( FString& Result, const uint8* Buffer, int32 Size )
{
	TArray<TCHAR>& ResultArray = Result.GetCharArray();
	ResultArray.Empty();

	if( Size >= 2 && !( Size & 1 ) && Buffer[0] == 0xff && Buffer[1] == 0xfe )
	{
		// Unicode Intel byte order. Less 1 for the FFFE header, additional 1 for null terminator.
		ResultArray.AddUninitialized( Size / 2 );
		for( int32 i = 0; i < ( Size / 2 ) - 1; i++ )
		{
			ResultArray[ i ] = CharCast<TCHAR>( (UCS2CHAR)(( uint16 )Buffer[i * 2 + 2] + ( uint16 )Buffer[i * 2 + 3] * 256) );
		}
	}
	else if( Size >= 2 && !( Size & 1 ) && Buffer[0] == 0xfe && Buffer[1] == 0xff )
	{
		// Unicode non-Intel byte order. Less 1 for the FFFE header, additional 1 for null terminator.
		ResultArray.AddUninitialized( Size / 2 );
		for( int32 i = 0; i < ( Size / 2 ) - 1; i++ )
		{
			ResultArray[ i ] = CharCast<TCHAR>( (UCS2CHAR)(( uint16 )Buffer[i * 2 + 3] + ( uint16 )Buffer[i * 2 + 2] * 256) );
		}
	}
	else
	{
		if ( Size >= 3 && Buffer[0] == 0xef && Buffer[1] == 0xbb && Buffer[2] == 0xbf )
		{
			// Skip over UTF-8 BOM if there is one
			Buffer += 3;
			Size   -= 3;
		}

		FUTF8ToTCHAR Conv((const ANSICHAR*)Buffer, Size);
		int32 Length = Conv.Length();
		ResultArray.AddUninitialized(Length + 1); // For the null terminator
		CopyAssignItems(ResultArray.GetData(), Conv.Get(), Length);
	}

	if (ResultArray.Num() == 1)
	{
		// If it's only a zero terminator then make the result actually empty
		ResultArray.Empty();
	}
	else
	{
		// Else ensure null terminator is present
		ResultArray.Last() = 0;
	}
}
Example #11
0
bool Conv(const string& str, bool* out, bool tryToCache )
{
	assert(out);
	*out = true;

	if(str == "")
		*out = false;
	if(str == "false")
		*out = false;
	if(str == "no")
		*out = false;

	int i;
	if(Conv(str, &i) && i == 0)
	{
		*out = false;
	}

	return true;
}
  /** Attempts to read the index file datafilename.obindx successively
      from the following directories:
      - the current directory
      - that in the environment variable BABEL_DATADIR or in the macro BABEL_DATADIR
      if the environment variable is not set
      - in a subdirectory of the BABEL_DATADIR directory with the version of OpenBabel as its name
      An index of type NameIndexType is then constructed. NameIndexType is defined
      in obmolecformat.h and may be a std::tr1::unordered_map (a hash_map) or std::map.
      In any case it is searched by 
      @code
      NameIndexType::iterator itr = index.find(molecule_name);
      if(itr!=index.end())
      unsigned pos_in_datafile = itr->second;
      @endcode
      pos_in_datafile is used as a parameter in seekg() to read from the datafile

      If no index is found, it is constructed from the datafile by reading all of
      it using the format pInFormat, and written to the directory containing the datafile.
      This means that this function can be used without worrying whether there is an index.
      It will be slow to execute the first time, but subsequent uses get the speed benefit
      of indexed access to the datafile. 

      The serialization and de-serialization of the NameIndexType is entirely in
      this routine and could possibly be improved. Currently re-hashing is done 
      every time the index is read.
  **/
  bool OBMoleculeFormat::ReadNameIndex(NameIndexType& index,
                                       const string& datafilename, OBFormat* pInFormat)
  {
    struct headertype
    {
      char filename[256];
      unsigned size;
    } header;

    NameIndexType::iterator itr;

    ifstream indexstream;
    OpenDatafile(indexstream, datafilename + ".obindx");
    if(!indexstream)
      {
        //Need to prepare the index
        ifstream datastream;
        string datafilepath = OpenDatafile(datastream, datafilename);
        if(!datastream)
          {
            obErrorLog.ThrowError(__FUNCTION__, 
                                  datafilename + " was not found or could not be opened",  obError);
            return false;
          }

        OBConversion Conv(&datastream,NULL);
        Conv.SetInFormat(pInFormat);
        OBMol mol;
        streampos pos;
        while(Conv.Read(&mol))
          {
            string name = mol.GetTitle();
            if(!name.empty())
              index.insert(make_pair(name, pos));
            mol.Clear();
            pos = datastream.tellg();
          }
        obErrorLog.ThrowError(__FUNCTION__, 
                              "Prepared an index for " + datafilepath, obAuditMsg);
        //Save index to file
        ofstream dofs((datafilepath + ".obindx").c_str(), ios_base::out|ios_base::binary);
        if(!dofs) return false;

        strncpy(header.filename,datafilename.c_str(), sizeof(header.filename));
        header.filename[sizeof(header.filename) - 1] = '\0';
        header.size = index.size();
        dofs.write((const char*)&header, sizeof(headertype));
	
        for(itr=index.begin();itr!=index.end();++itr)
          {
            //#chars; chars;  ofset(4bytes).
            const char n = itr->first.size();
            dofs.put(n);
            dofs.write(itr->first.c_str(),n);
            dofs.write((const char*)&itr->second,sizeof(unsigned));
          }			
      }
    else
      {
        //Read index data from file and put into hash_map
        indexstream.read((char*)&header,sizeof(headertype));
        itr=index.begin(); // for hint
        for(unsigned int i=0;i<header.size;++i)
          {
            char len;
            indexstream.get(len);
            string title(len, 0);
            unsigned pos;
            indexstream.read(&title[0],len);
            indexstream.read((char*)&pos,sizeof(unsigned));
            index.insert(itr, make_pair(title,pos));
          }
      }
    return true;
  }
Example #13
0
bool MovingCamera::Update(float elapsedTime)
{
	#pragma region WASD EQ

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
	{
		IncrementPosition(GetForward() * moveSpeed * elapsedTime);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
	{
		IncrementPosition(-GetForward() * moveSpeed * elapsedTime);
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
	{
		IncrementPosition(GetSideways() * moveSpeed * elapsedTime);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
	{
		IncrementPosition(-GetSideways() * moveSpeed * elapsedTime);
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::E))
	{
		IncrementPosition(GetUpward() * -moveSpeed * elapsedTime);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q))
	{
		IncrementPosition(GetUpward() * moveSpeed * elapsedTime);
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
	{
		return true;
	}

	#pragma endregion

	#pragma region Mouse

	if (Window == 0)
	{
		return false;
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
	{
        if (!pressedLastFrame)
        {
            Window->setMouseCursorVisible(true);
            pressedLastFrame = true;
            camPaused = !camPaused;
        }
	}
    else pressedLastFrame = false;

    if (camPaused) return false;

	Window->setMouseCursorVisible(false);

	Vector2i mousePos = Conv(sf::Mouse::getPosition());
	Vector2i delta = mousePos - mouseTarget;

	Vector2f rotAmount(delta.x * rotSpeed * elapsedTime, delta.y * rotSpeed * elapsedTime);

	sf::Mouse::setPosition(Conv(mouseTarget));

	AddPitch(-rotAmount.y);
	AddYaw(rotAmount.x);

	#pragma endregion

	return false;
}
//=======================================================================
//function : MergeEdges
//purpose  : auxilary
//=======================================================================
static Standard_Boolean MergeEdges(const TopTools_SequenceOfShape& SeqEdges,
                                   const TopoDS_Face& aFace,
                                   const Standard_Real Tol,
                                   TopoDS_Edge& anEdge)
{
  // make chain for union
  BRep_Builder B;
  ShapeAnalysis_Edge sae;
  TopoDS_Edge FirstE = TopoDS::Edge(SeqEdges.Value(1));
  TopoDS_Edge LastE = FirstE;
  TopoDS_Vertex VF = sae.FirstVertex(FirstE);
  TopoDS_Vertex VL = sae.LastVertex(LastE);
  TopTools_SequenceOfShape aChain;
  aChain.Append(FirstE);
  TColStd_MapOfInteger IndUsedEdges;
  IndUsedEdges.Add(1);
  Standard_Integer j;
  for(j=2; j<=SeqEdges.Length(); j++) {
    for(Standard_Integer k=2; k<=SeqEdges.Length(); k++) {
      if(IndUsedEdges.Contains(k)) continue;
      TopoDS_Edge edge = TopoDS::Edge(SeqEdges.Value(k));
      TopoDS_Vertex VF2 = sae.FirstVertex(edge);
      TopoDS_Vertex VL2 = sae.LastVertex(edge);
      if(sae.FirstVertex(edge).IsSame(VL)) {
        aChain.Append(edge);
        LastE = edge;
        VL = sae.LastVertex(LastE);
        IndUsedEdges.Add(k);
      }
      else if(sae.LastVertex(edge).IsSame(VF)) {
        aChain.Prepend(edge);
        FirstE = edge;
        VF = sae.FirstVertex(FirstE);
        IndUsedEdges.Add(k);
      }
    }
  }
  if(aChain.Length()<SeqEdges.Length()) {
    MESSAGE ("can not create correct chain...");
    return Standard_False;
  }
  // union edges in chain
  // first step: union lines and circles
  TopLoc_Location Loc;
  Standard_Real fp1,lp1,fp2,lp2;
  for(j=1; j<aChain.Length(); j++) {
    TopoDS_Edge edge1 = TopoDS::Edge(aChain.Value(j));
    Handle(Geom_Curve) c3d1 = BRep_Tool::Curve(edge1,Loc,fp1,lp1);
    if(c3d1.IsNull()) break;
    while(c3d1->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
      Handle(Geom_TrimmedCurve) tc =
        Handle(Geom_TrimmedCurve)::DownCast(c3d1);
      c3d1 = tc->BasisCurve();
    }
    TopoDS_Edge edge2 = TopoDS::Edge(aChain.Value(j+1));
    Handle(Geom_Curve) c3d2 = BRep_Tool::Curve(edge2,Loc,fp2,lp2);
    if(c3d2.IsNull()) break;
    while(c3d2->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
      Handle(Geom_TrimmedCurve) tc =
        Handle(Geom_TrimmedCurve)::DownCast(c3d2);
      c3d2 = tc->BasisCurve();
    }
    if( c3d1->IsKind(STANDARD_TYPE(Geom_Line)) && c3d2->IsKind(STANDARD_TYPE(Geom_Line)) ) {
      // union lines
      Handle(Geom_Line) L1 = Handle(Geom_Line)::DownCast(c3d1);
      Handle(Geom_Line) L2 = Handle(Geom_Line)::DownCast(c3d2);
      gp_Dir Dir1 = L1->Position().Direction();
      gp_Dir Dir2 = L2->Position().Direction();
      //if(!Dir1.IsEqual(Dir2,Precision::Angular())) { 
      //if(!Dir1.IsParallel(Dir2,Precision::Angular())) { 
      if(!Dir1.IsParallel(Dir2,Tol)) { 
        continue;
      }
      // can union lines => create new edge
      TopoDS_Vertex V1 = sae.FirstVertex(edge1);
      gp_Pnt PV1 = BRep_Tool::Pnt(V1);
      TopoDS_Vertex V2 = sae.LastVertex(edge2);
      gp_Pnt PV2 = BRep_Tool::Pnt(V2);
      gp_Vec Vec(PV1,PV2);
      Handle(Geom_Line) L = new Geom_Line(gp_Ax1(PV1,Vec));
      Standard_Real dist = PV1.Distance(PV2);
      Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(L,0.0,dist);
      TopoDS_Edge E;
      B.MakeEdge (E,tc,Precision::Confusion());
      B.Add (E,V1);  B.Add (E,V2);
      B.UpdateVertex(V1, 0., E, 0.);
      B.UpdateVertex(V2, dist, E, 0.);
      //ShapeFix_Edge sfe;
      //sfe.FixAddPCurve(E,aFace,Standard_False);
      //sfe.FixSameParameter(E);
      aChain.Remove(j);
      aChain.SetValue(j,E);
      j--;
    }
    if( c3d1->IsKind(STANDARD_TYPE(Geom_Circle)) && c3d2->IsKind(STANDARD_TYPE(Geom_Circle)) ) {
      // union circles
      Handle(Geom_Circle) C1 = Handle(Geom_Circle)::DownCast(c3d1);
      Handle(Geom_Circle) C2 = Handle(Geom_Circle)::DownCast(c3d2);
      gp_Pnt P01 = C1->Location();
      gp_Pnt P02 = C2->Location();
      if (P01.Distance(P02) > Precision::Confusion()) continue;
      // can union circles => create new edge
      TopoDS_Vertex V1 = sae.FirstVertex(edge1);
      gp_Pnt PV1 = BRep_Tool::Pnt(V1);
      TopoDS_Vertex V2 = sae.LastVertex(edge2);
      gp_Pnt PV2 = BRep_Tool::Pnt(V2);
      TopoDS_Vertex VM = sae.LastVertex(edge1);
      gp_Pnt PVM = BRep_Tool::Pnt(VM);
      GC_MakeCircle MC (PV1,PVM,PV2);
      Handle(Geom_Circle) C = MC.Value();
      TopoDS_Edge E;
      if (!MC.IsDone() || C.IsNull()) {
        // jfa for Mantis issue 0020228
        if (PV1.Distance(PV2) > Precision::Confusion()) continue;
        // closed chain
        C = C1;
        B.MakeEdge (E,C,Precision::Confusion());
        B.Add(E,V1);
        B.Add(E,V2);
      }
      else {
        gp_Pnt P0 = C->Location();
        gp_Dir D1(gp_Vec(P0,PV1));
        gp_Dir D2(gp_Vec(P0,PV2));
        Standard_Real fpar = C->XAxis().Direction().Angle(D1);
        if(fabs(fpar)>Precision::Confusion()) {
          // check orientation
          gp_Dir ND =  C->XAxis().Direction().Crossed(D1);
          if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
            fpar = -fpar;
          }
        }
        Standard_Real lpar = C->XAxis().Direction().Angle(D2);
        if(fabs(lpar)>Precision::Confusion()) {
          // check orientation
          gp_Dir ND =  C->XAxis().Direction().Crossed(D2);
          if(ND.IsOpposite(C->Axis().Direction(),Precision::Confusion())) {
            lpar = -lpar;
          }
        }
        if(lpar<fpar) lpar += 2*M_PI;
        Handle(Geom_TrimmedCurve) tc = new Geom_TrimmedCurve(C,fpar,lpar);
        B.MakeEdge (E,tc,Precision::Confusion());
        B.Add(E,V1);
        B.Add(E,V2);
        B.UpdateVertex(V1, fpar, E, 0.);
        B.UpdateVertex(V2, lpar, E, 0.);
      }
      aChain.Remove(j);
      aChain.SetValue(j,E);
      j--;
    }
  }
  if (j < aChain.Length()) {
    MESSAGE ("null curve3d in edge...");
    return Standard_False;
  }
  if (aChain.Length() > 1) {
    // second step: union edges with various curves
    // skl for bug 0020052 from Mantis: perform such unions
    // only if curves are bspline or bezier
    bool NeedUnion = true;
    for(j=1; j<=aChain.Length(); j++) {
      TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j));
      Handle(Geom_Curve) c3d = BRep_Tool::Curve(edge,Loc,fp1,lp1);
      if(c3d.IsNull()) continue;
      while(c3d->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
        Handle(Geom_TrimmedCurve) tc =
          Handle(Geom_TrimmedCurve)::DownCast(c3d);
        c3d = tc->BasisCurve();
      }
      if( ( c3d->IsKind(STANDARD_TYPE(Geom_BSplineCurve)) ||
            c3d->IsKind(STANDARD_TYPE(Geom_BezierCurve)) ) ) continue;
      NeedUnion = false;
      break;
    }
    if(NeedUnion) {
      MESSAGE ("can not make analitical union => make approximation");
      TopoDS_Wire W;
      B.MakeWire(W);
      for(j=1; j<=aChain.Length(); j++) {
        TopoDS_Edge edge = TopoDS::Edge(aChain.Value(j));
        B.Add(W,edge);
      }
      Handle(BRepAdaptor_HCompCurve) Adapt = new BRepAdaptor_HCompCurve(W);
      Approx_Curve3d Conv(Adapt,Tol,GeomAbs_C1,9,1000);
      Handle(Geom_BSplineCurve) bc = Conv.Curve();
      TopoDS_Edge E;
      B.MakeEdge (E,bc,Precision::Confusion());
      B.Add (E,VF);
      B.Add (E,VL);
      aChain.SetValue(1,E);
    }
    else {
      MESSAGE ("can not make approximation for such types of curves");
      return Standard_False;
    }
  }

  anEdge = TopoDS::Edge(aChain.Value(1));
  return Standard_True;
}
Example #15
0
int main(void) {
	
	TCCR0A = 0;
	TCCR0B = 3;//1/64
	TIMSK0 = 0;

	TCCR1A = 0;
	TCCR1B = 5;//1/1024 (16000000/1024=15625)tick/s
	TCCR1C = 0;
	TIMSK1 = 0;
		
	DDR_595_6 = 0xFC;//B11111100;
	DDR_CLK_ON;
	DDR_OE_ON;
	DDR_PNP1_ON;
	DDR_LED1_ON;
	DDR_LED2_ON;
	
	while(true)
	{
		//init/////////////////////////////////////////////////////////////////////////////////////////////////////////////
		TCNT1 = 0;//0.000064 s/tick
		for(uint16_t i=0;i<48;i++)
		{
			for(uint8_t t = 0;t<6;t++)
			{
				buff[i*8+t] = pgm_read_byte_near(data+i*6+t);
			}
			Conv(buff+i*8);
		}
		//part1///////////////////////////////////////////////////////////////////////////////////////////////////////////
		while(TCNT1<100);//0.0064s
		for(uint8_t m = 0;m<10;m++)
		{
			for(uint16_t i=0;i<48;i++)
			{
				TCNT0 = 0;
				SendLine(buff+(i<<3));
				while(TCNT0<187);
				PORT_PNP1_ON;//PNP on H
				PORT_OE_OFF;//OE on L
				while(TCNT0<230);
				PORT_LED2_ON;//PNP on H
				while(TCNT0<235);
				PORT_PNP1_OFF;//PNP disable L
				PORT_OE_ON;//OE disable H
				PORT_LED2_OFF;//PNP disable L
			}
		}
		//while(TCNT1<30000);//part2///////////////////////////////////////////////////////////////////////////////////////////

		//while(TCNT1<30000+100);//0.0064s
		for(uint8_t m = 0;m<10;m++)
		{
			for(uint16_t i=0;i<48;i++)
			{
				TCNT0 = 0;
				SendLine(buff+((47-i)<<3));
				while(TCNT0<187);
				PORT_PNP1_ON;//PNP on H
				PORT_OE_OFF;//OE on L
				while(TCNT0<230);
				PORT_LED1_ON;//PNP on H
				while(TCNT0<235);
				PORT_PNP1_OFF;//PNP disable L
				PORT_OE_ON;//OE disable H
				PORT_LED1_OFF;//PNP disable L
			}
		}
		
		//while(TCNT1<60000);
    }
}
Example #16
0
const U& ConvertIteracion<T,U,Conv>::ElementoActual() const
{
	Conversor<T,U>& conv = Conv();
	m_Actual = conv(m_ToConvert->ElementoActual());
	return m_Actual;
}