Example #1
0
// PACK に ELEMENT を追加
bool AddElement(PACK *p, ELEMENT *e)
{
	// 引数チェック
	if (p == NULL || e == NULL)
	{
		return false;
	}

	// サイズチェック
	if (LIST_NUM(p->elements) >= MAX_ELEMENT_NUM)
	{
		// これ以上追加できない
		FreeElement(e);
		return false;
	}

	// 同じ名前が存在しないかどうかチェック
	if (GetElement(p, e->name, INFINITE))
	{
		// 存在している
		FreeElement(e);
		return false;
	}

	if (e->num_value == 0)
	{
		// 項目が 1 つも存在していない VALUE は追加できない
		FreeElement(e);
		return false;
	}

	// 追加
	Add(p->elements, e);
	return true;
}
Example #2
0
static void
pkunk_intelligence (ELEMENT *ShipPtr, EVALUATE_DESC *ObjectsOfConcern,
		COUNT ConcernCounter)
{
	STARSHIP *StarShipPtr;
	HELEMENT hPhoenix;

	GetElementStarShip (ShipPtr, &StarShipPtr);
	hPhoenix = (HELEMENT) StarShipPtr->RaceDescPtr->data;
	if (hPhoenix && (StarShipPtr->control & STANDARD_RATING))
	{
		RemoveElement (hPhoenix);
		FreeElement (hPhoenix);
		StarShipPtr->RaceDescPtr->data = 0;
	}

	if (StarShipPtr->RaceDescPtr->ship_info.energy_level <
			StarShipPtr->RaceDescPtr->ship_info.max_energy
			&& (StarShipPtr->special_counter == 0
			|| (BYTE)TFB_Random () < 20))
		StarShipPtr->ship_input_state |= SPECIAL;
	else
		StarShipPtr->ship_input_state &= ~SPECIAL;
	ship_intelligence (ShipPtr, ObjectsOfConcern, ConcernCounter);
}
Example #3
0
Force* NextForce(List* forces)
{
    if(forces->size == 0)
        return NULL;
    Force* tmp = (Force*)GetValue(forces, 0);
    FreeElement(forces, 0);
    return tmp;
}
Example #4
0
void
TkStylePkgFree(
    TkMainInfo *mainPtr)	/* The application being deleted. */
{
    ThreadSpecificData *tsdPtr =
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));
    Tcl_HashSearch search;
    Tcl_HashEntry *entryPtr;
    StyleEngine *enginePtr;
    int i;

    tsdPtr->nbInit--;
    if (tsdPtr->nbInit != 0) {
	return;
    }

    /*
     * Free styles.
     */

    entryPtr = Tcl_FirstHashEntry(&tsdPtr->styleTable, &search);
    while (entryPtr != NULL) {
	ckfree(Tcl_GetHashValue(entryPtr));
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&tsdPtr->styleTable);

    /*
     * Free engines.
     */

    entryPtr = Tcl_FirstHashEntry(&tsdPtr->engineTable, &search);
    while (entryPtr != NULL) {
	enginePtr = Tcl_GetHashValue(entryPtr);
	FreeStyleEngine(enginePtr);
	ckfree(enginePtr);
	entryPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&tsdPtr->engineTable);

    /*
     * Free elements.
     */

    for (i = 0; i < tsdPtr->nbElements; i++) {
	FreeElement(tsdPtr->elements+i);
    }
    Tcl_DeleteHashTable(&tsdPtr->elementTable);
    ckfree(tsdPtr->elements);
}
Example #5
0
void ArrayFree(DArray array)
{
	int i;
	
	GS_ASSERT(array);
	for (i = 0; i < array->count; i++)
	{
		FreeElement(array, i);
	}
	// mj to do: move these asserts into gsi_free.  maybe, depends on whether user overloads them
	GS_ASSERT(array->list)
	GS_ASSERT(array)
	gsifree(array->list);
	gsifree(array);
}
Example #6
0
// PACK から ELEMENT を削除
void DelElement(PACK *p, char *name)
{
	ELEMENT *e;
	// 引数チェック
	if (p == NULL || name == NULL)
	{
		return;
	}

	e = GetElement(p, name, INFINITE);
	if (e != NULL)
	{
		Delete(p->elements, e);

		FreeElement(e);
	}
}
Example #7
0
void ArraySetDataPtr(DArray array, void *ptr, int count, int capacity)
{
	int i;
	
	GS_ASSERT(array);
	if (array->list != NULL)
	{
		for (i = 0; i < array->count; i++)
		{
			FreeElement(array, i);
		}
		gsifree(array->list);
	}
	array->list = ptr;
	array->count = count;
	array->capacity = capacity;

}
Example #8
0
// PACK オブジェクトの解放
void FreePack(PACK *p)
{
	UINT i;
	ELEMENT **elements;
	// 引数チェック
	if (p == NULL)
	{
		return;
	}

	elements = ToArray(p->elements);
	for (i = 0;i < LIST_NUM(p->elements);i++)
	{
		FreeElement(elements[i]);
	}
	Free(elements);

	ReleaseList(p->elements);
	Free(p);
}
ERR TestControllerLoop()
{
    while(flags & CONTINUE)
    {
        //AddForce(ship->physics_object, 0.0, 10.0, ship->physics_object->cog_x, ship->physics_object->cog_y);        

        SDL_Event event;
        while(SDL_PollEvent(&event) != 0)
        {
            if(event.type == SDL_QUIT)
                 flags ^= CONTINUE;
            else if(event.type == SDL_KEYDOWN && event.key.repeat == 0)
                switch(event.key.keysym.sym)
                {
                case SDLK_UP: 
                    flames->sprite->data[CURRENT_LOOP] ^= 1;
                    flags ^= ENGINE;
                    break;
                case SDLK_DOWN:
                    ship->y_speed = 0.0;
                    ship->x_speed = 0.0;
                    break;
                case SDLK_LEFT: ship->a_speed   = -5.0; break;
                case SDLK_RIGHT: ship->a_speed  = 5.0; break;
                case SDLK_r :
                    yoshi->center_x = 220;
                    yoshi->center_y = 120;
                    yoshi->x_speed = 0;
                    yoshi->y_speed = 0;
                    ship->center_x = 520;
                    ship->center_y = 120;
                    ship->x_speed = 0;
                    ship->y_speed = 0;
                case SDLK_SPACE:
                    tmp = CopyEntity(bolt);
                    tmp->center_x = ship->center_x;
                    tmp->center_y = ship->center_y;
                    tmp->angle = ship->angle;
                    tmp->x_speed = RotateOffsetX(0.0, -10.0, ship->angle);
                    tmp->y_speed = RotateOffsetY(0.0, -10.0, ship->angle);
                    InsertValue(tmp, bolts, 0);
                    break;
                }
            else if(event.type == SDL_KEYUP)
                switch(event.key.keysym.sym)
                {
                case SDLK_UP:
                    flames->sprite->data[CURRENT_LOOP] ^= 1;
                    flags ^= ENGINE;
                    break;
                case SDLK_DOWN: break;
                case SDLK_LEFT: ship->a_speed   = 0.0; break;
                case SDLK_RIGHT: ship->a_speed  = 0.0; break;
                case SDLK_SPACE: 
                    break;
                }
        }

        if(flags & UPDATE)
        {
            if(flags & ENGINE)
                AddForce(ship->physics_object, RotateOffsetX(0.0, -20.0, ship->angle), RotateOffsetY(0.0, -20.0, ship->angle),
                        ship->physics_object->cog_x, ship->physics_object->cog_y);

            if(CheckCollision(ship->collision_object, yoshi->collision_object) != 0)
            {
                printf("BOOM\n");
                //flags ^= CONTINUE;
                AddForce(ship->physics_object, yoshi->x_speed * yoshi->physics_object->mass, yoshi->y_speed * yoshi->physics_object->mass,
                        ship->physics_object->cog_x, ship->physics_object->cog_y);
                AddForce(yoshi->physics_object, ship->x_speed * ship->physics_object->mass, ship->y_speed * ship->physics_object->mass,
                        yoshi->physics_object->cog_x, yoshi->physics_object->cog_y);
            }
            Element* el = bolts->start;
            Entity* tmp = NULL;
            int i = 0;
            while(el != NULL)
            {
                tmp = (Entity*)el->value;
                //if(CheckCollision(ship->collision_object, tmp->collision_object) != 0)
                //{
                //    printf("BOOM\n");
                //    flags ^= CONTINUE;
                //}
                if(CheckCollision(yoshi->collision_object, tmp->collision_object) != 0)
                {
                    AddForce(yoshi->physics_object, RotateOffsetX(0.0, -10.0, tmp->angle), RotateOffsetY(0.0, -10.0, tmp->angle),
                            yoshi->physics_object->cog_x, yoshi->physics_object->cog_y);
                    yoshi->sprite->zoom -= 0.5;
                    if(yoshi->sprite->zoom < 0.5)
                        yoshi->sprite->zoom = 0.5;
                    FreeEntity(tmp);
                    FreeElement(bolts, i);
                }
                i++;
                el = el->next;
            }

            UpdateEntity(ship);

            flames->angle = ship->angle;
            flames->center_x = ship->center_x + RotateOffsetX(0.0, ship->sprite->h * ship->sprite->zoom, ship->angle);
            flames->center_y = ship->center_y + RotateOffsetY(0.0, ship->sprite->h * ship->sprite->zoom, ship->angle);
            UpdateEntity(flames);

            UpdateEntity(yoshi);
            yoshi->sprite->zoom      += 0.01;
            yoshi->physics_object->mass = yoshi->sprite->zoom * 100;
            if(yoshi->physics_object->mass < 1)
                yoshi->physics_object->mass = 1;
            yoshi->collision_object->radius = 32*yoshi->sprite->zoom;
            if(yoshi->collision_object->radius < 1)
                yoshi->collision_object->radius = 1;

            for(i = 0; i < bolts->size; i++)
            {
                Entity* tmp = (Entity*)GetValue(bolts, i);
                if(tmp->center_x < -15 || tmp->center_y < -15 || tmp->center_x > 1000 || tmp->center_y > 500)
                {
                    FreeEntity(tmp);
                    FreeElement(bolts, i);
                }
                else
                    UpdateEntity(tmp);
            }
        }

        if(flags & DRAW)
        {
            ClearPMap(visual_debug);
            DrawEntity(ship);
            DrawEntityDebugInfo(visual_debug, ship);
            DrawEntity(flames);
            DrawEntity(yoshi);
            DrawEntityDebugInfo(visual_debug, yoshi);
            int i;
            for(i = 0; i < bolts->size; i++)
            {
                Entity* tmp = (Entity*)GetValue(bolts, i);
                DrawEntity(tmp);
                DrawEntityDebugInfo(visual_debug, tmp);
            }
            DrawPixelMap(visual_debug);
            Render();
        }
    }
    return ExitTestController();
}