Esempio n. 1
0
void physics_add(Entity ent)
{
    PhysicsInfo *info;

    if (entitypool_get(pool, ent))
        return; /* already has physics */

    transform_add(ent);

    info = entitypool_add(pool, ent);

    info->mass = 1.0;
    info->type = PB_DYNAMIC;

    /* create, init cpBody */
    info->body = cpSpaceAddBody(space, cpBodyNew(info->mass, 1.0));
    cpBodySetUserData(info->body, ent); /* for cpBody -> Entity mapping */
    cpBodySetPos(info->body, cpv_of_vec2(transform_get_position(ent)));
    cpBodySetAngle(info->body, transform_get_rotation(ent));
    info->last_dirty_count = transform_get_dirty_count(ent);

    /* initially no shapes */
    info->shapes = array_new(ShapeInfo);

    /* initialize last_pos/last_ang info for kinematic bodies */
    info->last_pos = cpBodyGetPos(info->body);
    info->last_ang = cpBodyGetAngle(info->body);

    info->collisions = NULL;
}
Esempio n. 2
0
static int
transform_plugin(TSCont contp, TSEvent event, void *edata)
{
  TSHttpTxn txnp = (TSHttpTxn) edata;

  switch (event) {
  case TS_EVENT_HTTP_READ_RESPONSE_HDR:
    if (transformable(txnp)) {
      transform_add(txnp);
    }
    TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
    return 0;
  default:
    break;
  }

  return 0;
}
Esempio n. 3
0
/*-------------------------------------------------------------------------
  read_response_handler
  Handler for events related to hook READ_RESPONSE

  Input:
    contp      continuation for the current transaction
    event      event received
    data       pointer on eventual data
  Output :
  Return Value:
  -------------------------------------------------------------------------*/
static int
read_response_handler(TSCont contp, TSEvent event, void *edata)
{
  TSHttpTxn txnp = (TSHttpTxn) edata;

  switch (event) {
  case TS_EVENT_HTTP_READ_RESPONSE_HDR:
    if (transformable(txnp)) {
      TSDebug(DBG_TAG, "Add a transformation");
      transform_add(txnp);
    }
    TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
    return 0;
  default:
    break;
  }

  return 0;
}
Esempio n. 4
0
static int
transform_plugin(TSCont contp, TSEvent event, void *edata)
{
  TSHttpTxn txnp = (TSHttpTxn) edata;

  TSDebug("null-transform", "Entering transform_plugin()");
  switch (event) {
  case TS_EVENT_HTTP_READ_RESPONSE_HDR:
    TSDebug("null-transform", "\tEvent is TS_EVENT_HTTP_READ_RESPONSE_HDR");
    if (transformable(txnp)) {
      transform_add(txnp);
    }

    TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
    return 0;
  default:
    break;
  }

  return 0;
}
Esempio n. 5
0
char ai_get(character_t* c, char is_item, int id, float amount, char keep)
{
	universe_t* u = c->w->universe;

	amount -= inventory_get(&c->inventory, is_item, id);
	if (amount <= 0)
		return 0;

	// gather if possible
	kindOf_mine_t* m = universe_mineFor(u, is_item, id);
	if (m != NULL)
	{
		character_goMine(c, m);
		return 1;
	}

	// if the current building cannot obtain the component, build one which can
	building_t* b = building_get(&c->w->objects, c->hasBuilding);
	transform_t* tr = b == NULL ? NULL : kindOf_building_canMake(b->t, is_item, id);
	if (tr == NULL)
	{
		// do not replace the building
		if (keep)
		{
			if (rand() % 60 != 0)
				return 1;

			float price = is_item ? u->items[id].price : u->materials[id].price;
			price *= amount;
			if (c->inventory.money < price)
			{
				if (c->inBuilding != c->hasBuilding)
					character_goto(c, c->hasBuilding);
				return 1;
			}

			// try and buy it
			building_t* b = world_findSale(c->w, c->o.x, c->o.y, is_item, id);
			if (b == NULL)
				return 1;

			if (c->inBuilding != b->o.uuid)
			{
				character_goto(c, b->o.uuid);
				return 1;
			}

			building_take(b, is_item, id, amount, &c->inventory, 0);
			return 1;
		}

		kindOf_building_t* b = universe_buildFor(u, is_item, id);
		if (b == NULL)
		{
			const char* name = is_item ? u->items[id].name : u->materials[id].name;
			fprintf(stderr, "%s: I do not know how to make %s\n", c->ai->name, name);
			return 1;
		}

		// materials to be gather before building
		transform_t total;
		transform_init(&total);

		// first, gather the non-base materials for the component
		tr = kindOf_building_canMake(b, is_item, id);
		for (int i = 0; i < tr->n_req; i++)
		{
			component_t* p = &tr->req[i];
			if (universe_mineFor(u, p->is_item, p->id) == NULL)
				transform_req(&total, p->is_item, p->id, p->amount*amount);
		}

		// then, gather the materials for the building
		transform_add(&total, &b->build, 1);

		// do gather
		char isreq = ai_getreq(c, &total, 1, keep);
		transform_exit(&total);
		if (isreq)
			return 1;

		// build
		character_buildAuto(c, b);
		return 1;
	}

	if (ai_getreq(c, tr, amount, keep))
		return 1;

	// go in the building
	if (c->inBuilding != c->hasBuilding)
	{
		character_goto(c, b->o.uuid);
		return 1;
	}

	// enqueue item
	if (is_item && b->work_n == 0)
	{
		int nth = tr - b->t->items;
		building_work_enqueue(b, nth);
	}

	// work
	return 1;
}