116 lines
4.5 KiB
Plaintext
116 lines
4.5 KiB
Plaintext
//::///////////////////////////////////////////////
|
|
//:: Name: farm_plant
|
|
//:: Copyright (c) 2001 Bioware Corp.
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
This script is executed everytime seeds are
|
|
being attempted to plant.
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Adam Walenga
|
|
//:: Created On: September 4th, 2004
|
|
//:://////////////////////////////////////////////
|
|
#include "farm_include"
|
|
#include "farm_config"
|
|
#include "eds_include"
|
|
|
|
void Farm_CreateCrop (string sPlant, location lLoc, int iFarm, int iPosition)
|
|
{
|
|
//Create crop, and set loot delay.
|
|
object oPlant = CreateObject (OBJECT_TYPE_PLACEABLE, sPlant, lLoc, FALSE,
|
|
IntToString (iFarm) + "_" + IntToString (iPosition));
|
|
|
|
EDS_SetDelay (oPlant, "Is_Lootable", IntToFloat (GetMaxHitPoints (oPlant) * 60));
|
|
}
|
|
|
|
void main()
|
|
{
|
|
int iFarmNumber = GetLocalInt (OBJECT_SELF, "Farm_Number");
|
|
string sOwner = Farm_GetOwner (iFarmNumber);
|
|
|
|
//Make sure PC is on farmland in order to plant the crop.
|
|
if (!GetLocalInt (OBJECT_SELF, "Is_On_Farm"))
|
|
SendMessageToPC (OBJECT_SELF, "You must seek out more fertile land " +
|
|
"in order to plant crops.");
|
|
|
|
//Make sure PC is owner of this specific farm.
|
|
else if ((FindSubString (sOwner, GetPCPlayerName (OBJECT_SELF)) == -1))
|
|
SendMessageToPC (OBJECT_SELF, "You need to purchase this farmland if " +
|
|
"you wish to grow crops here.");
|
|
|
|
//Check for a shovel.
|
|
else if (!GetIsObjectValid (GetItemPossessedBy (OBJECT_SELF, "PlantersShovel")))
|
|
SendMessageToPC (OBJECT_SELF, "You need a shovel in order to dig the " +
|
|
"hole needed by the seeds.");
|
|
|
|
else if (d100() <= FARM_SHOVEL_BREAKAGE)
|
|
{
|
|
SendMessageToPC (OBJECT_SELF, "Your shovel broke while trying to " +
|
|
"dig a hole for the seeds...");
|
|
DestroyObject (GetItemPossessedBy (OBJECT_SELF, "PlantersShovel"));
|
|
}
|
|
else
|
|
{
|
|
object oBucket = GetFirstItemInInventory (OBJECT_SELF);
|
|
float fWaterUsage = 8.0f + (IntToFloat (d8()) + (1.0f / (IntToFloat (9) + 1)));
|
|
int iEnoughWater = FALSE;
|
|
|
|
//Loop through for buckets.
|
|
while (GetIsObjectValid (oBucket))
|
|
{
|
|
if ((GetTag (oBucket) == "WaterBucket") && (GetLocalFloat (oBucket, "Water_Percent_Full") >= fWaterUsage))
|
|
{
|
|
SetLocalFloat (oBucket, "Water_Percent_Full", GetLocalFloat
|
|
(oBucket, "Water_Percent_Full") - fWaterUsage);
|
|
iEnoughWater = TRUE;
|
|
break;
|
|
}
|
|
|
|
oBucket = GetNextItemInInventory();
|
|
}
|
|
|
|
if (!iEnoughWater) //Check if there is enough water to plant seeds.
|
|
{
|
|
SendMessageToPC (OBJECT_SELF, "You haven't enough water for the " +
|
|
"seeds you're attempting to plant. Try filling your water " +
|
|
"bucket with some water first.");
|
|
return;
|
|
}
|
|
|
|
//Now we can plant the crop.
|
|
location lLoc = Location (GetArea (OBJECT_SELF), GetPosition (OBJECT_SELF),
|
|
IntToFloat (Random (180) + 1));
|
|
object oSeed = GetLocalObject (OBJECT_SELF, "Item_Used");
|
|
object oHole = CreateObject (OBJECT_TYPE_PLACEABLE, "x2_plc_hole_s", lLoc);
|
|
string sResRef = GetResRef (oSeed);
|
|
string sPlant = "plant_" + GetStringRight (sResRef, GetStringLength (sResRef) - 5);
|
|
float fDelay = StringToFloat (GetTag (oSeed));
|
|
int iCount = 1;
|
|
|
|
//Find first available position to store new plant (for persistency).
|
|
while (Farm_GetPlantResRef (iFarmNumber, iCount) != "")
|
|
iCount++;
|
|
|
|
//Check if we need to update the maximum plant count.
|
|
if (iCount > Farm_GetMaxPlantNumber (iFarmNumber))
|
|
Farm_SetMaxPlantNumber (iFarmNumber, iCount);
|
|
|
|
//Store plant information for future use.
|
|
Farm_SetPlantResRef (iFarmNumber, iCount, sPlant);
|
|
Farm_SetPlantLocation (iFarmNumber, iCount, lLoc);
|
|
|
|
//Delay crop based on seed tag. Same for the created hole.
|
|
DestroyObject (oHole, fDelay);
|
|
DelayCommand (fDelay, Farm_CreateCrop (sPlant, lLoc, iFarmNumber, iCount));
|
|
|
|
//Have PC perform planting animation.
|
|
ClearAllActions();
|
|
SetFacingPoint (GetPosition (oHole));
|
|
ActionPlayAnimation (ANIMATION_LOOPING_GET_LOW, 1.0f, FARM_PLANT_DELAY);
|
|
DelayCommand (0.1f, SetCommandable (FALSE, OBJECT_SELF));
|
|
DelayCommand (FARM_PLANT_DELAY, SetCommandable (TRUE, OBJECT_SELF));
|
|
|
|
DestroyObject (GetLocalObject (OBJECT_SELF, "Item_Used"));
|
|
}
|
|
}
|