[Package Index | Mudlib Index | Effect Index]

File /d/cwc/families/handlers/cwc_mission_handler.c

The CWC Mission system is made up of three files. This Handler, the mission_controller inherit, and the mission_chit inherit.

How It works

when a player says "mission" in front of the mission_controller npc the handler checks the directory "/d/cwc/families/handlers/mission" for the existance of files named *_chit.c, it will also checks two subdirectories, family_name and guild_name depending on what guild and family the player belongs too. If you are a creator and say "cretest" the handler will only look in the "mission_dev" subdirectory. This is allow creators to test missions they are working on.

When the handler has retrieved the list of all files available to the player, it subtracts the last three missions the player has done and then select one at random. The handler then goes through a check and decides what family to send the player against. It does this whether the mission needs a terget family or not. Finally it clones the chit and calls:-

setup_mission_data(string player,string faction,string target_family)

on it. Finally it moves the chit to the player and returns the setup string from the chit to the mission_controller npc, so the they can tell the player.

right the handler has done its work and thats all you need to know about it for the moment. Now on to the mission_chit.

The Mission chit must have the following :-

  1. inherit "/d/cwc/families/handlers/mission/inherit/chit"
  2. call ::init() in init()
  3. have add_property("mission_value",int); in setup()
  4. have a function string setup_mission(string,string,string) which includes

more about setup_mission

The setup_mission function will be called by the mission_handler with three string values:-

you need to pass these values to the to setup_mission_base this allows the chit to remember som key values. These values can be accessed through the following functions:-

The last one query_mission_time() can be compared against query_player_data_key(query_player(),"missiondata")*["mission time"]) to ensure this chit is for the mission the player is actually on.

Ok, but what about variables you want to add, e.g the room the player needs to go through. well you can use set_mission_data_item(string item, mixed value) to add new variables to the chit, these will automatically be restored if the player logs off and will be recreated by the handler should the chit need be replaced. You can store anything you like in there except objects. You can access these variables using query_mission_data(string item).

Chit replacement

Normally the handler will do all that you need to do when the chit is replaced. However should you need to so something special, like clone a npc for the player to find, then you will need to overload :-

void replace_chit(mapping mission_data)

The mapping mission_data contains all the variables for the mission, including, the player so teh first line of the overload should be ::replace_chit(mission_data), this will allow query_player(), query_mission_data etc to work.

You can have variables that are not restored when the mission chit is replaced, if so make sure you overload query_dynamic_auto_load() and init_dynamic_arg properly.

Completing Missions

Your can complete the missions in one of two ways. calling add_property("mission_complete",1) on the chit and telling the Player to give it the the mission_controller npc. Or calling close_mission(playername,1) on the handler. Calling close_mission(playername,0) will fail the mission.

One final function on the handler worth mentioning is:-

void add_object_to_delete(string obj,int delay,string msgin,string msgout)

Sometimes when writing a mission, you will want to clone objects on the fly. this functions allows you to mark them for deletion at a later date. The handler will take care of moving them /room/rubbish etc.

Some Examples

/d/cwc/families/handlers/mission/investigate_chit.c

Very basic mission, good place to start. chit needs to be returned.

/d/cwc/families/handlers/mission/graffiti_chit.c

Example of cloning objects on the fly which are marked for deletion later by the handler, auto succeeds

/d/cwc/families/handlers/mission/graffiti_chit.c

more complicated example with over loads to replace_chit, query_dynamic_auto_load and init_dynamic_arg, auto succeeds/fails

Written by Noir

Started January 2006

Includes

This class includes the following files /include/move_failures.h, /d/cwc/families/handlers/path.h, /include/shops/bank.h and /include/money.h

Method index

Public Functions

These are functions that everyone can access.

cap_family
string cap_family(string fam)

return proper capitalization for BP family. ( damn McSweeneys)
close_mission
int close_mission(string player,
                  int succeeded)

close mission for a player with success or failure, call this from a chit to close a mission
delete_player
int delete_player(string player)

remove a player from the mapping, call it to delete old records

Parameters:
player - name of the player

Returns:
1 for success, 0 for failure


delete_player_data
int delete_player_data(string player,
                       string thekey)

remove a single key for a player from the mapping, call it to delete key values

Parameters:
player - name of the player
thekey - name of key to remove

Returns:
1 for success, 0 for failure


is_family_member
int is_family_member(string playername,
                     string ufid)

returns true if player is a member of the Family
query_cap_families
string * query_cap_families()

List all the families capitalised
query_families
string * query_families()

List all the families
query_player_data
mapping query_player_data(string player)



Parameters:
player - name of player

Returns:
mapping of all the data for a single player


query_player_data_key
mixed query_player_data_key(string player,
                            string thekey)



Parameters:
player - name of the player
thekey - the name of the key you want the data for

Returns:
data for a single player for one key


query_players
string * query_players()



Returns:
an array of all the playernames currently stored in the mapping


return_all_data
mapping return_all_data()



Returns:
The full _data mapping, use with caution


set_player_data_key
int set_player_data_key(string player,
                        string thekey,
                        mixed thedata)

set a piece of data for a single key

Parameters:
player - name of the player
thekey - the name of the key you want to set the data for
thedata - value you want to set

Returns:
1 for success 0 for failure