Example #1
0
  void UlamTypeInfoPrimitive::PrintPretty(ByteSink & bs) const
  {
    bs.Printf("%s", NameFromPrimType(GetPrimType()));

    if (m_bitSize != DefaultSizeFromPrimType(GetPrimType()))
      bs.Printf("(%d)", m_bitSize);

    if (m_arrayLength > 0)
      bs.Printf("[%d]", m_arrayLength);
  }
Example #2
0
static void
DoRunAway (STARSHIP *StarShipPtr)
{
	ELEMENT *ElementPtr;

	LockElement (StarShipPtr->hShip, &ElementPtr);
	if (GetPrimType (&DisplayArray[ElementPtr->PrimIndex]) == STAMP_PRIM
			&& ElementPtr->life_span == NORMAL_LIFE
			&& !(ElementPtr->state_flags & FINITE_LIFE)
			&& ElementPtr->mass_points != MAX_SHIP_MASS * 10
			&& !(ElementPtr->state_flags & APPEARING))
	{
		battle_counter[0]--;

		ElementPtr->turn_wait = 3;
		ElementPtr->thrust_wait = 4;
		ElementPtr->colorCycleIndex = 0;
		ElementPtr->preprocess_func = flee_preprocess;
		ElementPtr->mass_points = MAX_SHIP_MASS * 10;
		ZeroVelocityComponents (&ElementPtr->velocity);
		StarShipPtr->cur_status_flags &=
				~(SHIP_AT_MAX_SPEED | SHIP_BEYOND_MAX_SPEED);

		SetPrimColor (&DisplayArray[ElementPtr->PrimIndex],
				BUILD_COLOR (MAKE_RGB15 (0x0B, 0x00, 0x00), 0x2E));
				// XXX: I think this is supposed to be the same as the
				// first entry of the color cycle table in flee_preeprocess,
				// but it is slightly different (0x0A as red value). - SvdB.
		SetPrimType (&DisplayArray[ElementPtr->PrimIndex], STAMPFILL_PRIM);
	
		StarShipPtr->ship_input_state = 0;
	}
	UnlockElement (StarShipPtr->hShip);
}
Example #3
0
static void
ilwrath_preprocess (PELEMENT ElementPtr)
{
	ELEMENT_FLAGS status_flags;
	STARSHIPPTR StarShipPtr;
	PPRIMITIVE lpPrim;

	GetElementStarShip (ElementPtr, &StarShipPtr);
	status_flags = StarShipPtr->cur_status_flags;
	lpPrim = &(GLOBAL (DisplayArray))[ElementPtr->PrimIndex];
	if (GetPrimType (lpPrim) == STAMPFILL_PRIM)
	{
		COLOR Color;
		BOOLEAN weapon_discharge;

		Color = GetPrimColor (lpPrim);
		weapon_discharge = ((status_flags & WEAPON)
				&& StarShipPtr->RaceDescPtr->ship_info.energy_level >= WEAPON_ENERGY_COST);
		if (weapon_discharge
				|| (StarShipPtr->special_counter == 0
				&& ((status_flags & SPECIAL) || Color != BLACK_COLOR)))
		{
			if (Color == BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F), 0x0F))
				SetPrimType (lpPrim, STAMP_PRIM);
			else if (Color == BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B))
				SetPrimColor (lpPrim, BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F), 0x0F));
			else if (Color == BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03))
				SetPrimColor (lpPrim, BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B));
			else if (Color == BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09))
				SetPrimColor (lpPrim, BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03));
			else if (Color == BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01))
				SetPrimColor (lpPrim, BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09));
			else
			{
				ProcessSound (SetAbsSoundIndex (
								/* CLOAKING_OFF */
						StarShipPtr->RaceDescPtr->ship_data.ship_sounds, 2), ElementPtr);
				SetPrimColor (lpPrim,
						BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01));
				if (weapon_discharge)
				{
					COUNT facing;

					facing = StarShipPtr->ShipFacing;
					if (TrackShip (ElementPtr, &facing) >= 0)
					{
#define LOOK_AHEAD 4
						ELEMENTPTR eptr;
						SIZE dx0, dy0, dx1, dy1;
						VELOCITY_DESC v;

						LockElement (ElementPtr->hTarget, &eptr);
						v = eptr->velocity;
						GetNextVelocityComponents (&v, &dx0, &dy0, LOOK_AHEAD);
						v = ElementPtr->velocity;
						GetNextVelocityComponents (&v, &dx1, &dy1, LOOK_AHEAD);
						dx0 = (eptr->current.location.x + dx0)
								- (ElementPtr->current.location.x + dx1);
						dy0 = (eptr->current.location.y + dy0)
								- (ElementPtr->current.location.y + dy1);
						UnlockElement (ElementPtr->hTarget);

						StarShipPtr->ShipFacing =
								NORMALIZE_FACING (
								ANGLE_TO_FACING (ARCTAN (dx0, dy0))
								);
#ifdef NOTYET
						if (ElementPtr->thrust_wait == 0
								&& (StarShipPtr->cur_status_flags & THRUST))
						{
							COUNT last_facing;

							do
							{
								VELOCITY_DESC temp_v;

								last_facing = StarShipPtr->ShipFacing;
								inertial_thrust (ElementPtr);
								temp_v = ElementPtr->velocity;
								ElementPtr->velocity = v;

								dx0 += dx1;
								dy0 += dy1;
								GetNextVelocityComponents (&temp_v,
										&dx1, &dy1, LOOK_AHEAD);
								dx0 -= dx1;
								dy0 -= dy1;
								StarShipPtr->ShipFacing =
										NORMALIZE_FACING (
										ANGLE_TO_FACING (ARCTAN (dx0, dy0))
										);
							} while (StarShipPtr->ShipFacing != last_facing);
						}
#endif /* NOTYET */
						if (ElementPtr->turn_wait == 0)
							++ElementPtr->turn_wait;
						ElementPtr->next.image.frame =
								SetAbsFrameIndex (ElementPtr->next.image.frame,
								StarShipPtr->ShipFacing);
					}
					ElementPtr->hTarget = 0;
				}
			}

			ElementPtr->state_flags |= CHANGING;
			status_flags &= ~SPECIAL;
			StarShipPtr->special_counter = 0;
		}
		else if (Color != BLACK_COLOR)
		{
			if (Color == BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01))
			{
				SetPrimColor (lpPrim, BLACK_COLOR);
				Untarget (ElementPtr);
			}
			else if (Color == BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09))
				SetPrimColor (lpPrim, BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01));
			else if (Color == BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03))
				SetPrimColor (lpPrim, BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09));
			else if (Color == BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B))
				SetPrimColor (lpPrim, BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03));
			else
				SetPrimColor (lpPrim, BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B));

			ElementPtr->state_flags |= CHANGING;
		}
	}

	if ((status_flags & SPECIAL)
			&& StarShipPtr->special_counter == 0
			&& DeltaEnergy (ElementPtr, -SPECIAL_ENERGY_COST))
	{
		SetPrimColor (lpPrim, BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F), 0x0F));
		SetPrimType (lpPrim, STAMPFILL_PRIM);

		ProcessSound (SetAbsSoundIndex (
						/* CLOAKING_ON */
				StarShipPtr->RaceDescPtr->ship_data.ship_sounds, 1), ElementPtr);
		StarShipPtr->special_counter =
				StarShipPtr->RaceDescPtr->characteristics.special_wait;

		ElementPtr->state_flags |= CHANGING;
	}
}
Example #4
0
void
DrawBatch (PPRIMITIVE lpBasePrim, PRIM_LINKS PrimLinks, 
		BATCH_FLAGS BatchFlags)
{
	RECT ValidRect;
	HOT_SPOT OldHot;

	if (GraphicsSystemActive () && GetFrameValidRect (&ValidRect, &OldHot))
	{
		COUNT CurIndex;
		PRIM_LINKS OldLinks;
		PPRIMITIVE lpPrim;

		BatchFlags &= BATCH_SINGLE
				| BATCH_BUILD_PAGE
				| BATCH_XFORM;

		BatchFlags |= _get_context_flags () & BATCH_CLIP_GRAPHICS;

		BatchGraphics ();

		if (BatchFlags & BATCH_BUILD_PAGE)
		{
			ClearBackGround (&ValidRect);
		}

		CurIndex = GetPredLink (PrimLinks);

		if (BatchFlags & BATCH_SINGLE)
		{
			if (CurIndex == END_OF_LIST)
				BatchFlags &= ~BATCH_SINGLE;
			else
			{
				lpBasePrim += CurIndex;
				OldLinks = GetPrimLinks (lpBasePrim);
				SetPrimLinks (lpBasePrim, END_OF_LIST, END_OF_LIST);
				CurIndex = 0;
			}
		}

		for (; CurIndex != END_OF_LIST; CurIndex = GetSuccLink (GetPrimLinks (lpPrim)))
		{
			GRAPHICS_PRIM PrimType;
			PPRIMITIVE lpWorkPrim;
			RECT ClipRect;
			TFB_Palette color;

			lpPrim = &lpBasePrim[CurIndex];
			PrimType = GetPrimType (lpPrim);
			if (!ValidPrimType (PrimType))
				continue;

			lpWorkPrim = lpPrim;

			switch (PrimType)
			{
				case POINT_PRIM:
					COLORtoPalette (GetPrimColor (lpWorkPrim), &color);
					TFB_Prim_Point (&lpWorkPrim->Object.Point, &color);
					break;
				case STAMP_PRIM:
					TFB_Prim_Stamp (&lpWorkPrim->Object.Stamp);
					break;
				case STAMPFILL_PRIM:
					COLORtoPalette (GetPrimColor (lpWorkPrim), &color);
					TFB_Prim_StampFill (&lpWorkPrim->Object.Stamp, &color);
					break;
				case LINE_PRIM:
					COLORtoPalette (GetPrimColor (lpWorkPrim), &color);
					TFB_Prim_Line (&lpWorkPrim->Object.Line, &color);
					break;
				case TEXT_PRIM:
					if (!TextRect (&lpWorkPrim->Object.Text,
							&ClipRect, NULL_PTR))
						continue;

					_save_stamp.origin = ClipRect.corner;
					
					_text_blt (&ClipRect, lpWorkPrim);
					break;
				case RECT_PRIM:
					COLORtoPalette (GetPrimColor (lpWorkPrim), &color);
					TFB_Prim_Rect (&lpWorkPrim->Object.Rect, &color);
					break;
				case RECTFILL_PRIM:
					COLORtoPalette (GetPrimColor (lpWorkPrim), &color);
					TFB_Prim_FillRect (&lpWorkPrim->Object.Rect, &color);
					break;
			}
		}

		UnbatchGraphics ();

		_CurFramePtr->HotSpot = OldHot;

		if (BatchFlags & BATCH_SINGLE)
			SetPrimLinks (lpBasePrim,
					GetPredLink (OldLinks),
					GetSuccLink (OldLinks));

	}
}
static void
ilwrath_preprocess (ELEMENT *ElementPtr)
{
	STATUS_FLAGS status_flags;
	STARSHIP *StarShipPtr;
	PRIMITIVE *lpPrim;

	GetElementStarShip (ElementPtr, &StarShipPtr);
	status_flags = StarShipPtr->cur_status_flags;
	lpPrim = &(GLOBAL (DisplayArray))[ElementPtr->PrimIndex];
	if (GetPrimType (lpPrim) == STAMPFILL_PRIM)
	{
		Color color;
		BOOLEAN weapon_discharge;

		color = GetPrimColor (lpPrim);
		weapon_discharge = ((status_flags & WEAPON)
				&& StarShipPtr->RaceDescPtr->ship_info.energy_level >= WEAPON_ENERGY_COST);
	
		if (
			weapon_discharge
			|| (
				StarShipPtr->special_counter == 0
				&& ( 
					((!sameColor(color, BLACK_COLOR)) && (!sameColor(color, INVIS_COLOR)))
					|| status_flags & SPECIAL
				)
			)
		)
		{
			if (sameColor (color,
					BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F), 0x0F)))
				SetPrimType (lpPrim, STAMP_PRIM);
			else if (sameColor (color,
					BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B)))
				SetPrimColor (lpPrim,
						BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F), 0x0F));
			else if (sameColor (color,
					BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03)))
				SetPrimColor (lpPrim,
						BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B));
			else if (sameColor (color,
					BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09)))
				SetPrimColor (lpPrim,
						BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03));
			else if (sameColor (color,
					BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01)))
				SetPrimColor (lpPrim,
						BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09));
			else
			{
				ProcessSound (SetAbsSoundIndex (
						/* CLOAKING_OFF */
					StarShipPtr->RaceDescPtr->ship_data.ship_sounds, 2), ElementPtr);
			
				SetPrimColor (lpPrim, BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01));
			}
			
			ElementPtr->state_flags |= CHANGING;
			status_flags &= ~SPECIAL;
			StarShipPtr->special_counter = 0;
		}
		else if ( (!sameColor (color, BLACK_COLOR))
				&& (!sameColor (color, INVIS_COLOR)))
		{
			if (sameColor (color, BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01)))
			{
				if(PlayerControl[ElementPtr->playerNr] & HUMAN_CONTROL)
					SetPrimColor (lpPrim, INVIS_COLOR);
				else
					SetPrimColor (lpPrim, BLACK_COLOR);
				Untarget (ElementPtr);
			}
			else if (sameColor (color,
					BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09)))
				SetPrimColor (lpPrim,
						BUILD_COLOR (MAKE_RGB15 (0x00, 0x00, 0x14), 0x01));
			else if (sameColor (color,
					BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03)))
				SetPrimColor (lpPrim,
						BUILD_COLOR (MAKE_RGB15 (0x0A, 0x0A, 0x1F), 0x09));
			else if (sameColor (color,
					BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B)))
				SetPrimColor (lpPrim,
						BUILD_COLOR (MAKE_RGB15 (0x00, 0x14, 0x14), 0x03));
			else
				SetPrimColor (lpPrim,
						BUILD_COLOR (MAKE_RGB15 (0x0A, 0x1F, 0x1F), 0x0B));

			ElementPtr->state_flags |= CHANGING;
		}
	}

	if ((status_flags & SPECIAL)
			&& StarShipPtr->special_counter == 0
			&& DeltaEnergy (ElementPtr, -SPECIAL_ENERGY_COST))
	{
		SetPrimColor (lpPrim, BUILD_COLOR (MAKE_RGB15 (0x1F, 0x1F, 0x1F), 0x0F));
		SetPrimType (lpPrim, STAMPFILL_PRIM);

		ProcessSound (SetAbsSoundIndex (
						/* CLOAKING_ON */
				StarShipPtr->RaceDescPtr->ship_data.ship_sounds, 1),
				ElementPtr);
		StarShipPtr->special_counter =
				StarShipPtr->RaceDescPtr->characteristics.special_wait;

		ElementPtr->state_flags |= CHANGING;
	}
}
Example #6
0
 void UlamTypeInfoPrimitive::PrintMangled(ByteSink & bs) const
 {
   bs.Printf("%D%D1%c", m_arrayLength, m_bitSize, CharFromPrimType(GetPrimType()));
 }
Example #7
0
void
DrawBatch (PRIMITIVE *lpBasePrim, PRIM_LINKS PrimLinks,
           BATCH_FLAGS BatchFlags)
{
    RECT ValidRect;
    POINT origin;

    if (GraphicsSystemActive () && GetContextValidRect (&ValidRect, &origin))
    {
        COUNT CurIndex;
        PRIMITIVE *lpPrim;
        DrawMode mode = _get_context_draw_mode ();

        BatchGraphics ();

        if (BatchFlags & BATCH_BUILD_PAGE)
        {
            ClearBackGround (&ValidRect);
        }

        CurIndex = GetPredLink (PrimLinks);

        for (; CurIndex != END_OF_LIST;
                CurIndex = GetSuccLink (GetPrimLinks (lpPrim)))
        {
            GRAPHICS_PRIM PrimType;
            PRIMITIVE *lpWorkPrim;
            RECT ClipRect;
            Color color;

            lpPrim = &lpBasePrim[CurIndex];
            PrimType = GetPrimType (lpPrim);
            if (!ValidPrimType (PrimType))
                continue;

            lpWorkPrim = lpPrim;

            switch (PrimType)
            {
            case POINT_PRIM:
                color = GetPrimColor (lpWorkPrim);
                TFB_Prim_Point (&lpWorkPrim->Object.Point, color,
                                mode, origin);
                break;
            case STAMP_PRIM:
                TFB_Prim_Stamp (&lpWorkPrim->Object.Stamp, mode, origin);
                break;
            case STAMPFILL_PRIM:
                color = GetPrimColor (lpWorkPrim);
                TFB_Prim_StampFill (&lpWorkPrim->Object.Stamp, color,
                                    mode, origin);
                break;
            case LINE_PRIM:
                color = GetPrimColor (lpWorkPrim);
                TFB_Prim_Line (&lpWorkPrim->Object.Line, color,
                               mode, origin);
                break;
            case TEXT_PRIM:
                if (!TextRect (&lpWorkPrim->Object.Text, &ClipRect, NULL))
                    continue;
                // ClipRect is relative to origin
                _text_blt (&ClipRect, &lpWorkPrim->Object.Text, origin);
                break;
            case RECT_PRIM:
                color = GetPrimColor (lpWorkPrim);
                TFB_Prim_Rect (&lpWorkPrim->Object.Rect, color,
                               mode, origin);
                break;
            case RECTFILL_PRIM:
                color = GetPrimColor (lpWorkPrim);
                TFB_Prim_FillRect (&lpWorkPrim->Object.Rect, color,
                                   mode, origin);
                break;
            }
        }

        UnbatchGraphics ();
    }
}