Beispiel #1
0
void Object::move(const int direction, float amount) {
    Point p(0, 0, 0);
    float x, z, radAngle = getDirectionAngle() * M_PI / 180;

    switch (direction) {
        case Object::FRONT:
            x = cos(radAngle);
            z = sin(radAngle);
            break;
        case Object::BACK:
            x = -cos(radAngle);
            z = -sin(radAngle);
            break;
        case Object::LEFT:
            radAngle += M_PI / 2;
            x = -cos(radAngle);
            z = -sin(radAngle);
            break;
        case Object::RIGHT:
            radAngle -= M_PI / 2;
            x = -cos(radAngle);
            z = -sin(radAngle);
            break;
    }

    p.x += x * amount;
    p.z += z * amount;

    position = p + position;
}
void PlantObjectImplementation::changeSize(int size) {
	String plantTemplate = "";

	switch (size) {
	case 0: plantTemplate = "object/tangible/loot/plant_grow/plant_stage_dead.iff"; break;
	case 1: plantTemplate = "object/tangible/loot/plant_grow/plant_stage_1.iff"; break;
	case 2: plantTemplate = "object/tangible/loot/plant_grow/plant_stage_2.iff"; break;
	case 3: plantTemplate = "object/tangible/loot/plant_grow/plant_stage_3.iff"; break;
	}

	ManagedReference<ZoneServer*> zoneServer = getZoneServer();

	if (zoneServer == NULL)
		return;

	ManagedReference<SceneObject*> parent = getParent();

	if (parent == NULL || !parent->isCellObject())
		return;

	ManagedReference<SceneObject*> obj = zoneServer->createObject(plantTemplate.hashCode(), getPersistenceLevel());

	if (obj == NULL)
		return;

	Locker clocker(obj, _this.getReferenceUnsafeStaticCast());

	obj->initializePosition(getPositionX(), getPositionZ(), getPositionY());
	obj->setDirection(Math::deg2rad(getDirectionAngle()));

	ManagedReference<PlantObject*> newPlant = cast<PlantObject*>( obj.get());

	if (newPlant == NULL)
		return;

	newPlant->setWaterLevel(waterLevel);
	newPlant->setNutrientLevel(nutrientLevel);
	newPlant->setWaterQuality(waterQuality);
	newPlant->setNutrientQuality(nutrientQuality);
	newPlant->setPlantHealth(health);

	newPlant->initializePlant(size);

	parent->transferObject(obj, -1);

	clocker.release();

	destroyObjectFromWorld(true);
	destroyObjectFromDatabase();
}