Saturday, 24 September 2011

Evolution of the code #2

The items
In fallout there are two main types of items.

- The ones that are useless when holding - much like the rocks, or if anyone can remember the magic 8 ball from fallout 2 which i will attempt at remaking later on.

- Consumable item. This means anything that "uses" something in order to have an effect. For example health items can only be used a few times or the weapons which use ammo unless they are reloaded.

Therefore the base classes of the items should be split as such. This leads us to the following chart:
 Although all items are derived from the multiple action class it is because the item actions are defined in the class type file. I found this useful as in each item action we store the action text which shows on the HUD and the number of action points it takes. For example a weapon would read like this:

actionModes
{
item
{
actionPoints = 4
useText = SINGLE
}
item
{
actionPoints = 6
useText = BURST
}
item
{
actionPoints = 2
useText = RELOAD
}
}

The magic ball
Basically it is an entity that stores an array of strings and prints a random string when it is clicked on. Since there is no baseclass that does this, i had to create a separate item class for it:

public class StringListItemType : MultipleActionItemType
{
[FieldSerialize]
string[] stringList;

public string[] StringList
{
get { return stringList; }
set { stringList = value; }
}
}

public class StringListItem : MultipleActionItem
{
StringListItemType _type = null; public new StringListItemType Type { get { return _type; } }

public string GetRandomString()
{
int index = new Random().Next(0, Type.StringList.Length);
return Type.StringList[index];
}
}
Simple enough, right? Let's take a look at the type file:

type IT_8ball
{
class = StringListItem
soundTake = Types\VBEntities\InventoryItems\HealthItems\Health.ogg
physicsModel = "Types\\Dynamic\\SmallBox\\SmallBox.physics"
allowEditorCreate = True
networkType = Network
attachedObjects
{
mesh
{
meshName = Types\Items\BulletItems\SubmachineGunBulletsItem\SubmachineGunBulletsItem.mesh
castShadows = True
scale = "0.5 0.5 0.5"
}
}
weight = 2
itmvalue = 3000
invIcon = Gui\HUD\interface\inventory\ITEMS\IT_8ball_INV.tga
actIcon = Gui\HUD\interface\inventory\ITEMS\IT_8ball_INV.tga
stringList
{
item
{
value = What kind of an asshole question is that?
}
[...]
item
{
value = Your hands are warm.
}
}
actionModes
{
item
{
actionPoints = 2
useText = SHAKE
}
}
And after putting it all together this was the result:


Now what else should we look for with these useless items? Well if we have an ammo type in our hand we should try and reload the first weapon in our inventory which uses it.

Weapons and health items
In order to create weapons, grenades, heath kits and other items we simply use different base classes.

No comments:

Post a Comment