Пример #1
0
void createBonus()
{
	if(int(game.bonuses.size()) >= game.settings.maxBonuses)
		return;
		
	Bonus* bonus = game.bonuses.newObject();
	if(!bonus)
		return;
	
	for(std::size_t i = 0; i < 50000; ++i)
	{
		int ix = game.rand(C[BonusSpawnRectW]);
		int iy = game.rand(C[BonusSpawnRectH]);
		
		if(H[HBonusSpawnRect])
		{
			ix += C[BonusSpawnRectX];
			iy += C[BonusSpawnRectY];
		}
		
		if(checkBonusSpawnPosition(ix, iy))
		{
			int frame;
			
			if(H[HBonusOnlyHealth])
				frame = 1;
			else if(H[HBonusOnlyWeapon])
				frame = 0;
			else
				frame = game.rand(2);
			
			bonus->x = itof(ix);
			bonus->y = itof(iy);
			bonus->velY = 0;
			bonus->frame = frame;
			bonus->timer = game.rand(game.bonusRandTimer[frame][1]) + game.bonusRandTimer[frame][0];
			
			if(frame == 0)
			{
				do
				{
					bonus->weapon = game.rand(40); // TODO: Unhardcode
				}
				while(game.settings.weapTable[bonus->weapon] == 2);
			}
			
			game.sobjectTypes[7].create(ix, iy, 0);
			return;
		}
	} // 234F
	
	game.bonuses.free(bonus);
}
Пример #2
0
void AbstractFrame::load(QXmlStreamReader* e)
{
#if 0
    assert (e);
    int pointcount = 1;
    std::string udw = "False";
    dewell = 0;
    repeats = 1;
    slog()->debugStream() << "Loading static frame : "<< this;
    pointcount= e->attributes().value("Points").toString().toInt();
    udw = e->attributes().value("Use_Dewell").toString().toStdString();
    dewell = e->attributes().value("Dewell").toString().toInt();
    repeats = e->attributes().value("Repeats").toString().toInt();
    useDewell = (udw=="True") ? true : false;
    slog()->debugStream() << "Dewell : " << dewell;
    slog()->debugStream() << "Repeats : " << repeats;
    slog()->debugStream() << "Use Dewell : " << (useDewell ? "True" : "False");
    data_->clear();
    data_->reserve(pointcount);
    slog()->debugStream() << "Points : " << pointcount;
    e->readNextStartElement();
    if (e->name() == "PointList") {
        slog()->debugStream()<<"Found a PointList";
        e->readNext();
        QByteArray ba;
        ba.reserve(16 * pointcount);
        ba = QByteArray::fromBase64(e->text().toString().toUtf8());
        const char *b = ba.constData();
        // ba now contains the raw binary frame
        // 16 bytes per point
        slog()->debugStream()<<"ByteArray contains : " << ba.size() << " Bytes";
        for (int i=0; i < ba.size()/16; i++) {
            Point p;
            const int a = 16 * i;
            p.setX(itof (*(unsigned int*)(b+a)));
            p.setY(itof (*(unsigned int*)(b+a+4)));
            p.setZ(itof (*(unsigned int*)(b+a+8)));
            p.r = b[a+12];
            p.g = b[a+13];
            p.b = b[a+14];
            p.blanked = b[a+15];
            data_->addPoint(p);
        }
    } else {
        slog()->errorStream()<<"Failed to find valid point data";
    }
#endif
}
Пример #3
0
void drain(void)
{
    int sp_drain = random(5) + 1;

    if(shining)
    {
        if(ENV(TO) != user)
        {
            tell_object(ENV(TO),"The stone stops shining.\n");
            darken();
            return;
        }

        if(sp_drain > user->query_spell_points())
        {
            tell_object(user,"The stone grows dark as you have no more "+
                        "power to channel into it.\n");
            darken();
            return;
        }

        tell_object(user,"You channel some power into the stone to keep "+
                    "it shining.\n");
        user->reduce_spell_points(sp_drain);
        set_alarm(300.0 + itof(random(120)),0.0,"drain");
    }
}
Пример #4
0
void depart(void)
{
  if(!boatman)
    {
      boatman = make(NMONSTER+"boatman");
    }

  switch(location)
    {
    case 1: tell_room(TO,"The boatman jumps on board and sets sail for "+
                      "Newbie Island.\n");
            tell_room(larstown,"The Boatman jumps into his sailing boat "+
                      "and sets sail for Newbie Island.\n");
      destination = island;
      break;
    case 2: tell_room(TO,"The boatman climbs on board and sets sail for "+
                      "Larstown.\n");
            tell_room(island,"The Boatman pushes the sailing boat out into "+
                      "the shallows, jumps on board, and sets sail for "+
                      "Larstown.\n");
      destination = larstown;
      break;
  }
  transfer(boatman,TO);
  boat_object->destroy();
  set_at_sea();
  set_alarm(5.0 + itof(random(5)),0.0,"journey");
  set_alarm(40.0,0.0,"arrive");
}
Пример #5
0
int do_light(string str)
{
    int sp_cost = 10 + random(10);

    if(str == "stone" && TP->QS("attune") > 20 && ENV(TO) == TP)
    {
        if(shining)
        {
            W("The stone is already shining!\n");
            return 1;
        }

        if(TP->query_spell_points() >= sp_cost)
        {
            W("You channel some power into the stone and make it shine "+
              "with a warm light.\n");
            S(TP->QN + " concentrates on a small stone and suddenly it "+
              "starts shining with a warm light.\n");
            TP->reduce_spell_points(sp_cost);
            user = TP;
            light();
            set_alarm(300.0 + itof(random(120)),0.0,"drain");
        }
        else
        {
            W("You don't have enough power to light the stone at the "+
              "moment.\n");
            S(TP->QN + " concentrates on a small stone but looks "+
              "disappointed.\n");
            return 1;
        }
    }
    // No mistake here. Don't want hints to people with attune < 20,
    // and don't want to mess up other light commands
}
Пример #6
0
void journey(void)
{
  if(!location)
  {
    tell_room(TO,journey_messages[random(sizeof(journey_messages))]);
    set_alarm(5.0 + itof(random(5)),0.0,"journey");
  }
}
Пример #7
0
// reads register(s) from controller at address to len
// abel_comm_object_read(obj,"n7:90",4)
// will return a ABELDataReturn 
//   with type 0, len 4
//   with num of values at n7:90,n7:91,n7:92,n7:93
ABELDataReturn* abel_comm_object_read(ABELCommObject* obj,char* addr,int len)
{
    ABELDataReturn* out;
    out = abel_data_return_new();
	int type;
	type = abel_comm_object_get_device_type(obj);
	int x,sts,extsts;
	unsigned int temp1, temp2;
	struct _data data;
    out->len=len;
    obj->comm1.tns = obj->comm1.tns + 4;
	data=protread3(obj->comm1,addr,len,type,FALSE);
    if (data.len == -1)
		{
		sts = data.data[0];
		extsts = data.data[1];
		printf ("An error occured.  The PLC STS byte is %d, the EXT STS byte is %d\n",sts,extsts);
		if (sts != 0xf0)
			printf ("Primary Error code is %s\n",errors[(sts/16)]);
		if (extsts != 0)
			printf ("Extended error code is %s\n",ext_errors[extsts]);
		close (obj->comm1.handle);
		}
	switch (data.name.section)
		{
		case 0:
			if (data.name.floatdata == TRUE)
				{
				out->type=1;
				for (x=0;x<data.len;x=x+2)
					{
					temp1 = (data.data[x]);
					temp2 = (data.data[x+1]);
					out->flt[x]=itof(temp1,temp2);
					}
				}
			if (data.name.floatdata == FALSE)
				{
				out->type=0;
				for (x=0;x<(data.len);x++)
					out->num[x]=(int)data.data[x];
				}
			break;
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		    for (x=0;x<data.len;x++)
				printf ("%02X  ",(byte)data.data[x]);
			printf ("\n");
		}	
  return out;
}
Пример #8
0
/*
 * Function name: init
 * Description:   Called when meeting an object
 */
void
init()
{
    ::init();

    if (remove_time)
    {
        set_alarm(itof(remove_time), 0.0, stop_paralyze);
    }

    add_action(stop, "", 1);
}
Пример #9
0
void tell_message(int index)
{
    if(index < sizeof(messages))
    {
        tell_object(ENV(TO),messages[index] + "\n");
        ++index;
        set_alarm(15.0 + itof(random(10)),0.0,"tell_message",index);
    }
    else
    {
        ENV(ENV(TO))->land(ENV(TO));
        destroy();
    }
}
Пример #10
0
int main()
{   
    
    int input = 127;
    printf("input is: %d\n",input);
    int s[] = {-12,0,123};
    int i = 0;
    
    for (i = 0; i < 3; i++)
    {
        float output = 0.0;
        output = itof(s[i]);
        printf("input is: %d\t",s[i]);
        printf("changed to: %f\n",output);
    }
    return 0;
}
Пример #11
0
/*
 * Function name: call_out
 * Description:   Add a call_out to the named function
 * Arguments:     func  - function to be called
 *                delay - how long to wait before calling
 *                        the function
 *                arg   - optional argument to pass to the named
 *                        function when the call_out triggers
 * Returns:       The id if the call_out
 */
varargs int
call_out(string func, mixed delay, mixed arg)
{
    float repeat;

    repeat = 0.0;
    if (intp(delay))
	delay = itof(delay);
    if (delay < 0.0)
    {
	repeat = -delay;
	delay = repeat;
    }
    /*
     * Don't pass a 0 argument if no argument were specified
     */
    if (arg)
	return set_alarm(delay, repeat, func, arg);
    return set_alarm(delay, repeat, func);
}
Пример #12
0
void DepthBuffer::binTriangles4Simd(vec4f vertices[12],uint32 count) {
	enum { kNumLanes = 4 };

	VecF32Soa transformedPos[3];
	gather4Simd(transformedPos,(VecF32*)vertices);

	VecS32 vertexX[3],vertexY[3];
	VecF32 vertexZ[3];

	for(int i = 0;i<3;i++){
		//Convert the floating point coordinates to integer screen space coordinates.
		//NB: truncate
		vertexX[i] = ftoi(transformedPos[i].x);
		vertexY[i] = ftoi(transformedPos[i].y);

		vertexZ[i] = transformedPos[i].z;
	}

	//Compute triangle area.
	VecS32 area = (vertexX[1] - vertexX[0]) * (vertexY[2] - vertexY[0]) - (vertexX[0] - vertexX[2]) * (vertexY[0] - vertexY[1]);
	VecF32 oneOverArea = VecF32(1.0f)/itof(area);

	//Setup Z for interpolation
	vertexZ[1] = (vertexZ[1] - vertexZ[0]) * oneOverArea;
	vertexZ[2] = (vertexZ[2] - vertexZ[0]) * oneOverArea;

	//Find bounding box for the screen space triangle
	VecS32 zero = VecS32(0);
	VecS32 minX = vmax( vmin(vmin(vertexX[0],vertexX[1]),vertexX[2]), zero);
	VecS32 maxX = vmin( vmax(vmax(vertexX[0],vertexX[1]),vertexX[2]), VecS32(size_.x-1) );
	VecS32 minY = vmax( vmin(vmin(vertexY[0],vertexY[1]),vertexY[2]), zero);
	VecS32 maxY = vmin( vmax(vmax(vertexY[0],vertexY[1]),vertexY[2]), VecS32(size_.y-1) );

	uint32 numLanes = std::min(count,uint32(kNumLanes));
	for(uint32 i =0;i<numLanes;++i){
		//Skip triangle if the area is zero
		if(area.lane[i] <= 0) continue;

		float oneOverW[3];
		for(int j = 0;j<3;++j){
			oneOverW[j] = transformedPos[j].w.lane[i];
		}

		// Reject the triangle if any of its verts is behind the nearclip plane
		if(oneOverW[0] == 0.0f || oneOverW[1] == 0.0f || oneOverW[2] == 0.0f) continue;

		//Convert bounding box in terms of pixels to bounding box in terms of tiles.
		int32 tileMinX = minX.lane[i]/tileSize_.x;//std::max(minX.lane[i]/tileSize_.x,0);
		int32 tileMaxX = maxX.lane[i]/tileSize_.x;//std::min(maxX.lane[i]/tileSize_.x,tileCount_.x);
		int32 tileMinY = minY.lane[i]/tileSize_.y;//std::max(minY.lane[i]/tileSize_.y,0);
		int32 tileMaxY = maxY.lane[i]/tileSize_.y;//std::min(maxY.lane[i]/tileSize_.y,tileCount_.y);

		for(;tileMinY <= tileMaxY;tileMinY++){
			auto tileIndex = tileMinX + tileMinY*tileCount_.x;
		for(auto x = tileMinX; x<= tileMaxX; x++,tileIndex++){
			auto count = tileTriangleCount_[tileIndex];
			if(count >= kMaxTrianglesPerTile) continue;
			tileTriangleCount_[tileIndex]++;

			BinnedTriangle& triangle =*( triangleBins_ + count + x*kMaxTrianglesPerTile + tileMinY*tileCount_.x*kMaxTrianglesPerTile);
			triangle.v[0].x = vertexX[0].lane[i];
			triangle.v[0].y = vertexY[0].lane[i];
			triangle.v[1].x = vertexX[1].lane[i];
			triangle.v[1].y = vertexY[1].lane[i];
			triangle.v[2].x = vertexX[2].lane[i];
			triangle.v[2].y = vertexY[2].lane[i];
			triangle.z[0] = vertexZ[0].lane[i];
			triangle.z[1] = vertexZ[1].lane[i];
			triangle.z[2] = vertexZ[2].lane[i];
		} }
	}
}
Пример #13
0
inline fixedvec itof(gvl::ivec2 v)
{
	return fixedvec(itof(v.x), itof(v.y));
}
Пример #14
0
int main (int argc, char *argv[])
{
struct _comm comm;
struct _data data;
struct plc5stat status;
	int count,x,sts,extsts,type;
	unsigned int temp1, temp2;
	count=0;
	if (argc == 3)
		count = 1;
	if (argc == 4)
		count = atoi(argv[3]);
	if ((argc < 3) || (argc > 4))
		{
		printf ("\nThis program will read a register from an Ethernet connected Allen Bradley\n");
		printf ("PLC-5.  It should also work with a Pyramid Integrator.\n\n");
		printf ("Correct Usage:\nab <plc ip addr> <plc register> {<quantity>}\n");
		printf ("ab 192.168.10.5 n7:0   - will read one integer from N7:0 on plc 192.168.10.5\n");
		printf ("ab 192.168.10.5 n7:30 4 - will read four integers from N7:30 on plc 192.168.10.5\n"); 
		printf ("\n\n");
		exit (-1);
		}

	comm=abel_attach(argv[1],FALSE);
	if (comm.error != 0)
		{
		printf ("Could not connect.  Check your address and try again.\n");
		exit (-1);
		}
	status = getstatus (comm,FALSE);
	type = PLC5;
	if (status.type == 0xde)
		type = PLC5250;
	if (status.type == 0xee)
		type = SLC;
	comm.tns = comm.tns + 4;

	data=protread3(comm,argv[2],count,type,FALSE);
	if (data.len == -1)
		{
		sts = data.data[0];
		extsts = data.data[1];
		printf ("An error occured.  The PLC STS byte is %d, the EXT STS byte is %d\n",sts,extsts);
		if (sts != 0xf0)
			printf ("Primary Error code is %s\n",errors[(sts/16)]);
		if (extsts != 0)
			printf ("Extended error code is %s\n",ext_errors[extsts]);
		close (comm.handle);
		exit (-1);
		}
	switch (data.name.section)
		{
		case 0:
			if (data.name.floatdata == TRUE)
				{
				for (x=0;x<data.len;x=x+2)
					{
					temp1 = (data.data[x]);
					temp2 = (data.data[x+1]);
					printf ("%f\n",itof(temp1,temp2));
					}
				}
			if (data.name.floatdata == FALSE)
				{
				for (x=0;x<(data.len);x++)
					printf ("%d\n",(short)data.data[x]);
				}
			break;
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
			for (x=0;x<data.len;x++)
				printf ("%02X  ",(byte)data.data[x]);
			printf ("\n");
		}	 
	close (comm.handle);
	exit (0);
}
Пример #15
0
//Rasterize 4 pixels at once
void DepthBuffer::rasterizeTile2x2(int32 x,int32 y,uint32 pass) {

	auto tileIndex = x + y*tileCount_.x;
	auto count = tileTriangleCount_[tileIndex];
	tileTriangleCount_[tileIndex] = 0;
	auto faces = triangleBins_ + x*kMaxTrianglesPerTile + y*tileCount_.x*kMaxTrianglesPerTile;
	vec2i tilePos(x*tileSize_.x,y*tileSize_.y);
	vec2i tileEnd(tilePos + tileSize_);
#ifdef ARPHEG_ARCH_X86
	enum { kNumLanes = 4 };

	//Flush denormals to zero
	_mm_setcsr( _mm_getcsr() | 0x8040 );

	VecS32 colOffset(0, 1, 0, 1);
	VecS32 rowOffset(0, 0, 1, 1);

	//Process the 4 binned triangles at a time
	VecS32 vertexX[3];
	VecS32 vertexY[3];
	VecF32  vertexZ[4];
	VecS32 tileMinXSimd(tilePos.x);
	VecS32 tileMaxXSimd(tilePos.x+tileSize_.x-2);
	VecS32 tileMinYSimd(tilePos.y);
	VecS32 tileMaxYSimd(tilePos.y+tileSize_.y-2);

	for(uint32 i = 0;i<count;i += kNumLanes){

		uint32 numSimdTris = std::min(uint32(kNumLanes),count-i);
		auto f = faces+i;
		for(uint32 ii = 0;ii< numSimdTris;++ii){
			vertexX[0].lane[ii] = f[ii].v[0].x;
			vertexY[0].lane[ii] = f[ii].v[0].y;
			vertexX[1].lane[ii] = f[ii].v[1].x;
			vertexY[1].lane[ii] = f[ii].v[1].y;
			vertexX[2].lane[ii] = f[ii].v[2].x;
			vertexY[2].lane[ii] = f[ii].v[2].y;
			vertexZ[ii] = VecF32(f[ii].z[0],f[ii].z[1],f[ii].z[2],0.0f);
		}

		// Fab(x, y) =     Ax       +       By     +      C              = 0
		// Fab(x, y) = (ya - yb)x   +   (xb - xa)y + (xa * yb - xb * ya) = 0
		// Compute A = (ya - yb) for the 3 line segments that make up each triangle
		VecS32 A0 = vertexY[1] - vertexY[2];
		VecS32 A1 = vertexY[2] - vertexY[0];
		VecS32 A2 = vertexY[0] - vertexY[1];

		// Compute B = (xb - xa) for the 3 line segments that make up each triangle
		VecS32 B0 = vertexX[2] - vertexX[1];
		VecS32 B1 = vertexX[0] - vertexX[2];
		VecS32 B2 = vertexX[1] - vertexX[0];

		// Compute C = (xa * yb - xb * ya) for the 3 line segments that make up each triangle
		VecS32 C0 = vertexX[1] * vertexY[2] - vertexX[2] * vertexY[1];
		VecS32 C1 = vertexX[2] * vertexY[0] - vertexX[0] * vertexY[2];
		VecS32 C2 = vertexX[0] * vertexY[1] - vertexX[1] * vertexY[0];

		// Use bounding box traversal strategy to determine which pixels to rasterize 
		VecS32 minX = vmax(vmin(vmin(vertexX[0], vertexX[1]), vertexX[2]), tileMinXSimd) & VecS32(~1);
		VecS32 maxX   = vmin(vmax(vmax(vertexX[0], vertexX[1]), vertexX[2]), tileMaxXSimd);

		VecS32 minY = vmax(vmin(vmin(vertexY[0], vertexY[1]), vertexY[2]), tileMinYSimd) & VecS32(~1);
		VecS32 maxY = vmin(vmax(vmax(vertexY[0], vertexY[1]), vertexY[2]), tileMaxYSimd);

		//Rasterize each triangle individually
		for(uint32 lane = 0;lane < numSimdTris;++lane){
			//Rasterize in 2x2 quads.
			VecF32 zz[3];
			zz[0] = VecF32(vertexZ[lane].lane[0]);
			zz[1] = VecF32(vertexZ[lane].lane[1]);
			zz[2] = VecF32(vertexZ[lane].lane[2]);

			VecS32 a0(A0.lane[lane]);
			VecS32 a1(A1.lane[lane]);
			VecS32 a2(A2.lane[lane]);
			VecS32 b0(B0.lane[lane]);
			VecS32 b1(B1.lane[lane]);
			VecS32 b2(B2.lane[lane]);

			int32 minx = minX.lane[lane];
			int32 maxx = maxX.lane[lane];
			int32 miny = minY.lane[lane];
			int32 maxy = maxY.lane[lane];

			VecS32 col = VecS32(minx) + colOffset;
			VecS32 row = VecS32(miny) + rowOffset;
			auto rowIdx = miny*size_.x + 2 * minx;
			VecS32 w0_row  = a0 * col + b0 * row + VecS32(C0.lane[lane]);
			VecS32 w1_row  = a1 * col + b1 * row + VecS32(C1.lane[lane]);
			VecS32 w2_row  = a2 * col + b2 * row + VecS32(C2.lane[lane]);

			//Multiply each weight by two(rasterize 2x2 quad at once).
			a0 = shiftl<1>(a0);
			a1 = shiftl<1>(a1);
			a2 = shiftl<1>(a2);
			b0 = shiftl<1>(b0);
			b1 = shiftl<1>(b1);
			b2 = shiftl<1>(b2);

			VecF32 zInc = itof(a1)*zz[1] + itof(a2)*zz[2];
	
			for(int32 y = miny;y<=maxy;y+=2,rowIdx += 2 * size_.x){
				auto w0 = w0_row;
				auto w1 = w1_row;
				auto w2 = w2_row;

				VecF32 depth = zz[0] + itof(w1)*zz[1] + itof(w2)*zz[2];
				auto idx = rowIdx;
				
				for(int32 x = minx;x<=maxx;x+=2,idx+=4){
					auto mask = w0|w1|w2;
					VecF32 previousDepth = VecF32::load(data_+idx);
					VecF32 mergedDepth = vmin(depth,previousDepth);
					previousDepth = select(mergedDepth,previousDepth,mask);
					previousDepth.store(data_+idx);
	
					w0+=a0;
					w1+=a1;
					w2+=a2;
					depth+=zInc;
				}
				w0_row += b0;
				w1_row += b1;
				w2_row += b2;
			}
		}
	}
#endif
}
/**********************************************************
Description : debug print used internally
Input       : Buffer pointer, value to convert.
Output      : None
***********************************************************/
void bl_print_internal(LOG_LEVEL level, kal_char *fmt, va_list ap)
{
   kal_int64   dval;
   kal_int32    ival;
   kal_char    *p, *sval;
   kal_char    *bp, cval;
   kal_int32    fract;
#ifdef __ADV_DBG_PRINT__
   kal_uint32 uival, uival1, uival2;
   kal_char *bp_old;
   kal_int32 i, j;
#endif /* __ADV_DBG_PRINT__ */

   bp= buf;
   *bp= 0;
   
   if((level) < debug_level)
   {
      return;
   }

   for (p= fmt; *p; p++)
   {
      if (*p != '%')
      {
         *bp++= *p;
         continue;
      }
      switch (*++p) 
      {
         case 'd':
            ival= va_arg(ap, kal_int32);
            if (ival < 0)
            {
               *bp++= '-';
               ival= -ival;
            }
            itoa (&bp, ival, 10);
            break;
         
         case 'o':
            ival= va_arg(ap, kal_int32);
            if (ival < 0)
            {
               *bp++= '-';
              ival= -ival;
            }
            *bp++= '0';
            itoa (&bp, ival, 8);
            break;
         
         case 'x':
            ival= va_arg(ap, kal_int32);
            if (ival < 0)
            {
              *bp++= '-';
              ival= -ival;
            }
            *bp++= '0';
            *bp++= 'x';
            itoa (&bp, ival, 16);
            break;

#ifdef __ADV_DBG_PRINT__
         case 'u':
            uival= va_arg(ap, unsigned int);
            *bp++= '0';
            *bp++= 'x';
            bp_old = bp;
            uival1 = uival >> 16;
            uival2 = uival & 0x0000ffff;
            itoa(&bp, uival1, 16);
            i = (unsigned int)bp - (unsigned int)bp_old;
            if (i < 4) {           
                for (j = 3; j > (3 - i); j--) {
                    bp_old[j] = bp_old[j - (3 - i) - 1];
                }          
                for (j = 0; j <= (3 - i); j++)
                    bp_old[j] = '0';
            }
            bp = bp_old + 4;
            bp_old = bp;
            itoa(&bp, uival2, 16);
            i = (unsigned int)bp - (unsigned int)bp_old;
            if (i < 4) {            
                for (j = 3; j > (3 - i); j--) {
                    bp_old[j] = bp_old[j - (3 - i) - 1];
                }            
                for (j = 0; j <= (3 - i); j++)
                    bp_old[j] = '0';
            }
            bp = bp_old + 4;
            break;
#endif /* __ADV_DBG_PRINT__ */
         
         case 'p':
            ival= va_arg(ap, kal_int32);
            *bp++= '0';
            *bp++= 'x';
            itoa (&bp, ival, 16);
            break;
         
         case 'c':
            cval= va_arg(ap, kal_int32);
            *bp++= cval;
            break;
         
         case 'f':
            dval= va_arg(ap, kal_int64);
            if (dval < 0)
            {
               *bp++= '-';
               dval= -dval;
            }
            if (dval >= 1.0)
               itoa (&bp, (kal_int32)dval, 10);
             else
               *bp++= '0';
            *bp++= '.';
            fract= (kal_int32)((dval- (kal_int64)(kal_int32)dval)*(kal_int64)(MAXFRACT));
            itof(&bp, fract);
            break;
         
         case 's':
            for (sval = va_arg(ap, kal_char *) ; *sval ; sval++ )
               *bp++= *sval;
            break;
      }
   }
   
   *bp= 0;
   
   for (bp= buf; *bp; bp++) 
   {
      PutUARTByte(*bp);
   } 
}
Пример #17
0
void SObjectType::create(Game& game, int x, int y, int ownerIdx, WormWeapon* firedBy, WObject* from)
{
	Common& common = *game.common;
	SObject& obj = *game.sobjects.newObjectReuse();

	LTRACE(rand, 0, sobj, game.rand.x);
	LTRACE(sobj, &obj - game.sobjects.arr, cxpo, x);
	LTRACE(sobj, &obj - game.sobjects.arr, cypo, y);
	
	assert(numSounds < 10);
	
	if(startSound >= 0)
		game.soundPlayer->play(game.rand(numSounds) + startSound);
		
	for(std::size_t i = 0; i < game.viewports.size(); ++i)
	{
		Viewport& v = *game.viewports[i];
		
		if(x > v.x
		&& x < v.x + v.rect.width()
		&& y > v.y
		&& y < v.y + v.rect.height())
		{
			if(itof(shake) > v.shake)
				v.shake = itof(shake);
		}
	}
	
	obj.id = id;
	obj.x = x - 8;
	obj.y = y - 8;
	obj.curFrame = 0;
	obj.animDelay = animDelay;
	
	if(flash > game.screenFlash)
	{
		game.screenFlash = flash;
	}

	Worm* owner = game.wormByIdx(ownerIdx);

	game.statsRecorder->damagePotential(owner, firedBy, damage);
		
	if(damage > 0)
	{
		for(std::size_t i = 0; i < game.worms.size(); ++i)
		{
			Worm& w = *game.worms[i];
			
			int wix = ftoi(w.pos.x);
			int wiy = ftoi(w.pos.y);
			
			if(wix < x + detectRange
			&& wix > x - detectRange
			&& wiy < y + detectRange
			&& wiy > y - detectRange)
			{
				int delta = wix - x;
				int power = detectRange - std::abs(delta);
				int powerSum = power;
				
				if(std::abs(w.vel.x) < itof(2)) // TODO: Read from EXE
				{
					if(delta > 0)
						w.vel.x += blowAway * power;
					else
						w.vel.x -= blowAway * power;
				}
				
				delta = wiy - y;
				power = detectRange - std::abs(delta);
				powerSum = (powerSum + power) / 2;
				
				if(std::abs(w.vel.y) < itof(2)) // TODO: Read from EXE
				{
					if(delta > 0)
						w.vel.y += blowAway * power;
					else
						w.vel.y -= blowAway * power;
				}
				
				int z = damage * powerSum;
				if(detectRange)
					z /= detectRange;

				if (from && !from->hasHit)
				{
					game.statsRecorder->hit(owner, firedBy, &w);
					from->hasHit = true;
				}
					
				if(w.health > 0)
				{
					game.doDamage(w, z, ownerIdx);
					game.statsRecorder->damageDealt(owner, firedBy, &w, z, false);
						
					int bloodAmount = game.settings->blood * powerSum / 100;
					
					if(bloodAmount > 0)
					{
						for(int i = 0; i < bloodAmount; ++i)
						{
							int angle = game.rand(128);
							common.nobjectTypes[6].create2(
								game,
								angle,
								w.vel / 3,
								w.pos,
								0,
								w.index,
								firedBy);
						}
					}
					
					if(game.rand(3) == 0)
					{
						int snd = 18 + game.rand(3); // NOTE: MUST be outside the unpredictable branch below
						if(!game.soundPlayer->isPlaying(&w))
						{
							game.soundPlayer->play(snd, &w);
						}
					}
				}
			}
		} // for( ... worms ...
		
		int objBlowAway = blowAway / 3; // TODO: Read from EXE
		
		auto wr = game.wobjects.all();
		for (WObject* i; i = wr.next(); )
		{
			Weapon const& weapon = *i->type;
			
			if(weapon.affectByExplosions)
			{
				auto ipos = ftoi(i->pos);
				if(ipos.x < x + detectRange
				&& ipos.x > x - detectRange
				&& ipos.y < y + detectRange
				&& ipos.y > y - detectRange)
				{
					int delta = ipos.x - x;
					int power = detectRange - std::abs(delta);
					
					if(power > 0)
					{
						if(delta > 0)
							i->vel.x += objBlowAway * power;
						else if(delta < 0)
							i->vel.x -= objBlowAway * power;
					}
					
					delta = ipos.y - y;
					power = detectRange - std::abs(delta);
					
					if(power > 0)
					{
						if(delta > 0)
							i->vel.y += objBlowAway * power;
						else if(delta < 0)
							i->vel.y -= objBlowAway * power;
					}
					
					if(weapon.chainExplosion)
						i->blowUpObject(game, ownerIdx);
				}
			} // if( ... affectByExplosions ...
		} // for( ... wobjects ...
		
		auto nr = game.nobjects.all();
		for (NObject* i; i = nr.next(); )
		{
			NObjectType const& t = *i->type;
		
			if(t.affectByExplosions)
			{
				auto ipos = ftoi(i->pos);
				if(ipos.x < x + detectRange
				&& ipos.x > x - detectRange
				&& ipos.y < y + detectRange
				&& ipos.y > y - detectRange)
				{
					int delta = ipos.x - x;
					int power = detectRange - std::abs(delta);
					
					if(power > 0)
					{
						if(delta > 0)
							i->vel.x += objBlowAway * power;
						else if(delta < 0)
							i->vel.x -= objBlowAway * power;
					}
					
					delta = ipos.y - y;
					power = detectRange - std::abs(delta);
					
					if(power > 0)
					{
						if(delta > 0)
							i->vel.y += objBlowAway * power;
						else if(delta < 0)
							i->vel.y -= objBlowAway * power;
					}

					Common& common = *game.common;

					LTRACE(nobj, &*i - game.nobjects.arr, puxp, i->vel.x);
					LTRACE(nobj, &*i - game.nobjects.arr, puyp, i->vel.y);
				}
			}
		}
				
		{
			int width = detectRange / 2;
			
			gvl::rect rect(x - width, y - width, x + width + 1, y + width + 1);
			
			rect.intersect(game.level.rect());

			for(int y = rect.y1; y < rect.y2; ++y)
			for(int x = rect.x1; x < rect.x2; ++x)
			{
				if(game.level.mat(x, y).anyDirt()
				&& game.rand(8) == 0)
				{
					PalIdx pix = game.level.pixel(x, y);
					int angle = game.rand(128);
					common.nobjectTypes[2].create2(
						game,
						angle,
						fixedvec(),
						itof(gvl::ivec2(x, y)),
						pix, ownerIdx, firedBy);
				}
			}
		}
		
	} // if(damage ...
	
	if(dirtEffect >= 0)
	{
		drawDirtEffect(common, game.rand, game.level, dirtEffect, x - 7, y - 7);
		
		if(game.settings->shadow)
			correctShadow(common, game.level, gvl::rect(x - 10, y - 10, x + 11, y + 11));
	}
	
	auto br = game.bonuses.all();
	for (Bonus* i; i = br.next(); )
	{
		int ix = ftoi(i->x), iy = ftoi(i->y);
		
		if(ix > x - detectRange
		&& ix < x + detectRange
		&& iy > y - detectRange
		&& iy < y + detectRange)
		{
			game.bonuses.free(br);
			common.sobjectTypes[0].create(game, ix, iy, ownerIdx, firedBy);
		}
	} // for( ... bonuses ...
}
Пример #18
0
/*
** TYPECHECK
**
**	Performs typechecking and conversions where appropriate .
**	Prohibits mixed type expressions.
*/
void
typecheck(sym_t *pp1, sym_t *pp2, int opval)
{
	register int	i;
	register sym_t	*p1, *p2;

	p1 = pp1;
	p2 = pp2;

	i = (p1->type == CHAR_CONST & p2->type == CHAR_CONST);
	/* i is non-zero only if both are chars */
	switch (opval) {

	  case opCONCAT:
		if (!i)
			ov_err(NUMERIC);	/* numeric in a char operator */
		return;	/* else no further checking is needed */

	  
	  case opADD:
	  case opSUB:
		if (i)
		    return;       /* make opADD and opSUB legal operators with char */
	  case opMUL:
	  case opDIV:
	  case opPOW:
	  case opMOD:
		if (i)
			ov_err(BADCHAR);	/* arithmetic operation on two character fields */
	}

	/* first check for identical types of symbols */
	if (p1->type == p2->type) {
		if (p1->len == p2->len)
			return;
		/* lengths are different. make p2 point to the smaller one */
		if (p1->len < p2->len) {
			p2 = p1;
			p1 = pp2;
		}

		switch (p2->type) {
		  case INT_CONST:
			if (p1->len == 2) {
				*(i2type *)&p2->value = *(i1type *)&p2->value;
				p2->len = 2;
			}
			else if (p1->len == 4)
				if (p2->len == 1) {
					*(i4type *)&p2->value = *(i1type *)&p2->value;
					p2->len = 4;
				}
				else
					i2toi4(p2);

		  case CHAR_CONST:
			return;	/* done if char or int */

		  case FLOAT_CONST:
			f8tof4(p1);
			return;
		}
	}

	/* at least one symbol is an INT_CONST or FLOAT_CONST. The other can't be a CHAR */
	if (p1->type == CHAR_CONST || p2->type == CHAR_CONST)
		ov_err(BADMIX);	/* attempting binary operation on one CHAR_CONST field with a numeric */

	/* one symbol is an INT_CONST and the other a FLOAT_CONST */
	if (p2->type == INT_CONST) {
		/* exchange so that p1 is an INT_CONST and p2 is a FLOAT_CONST */
		p1 = p2;
		p2 = pp1;
	}

	/* p1 is an INT_CONST and p2 a FLOAT_CONST */
	itof(p1);
	if (p2->len == 4)
		f8tof4(p1);
}
Пример #19
-1
void Game::initGame()
{
	clearWorms();
	clearViewports();
	
	bonuses.clear();
	wobjects.clear();
	sobjects.clear();
	bobjects.clear();
	nobjects.clear();
	
	Worm* worm1 = new Worm(&game.settings.wormSettings[0], 0, 19);
	Worm* worm2 = new Worm(&game.settings.wormSettings[1], 1, 20);
	
	addViewport(new Viewport(Rect(0, 0, 158, 158), worm1, 0, 504, 350));
	addViewport(new Viewport(Rect(160, 0, 158+160, 158), worm2, 218, 504, 350));
	
	addWorm(worm1);
	addWorm(worm2);
	
	// TODO: Move as much of this as possible into the Worm ctor
	for(std::size_t i = 0; i < worms.size(); ++i)
	{
		Worm& w = *worms[i];
		w.makeSightGreen = false;
		w.lives = game.settings.lives;
		w.ready = true;
		w.movable = true;
		
		if(game.rand(2) > 0)
		{
			w.aimingAngle = itof(32);
			w.direction = 0;
		}
		else
		{
			w.aimingAngle = itof(96);
			w.direction = 1;
		}

		w.health = w.settings->health;
		w.visible = false;
		w.killedTimer = 150;
		
		w.currentWeapon = 1; // This is later changed to 0, why is it here?

/* Done in WormWeapon ctor
		for(int i = 0; i < game.settings.selectableWeapons; ++i)
		{
			w.weapons[i].available = true;
			w.weapons[i].delayLeft = 0;
			w.weapons[i].ammo = 0;
			
		}*/
	}
	
	gotChanged = false;
	lastKilled = 0;
}