blib/lib/auto/share/dist/Games-Axmud/plugins/convertlpc.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 47 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
END
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/perl
2 package convertlpc;
3 #: Version: 1.0
4 #: Description: Converts world model into LPC
5 #: Author: A S Lewis
6 #: Copyright: This plugin is in the public domain, but you are encouraged to share any modifications
7 # and improvements you make!
8  
9 # =-=-=-=-=-=-=-=-=-=
10 # PLUGIN INSTRUCTIONS
11 # =-=-=-=-=-=-=-=-=-=
12 #
13 # This plugin can be used to convert the contents of the current world model (which stores the
14 # maps you've drawn in the Automapper window) into LPC files; specifically those used by the
15 # DeadSouls mudlib.
16 # The new LPC files can then be copied onto the machine on which the MUD is running.
17 # Simply re-start the MUD and - hey presto! - the contents of your maps will appear in the MUD,
18 # as if by magic.
19 #
20 # This plugin produces LPC files for rooms and objects using a standard format, but if you have an
21 # understanding of Perl, you can easily modify the plugin code to make it produce files in a
22 # different format.
23 # You could also modify the plugin to produce LPC files for other LPC mudlibs, or for other code
24 # bases altogether.
25 #
26 # This is a step-by-step guide for doing your first conversion. (Since you have access to MUD
27 # code, we're assuming that you possess basic computer skills such as copying files and
28 # navigating through directories/folders.)
29 #
30 # 1. First, connect to the world in OFFLINE mode, as very large maps will take a long time to
31 # convert, and you won't be able to type commands during this process. (If you're an admin
32 # user at the world who is unlikely to be attacked by NPCs, then of course you can connect in
33 # online mode.)
34 #
35 # 2. Load the plugin using this (client) command:
36 #
37 # ;loadplugin -s
38 #
39 # It might be more convenient to have the plugin load every time you start Axmud, in which case
40 # you should use this command:
41 #
42 # ;addinitialplugin -s
43 #
44 # If you have copied the plugin to Axmud's data folder, because you want to modify it for your
45 # own purposes, then don't use the -s switch
46 #
47 # ;loadplugin
48 # ;addinitialplugin
49 #
50 # 3. Convert your world model into LPC files with this command:
51 #
52 # ;convertlpc
53 #
54 # 4. The LPC files are stored in your usual data directory (folder). For a normal Axmud
55 # installation on a Linux machine, it will be something like:
56 #
57 # /home/<your name>/axmud-data/clpc_output
58 #
59 # 5. Navigate into the .../clpc_output/<world_name>/domains directory, and you'll find a list
60 # of sub-directories, one for each region in your world model.
61 #
62 # 6. Copy all of these directories onto the machine on which the MUD is running. On a DeadSouls
63 # installation, they should be copied into the .../ds/lib/domains directory.
64 #
65 # 7. Restart the MUD (or update the mudlib in the usual way). As if by magic, the contents of your
66 # world model will appear in the MUD, ready to be played!
67 #
68 # Now you can modify this plugin to suit your requirements.
69 #
70 # 8. Before modifying anything, it would be a good idea to copy the plugin into your data
71 # directory. There's a 'plugins' directory there which Axmud will not disturb, even if you
72 # update or re-install Axmud. (You need to copy both this file and the '_convertlpc_cmds.pm'
73 # file.)
74 #
75 # 9. (If you used the ';addinitialplugin' command earlier, you should now use the
76 # ';deleteinitialplugin' command for the plugin at its old location, before using the
77 # ';addinitialplugin' command to add the plugin at its new location.)
78 #
79 # 10. Look through the global variables in this file. You can modify any of them which aren't
80 # marked 'DO NOT MODIFY!'
81 #
82 # 11. The conversion code is in the '_convertlpc_cmds.pm' file, which is loaded automatically
83 # whenever this plugin is loaded.
84 #
85 # 12. If you want to change the format of the converted LPC files, you can modify any of the
86 # following subroutines, following the pattern of the existing code:
87 #
88 # ->prepareRoom
89 # ->prepareWeapon
90 # ->prepareArmour
91 # ->prepareGarment
92 # ->prepareSentient
93 # ->prepareCreature
94 # ->preparePortable
95 # ->prepareDecoration
96 #
97 # 13. It's VERY unlikely that you will need to modify any other subroutines.
98 #
99 # 14. Perl modules can't be unloaded or re-loaded, so you will need to restart Axmud before trying
100 # to use the modified code.
101 #
102 # 15. The world model is stored in various Perl objects (rooms are represented by
103 # GA::ModelObj::Room objects, sentient NPCS by GA::ModelObj::Sentient objecs, and so on).
104 # If you need to refer to this code, in order to see exactly what information is stored
105 # by the world model and how it is stored, you can look at this file:
106 #
107 # .../axmud/lib/world_model_objs.pm
108  
109 use strict;
110 #use diagnostics;
111 use warnings;
112  
113 # Modules used by this plugin
114 require _convertlpc_cmds;
115  
116 # Standard BEGIN / END functions
117 BEGIN {
118  
119 use Glib qw(TRUE FALSE);
120  
121 # Global variables (for the plugin)
122 use vars qw(
123 $CONVERT_TYPE $DIRECTORY $NO_ERROR_FLAG $MAX_FILES $MAX_FILE_NAME_SIZE $UPDATE_COUNT
124 $NEST_DIRECTORIES_FLAG $NO_UNDERLINE_FLAG $MAX_WORDS $NULL_OBJ_DESCRIP $DEFAULT_WEIGHT
125 $DEFAULT_CURRENCY $DEFAULT_VALUE $SENTIENT_DEFAULT_RACE $CREATURE_DEFAULT_RACE
126 $DEFAULT_GENDER
127 @COPYRIGHT_LIST @CATEGORY_LIST
128 %REMOVE_HASH %SPECIAL_NAME_HASH %DIRECTORY_HASH %CATEGORY_HASH
129 );
130  
131 # If you want error messages (etc) to show something other than 'LPC', change this variable
132 $CONVERT_TYPE = 'LPC';
133 # All converted LPC files saved to this directory
134 $DIRECTORY = $axmud::DATA_DIR . '/clpc_output';
135 # Flag set to TRUE if the ';convertlpc' command should give up at the first error, FALSE if it
136 # should continue (if possible)
137 $NO_ERROR_FLAG = TRUE;
138 # Max number of LPC files to convert before giving up
139 $MAX_FILES = 100000;
140 # Max characters in each file name (not including the number added to differentiate objects
141 # with the same name, e.g. 'start4.c', and not including the .c)
142 $MAX_FILE_NAME_SIZE = 32;
143 # Show a message in the 'main' window after converting this many files (set to 0 to avoid
144 # showing updates)
145 $UPDATE_COUNT = 1000;
146 # Flag set to TRUE if the LPC directory corresponding to a world model region should be nested
147 # inside the directory of its parent region; set to FALSE if every world model region has an
148 # LPC directory in /clpc_output/<world>/domains/
149 $NEST_DIRECTORIES_FLAG = TRUE;
150 # Directory/file names don't contain underline characters in place of whitespace; instead,
151 # whitespace is removed entirely (e.g. 'big white house' > 'bigwhitehouse')
152 $NO_UNDERLINE_FLAG = TRUE;
153 # If set to 0, the whole room title (brief description) is used for the converted file name. For
154 # other model objects, the whole of the object's base string is used
155 # If set to a positive integer, only that many words are used (not including any of the words
156 # stored in %REMOVE_HASH, which are removed in any case)
157 # e.g. 'big white house' > 'bigwhite' (if this variable is set to 2)
158 $MAX_WORDS = 2;
159 # Hash of words that should be removed from the room title or the object base string, when
160 # deciding its corresponding filename. Removeable words are stored as keys in the hash; the
161 # corresponding values are ignored.
162 # To stop word removal altogether, simply empty this hash. Otherwise, add or remove words as
163 # you please
164 %REMOVE_HASH = (
165 # Articles
166 'a' => undef,
167 'an' => undef,
168 'the' => undef,
169 # Prepositions
170 'above' => undef,
171 'at' => undef,
172 'below' => undef,
173 'for' => undef,
174 'in' => undef,
175 'of' => undef,
176 'off' => undef,
177 'onto' => undef,
178 'to' => undef,
179 'with' => undef,
180 'without' => undef,
181 );
182 # When converting model objects (other than rooms), if the object doesn't contain a description,
183 # this string is used as the description
184 $NULL_OBJ_DESCRIP = 'This object that hasn\'t been described yet.';
185 # Default mass for model objects
186 $DEFAULT_WEIGHT = 100;
187 # Default value and currency for model objects
188 $DEFAULT_CURRENCY = 'silver';
189 $DEFAULT_VALUE = 10;
190 # Default race/gender for 'sentient' and 'creature' objects
191 $SENTIENT_DEFAULT_RACE = 'human';
192 $CREATURE_DEFAULT_RACE = 'orc';
193 $DEFAULT_GENDER = 'male';
194 # List of lines added to the beginning of every file, typically used for copyright messages and
195 # other such comments
196 @COPYRIGHT_LIST = (
197 '/* Copyright (C) 2016 The Gods of DeathMud */',
198 '/* See the file /copyright.txt */',
199 );
200 # Hash of world model region names (stored as keys), and the corresponding directory names
201 # (stored as values), in case you don't want this plugin to decide the name of the directory
202 # for one or more regions
203 %SPECIAL_NAME_HASH = (
204 # 'Northern desert' => 'ndesert', # Save this domain in .../<world>/domains/ndesert/
205 );
206 # Each world model region has its own directory, and each directory typically has
207 # sub-directories for each type of object - rooms in one sub-directory, weapons in another,
208 # and so-on
209 # The keys in the hash represent model object categories, and they should not be changed (nor
210 # should you remove or add extra keys, unless of course you're willing to change the rest of
211 # the plugin code yourself)
212 # Each key's corresponding value is the sub-directory used by the DeadSouls mudlib to store this
213 # type of object; you can change these if you want (e.g. change the value 'npc' to 'mon', if
214 # you want all sentients and creatures to be stored in a sub-directory called 'mon'), but
215 # don't change the value to an empty string or 'undef'
216 %DIRECTORY_HASH = (
217 'room' => 'room',
218 'weapon' => 'weap',
219 'armour' => 'armor',
220 'garment' => 'armor',
221 'sentient' => 'npc',
222 'creature' => 'npc',
223 'portable' => 'obj',
224 'decoration' => 'obj',
225 );
226 # Corresponding hash, which tells the plugin which categories of model object should be
227 # converted. Once again, the keys must not be modified, but you can change any of the TRUE
228 # values to FALSE to prevent them from being written
229 %CATEGORY_HASH = (
230 'room' => TRUE,
231 'weapon' => TRUE,
232 'armour' => TRUE,
233 'garment' => TRUE,
234 'sentient' => TRUE,
235 'creature' => TRUE,
236 'portable' => TRUE,
237 'decoration' => TRUE,
238 );
239 # List of model object categories in the order they're written. DO NOT MODIFY THIS LIST.
240 @CATEGORY_LIST = (
241 'weapon',
242 'armour',
243 'garment',
244 'sentient',
245 'creature',
246 'portable',
247 'decoration',
248 # (Rooms are always created last, so that the LPC files can contain the room's inventory)
249 'room',
250 );
251 }
252  
253 END {}
254  
255 # Add client commands
256 $axmud::CLIENT->addPluginCmds(
257 'convertlpc',
258 '@convertlpc plugin',
259 'ConvertLPC'
260 );
261  
262 # Package must return a true value
263 1