示例#1
0
void
VSShaderLib::prepareProgram() {

	glLinkProgram(pProgram);
	addUniforms();
	addBlocks();
}
示例#2
0
void BlockPlant::onNeighbourPlace(User* user, int16_t newblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction)
{
	addBlocks(x, y, z, map);
}
示例#3
0
bool BlockPlant::onPlace(User* user, int16_t newblock, int32_t x, int16_t y, int32_t z, int map, int8_t direction)
{
	uint8_t oldblock;
	uint8_t oldmeta;

	/* move the x,y,z coords dependent upon placement direction */
	if (!this->translateDirection(&x, &y, &z, map, direction)) {
		revertBlock(user, x, y, z, map);
		return true;
	}

	if (!ServerInstance->map(map)->getBlock(x, y - 1, z, &oldblock, &oldmeta)) {
		revertBlock(user, x, y, z, map);
		return true;
	}

	if (newblock != BLOCK_DIRT && newblock != BLOCK_SOIL && newblock != BLOCK_GRASS) {
		if (this->isBlockEmpty(x, y - 1, z, map) || !this->isBlockEmpty(x, y, z, map)) {
			revertBlock(user, x, y, z, map);
			return true;
		}

		if (!this->isBlockStackable(oldblock)) {
			revertBlock(user, x, y, z, map);
			return true;
		}
	} else {
		if (this->isUserOnBlock(x, y, z, map)) {
			revertBlock(user, x, y, z, map);
			return true;
		}
	}

	if ((newblock == BLOCK_REED || newblock == ITEM_REED) && (oldblock == BLOCK_GRASS || oldblock == BLOCK_DIRT)) {
		// TODO : Check for water
		ServerInstance->map(map)->sendBlockChange(x, y, z, BLOCK_REED, 0);
		ServerInstance->map(map)->setBlock(x, y, z, BLOCK_REED, 0);
		addBlock(x, y, z, map);
		return false;
	}

	if (newblock == BLOCK_CACTUS && oldblock != BLOCK_SAND) {
		revertBlock(user, x, y, z, map);
		return true;
	}

	if ((newblock == BLOCK_YELLOW_FLOWER  ||
	        newblock == BLOCK_RED_ROSE) && (oldblock != BLOCK_DIRT &&
	                                        oldblock != BLOCK_GRASS)) {
		revertBlock(user, x, y, z, map);
		return true;
	}

	if ((newblock == ITEM_SEEDS || newblock == BLOCK_CROPS) && (oldblock == BLOCK_SOIL)) {
		ServerInstance->map(map)->sendBlockChange(x, y, z, BLOCK_CROPS, 0);
		ServerInstance->map(map)->setBlock(x, y, z, BLOCK_CROPS, 0);
		addBlock(x, y, z, map);
		return false;
	}

	if ((newblock == ITEM_SEEDS || newblock == BLOCK_CROPS)) {
		revertBlock(user, x, y, z, map);
		return true;
	}

	if (newblock > 255 && (oldblock == BLOCK_DIRT  || oldblock == BLOCK_GRASS)) {
		// Hoe on dirt = Soil
		ServerInstance->map(map)->sendBlockChange(x, y - 1, z, BLOCK_SOIL, 0);
		ServerInstance->map(map)->setBlock(x, y - 1, z, BLOCK_SOIL, 0);
		if (SEEDS_CHANCE >= rand() % 10000) {
			ServerInstance->map(map)->createPickupSpawn(x, y + 1, z, ITEM_SEEDS, 1, 0, nullptr);
		}
		return true;
	}

	if (newblock > 255) {
		revertBlock(user, x, y, z, map);
		return true;
	}

	if ((newblock == BLOCK_BROWN_MUSHROOM || newblock == BLOCK_RED_MUSHROOM)
	        && oldblock != BLOCK_DIRT) {
		revertBlock(user, x, y, z, map);
		return true;
	}

	if (newblock == BLOCK_SAPLING) {
		ServerInstance->map(map)->addSapling(user, x, y, z);
	} else {
		ServerInstance->map(map)->sendBlockChange(x, y, z, char(newblock), 0);
		ServerInstance->map(map)->setBlock(x, y, z, char(newblock), 0);
		addBlocks(x, y, z, map);
	}
	return false;
}
示例#4
0
void BlockPlant::timer200()
{
	for (int i = growingPlants.size() - 1; i >= 0; i--) {
		PlantBlockPtr p = growingPlants[i];
		uint8_t block, meta, sky, light;

		ServerInstance->map(p->map)->getBlock(p->x, p->y, p->z, &block, &meta);
		ServerInstance->map(p->map)->getLight(p->x, p->y, p->z, &light, &sky);

		p->count++;

		if (p->count > grass_timeout * 5 && (block == BLOCK_DIRT || block == BLOCK_GRASS)) {
			uint8_t block2, meta2;
			ServerInstance->map(p->map)->getBlock(p->x, p->y + 1, p->z, &block2, &meta2);
			if (block2 == BLOCK_AIR || block2 == BLOCK_SAPLING ||
			        block2 == BLOCK_LEAVES || block2 == BLOCK_GLASS ||
			        block2 == BLOCK_BROWN_MUSHROOM || block2 == BLOCK_RED_MUSHROOM ||
			        block2 == BLOCK_YELLOW_FLOWER || block2 == BLOCK_RED_ROSE ||
			        block2 == BLOCK_TORCH || block2 == BLOCK_FIRE ||
			        block2 == BLOCK_SAPLING || block2 == BLOCK_SIGN_POST ||
			        block2 == BLOCK_WOODEN_DOOR || block2 == BLOCK_LADDER ||
			        block2 == BLOCK_WALL_SIGN || block2 == BLOCK_LEVER ||
			        block2 == BLOCK_IRON_DOOR || block2 == BLOCK_REDSTONE_TORCH_OFF ||
			        block2 == BLOCK_REDSTONE_TORCH_ON || block2 == BLOCK_STONE_BUTTON ||
			        block2 == BLOCK_SNOW) {
				// The grass can grow
				if (block == BLOCK_DIRT) {
					if (light > 4 || sky > 3) {
						ServerInstance->map(p->map)->sendBlockChange(p->x, p->y, p->z, (char)BLOCK_GRASS, 0);
						ServerInstance->map(p->map)->setBlock(p->x, p->y, p->z, (char)BLOCK_GRASS, 0);
						addBlocks(p->x, p->y, p->z, p->map);
					}
				}
			} else {
				if (block == BLOCK_GRASS) {
					ServerInstance->map(p->map)->sendBlockChange(p->x, p->y, p->z, (char)BLOCK_DIRT, 0);
					ServerInstance->map(p->map)->setBlock(p->x, p->y, p->z, (char)BLOCK_DIRT, 0);
					addBlocks(p->x, p->y, p->z, p->map);
				}
			}

			remBlock(p);
			continue;
		}
		if (p->count > crop_timeout * 5 && block == BLOCK_CROPS) {
			p->count = 0;
			if (light > 7 || sky > 3) {
				if (meta < 7) {
					meta ++;
				} else {
					remBlock(p);
					continue;
				}
				ServerInstance->map(p->map)->sendBlockChange(p->x, p->y, p->z, (char)BLOCK_CROPS, meta);
				ServerInstance->map(p->map)->setBlock(p->x, p->y, p->z, (char)BLOCK_CROPS, meta);
			}
		}
		if (p->count > cactus_timeout * 5 && block == BLOCK_CACTUS) {
			uint8_t block, meta;
			if (!ServerInstance->map(p->map)->getBlock(p->x, p->y + 1, p->z, &block, &meta)) {
				remBlock(p);
				continue;
			}
			if (block != BLOCK_AIR) {
				remBlock(p);
				continue;
			}
			p->count = 0;
			for (int i = 0 ; i < cactus_max; i++) {
				ServerInstance->map(p->map)->getBlock(p->x, p->y - i, p->z, &block, &meta);
				if (block != BLOCK_CACTUS && block != BLOCK_SAND) {
					onBroken(nullptr, 0, p->x, p->y, p->z, p->map, 0);
					remBlock(p);
					i = cactus_max;
				}
				if (block == BLOCK_SAND) {
					ServerInstance->map(p->map)->sendBlockChange(p->x, p->y + 1, p->z, (char)BLOCK_CACTUS, 0);
					ServerInstance->map(p->map)->setBlock(p->x, p->y + 1, p->z, (char)BLOCK_CACTUS, 0);
					addBlocks(p->x, p->y, p->z, p->map);
					break;
				}
			}
		}
		if (p->count > reed_timeout * 5 && (block == BLOCK_REED)) {
			uint8_t block, meta;
			if (!ServerInstance->map(p->map)->getBlock(p->x, p->y + 1, p->z, &block, &meta)) {
				remBlock(p);
				continue;
			}
			if (block != BLOCK_AIR) {
				remBlock(p);
				continue;
			}
			p->count = 0;
			for (int i = 0 ; i < reed_max; i++) {
				ServerInstance->map(p->map)->getBlock(p->x, p->y - i, p->z, &block, &meta);
				if (block != BLOCK_REED && block != BLOCK_GRASS && block != BLOCK_DIRT) {
					onBroken(nullptr, 0, p->x, p->y, p->z, p->map, 0);
					remBlock(p);
					i = reed_max;
				}
				if (block == BLOCK_GRASS || block == BLOCK_DIRT) {
					ServerInstance->map(p->map)->sendBlockChange(p->x, p->y + 1, p->z, (char)BLOCK_REED, 0);
					ServerInstance->map(p->map)->setBlock(p->x, p->y + 1, p->z, (char)BLOCK_REED, 0);
					addBlocks(p->x, p->y, p->z, p->map);
					break;
				}
			}
		}

	}
}
  void goalCB()
  {
    // ---------------------------------------------------------------------------------------------
    // Accept the new goal
    goal_ = action_server_.acceptNewGoal();

    ROS_INFO("[block logic] Received goal! %f, %s", goal_->block_size, goal_->frame.c_str());

    block_size = goal_->block_size;
    arm_link = goal_->frame;

    if (initialized_)
    {
      addBlocks(msg_);
    }

    // --------------------------------------------------------------------------------------------
    // Start pose - choose one that is preferrably not in the goal region
    geometry_msgs::Pose start_pose;
    bool found_pose = false;

    // Check if there is only 1 block detected
    if( !msg_->poses.size() )
    {
      // no blocks, what to do?
      ROS_WARN("[block logic] No blocks found");
    }
    else if( msg_->poses.size() == 1 )
    {
      start_pose = msg_->poses[0];
      found_pose = true;
      ROS_INFO("[block logic] Only 1 block, using it");
    }
    else
    {
      // Search for block that meets our criteria
      for(int i = 0; i < msg_->poses.size(); ++i)
      {
        if( msg_->poses[i].position.y > -0.12 && msg_->poses[i].position.y < 0.2 ) // start of goal region
        {
          start_pose = msg_->poses[i];
          found_pose = true;
          ROS_INFO_STREAM("[block logic] Chose this block:\n" << start_pose);
          break;
        }
      }
      if( !found_pose )
      {
        ROS_INFO("[block logic] Did not find a good block, default to first");
        start_pose = msg_->poses[0];
        found_pose = true;
      }
    }

    // --------------------------------------------------------------------------------------------
    // End pose is just chosen place on board
    geometry_msgs::Pose end_pose;
    end_pose.orientation = msg_->poses[0].orientation; // keep the same orientation
    end_pose.position.x = 0.225;
    end_pose.position.y = 0.18;
    end_pose.position.z = msg_->poses[0].position.z;

    // --------------------------------------------------------------------------------------------
    // Move that block
    if( found_pose )
    {
      moveBlock(start_pose, end_pose);
    }
  }