Imported from archive.
[mudpy.git] / lib / muff / muffmisc.py
index d2848b2..749af91 100644 (file)
@@ -3,6 +3,8 @@
 # Copyright (c) 2005 mudpy, Jeremy Stanley <fungi@yuggoth.org>, all rights reserved.
 # Licensed per terms in the LICENSE file distributed with this software.
 
+import ConfigParser
+
 # used by several functions for random calls
 import random
 
@@ -147,7 +149,14 @@ def repr_long(value):
        else: return string_value
 
 def getlong(config, section, option):
-       return int(config.get(section, option).strip("L"))
+       try:
+               return int(config.get(section, option).strip("L"))
+       except ConfigParser.NoSectionError:
+               config.add_section(section)
+               return getlong(config, section, option)
+       except ConfigParser.NoOptionError:
+               setlong(config, section, option, 0)
+               return getlong(config, section, option)
 
 def setlong(config, section, option, value):
        return config.set(section, option, repr_long(value))
@@ -165,6 +174,33 @@ def replace_macros(user, text, is_input=False):
                elif macro == "$(account)":
                        text = string.replace(text, macro, user.name)
 
+               # third person subjective pronoun
+               elif macro == "$(tpsp)":
+                       if user.avatar.get("gender") == "male":
+                               text = string.replace(text, macro, "he")
+                       elif user.avatar.get("gender") == "female":
+                               text = string.replace(text, macro, "she")
+                       else:
+                               text = string.replace(text, macro, "it")
+
+               # third person objective pronoun
+               elif macro == "$(tpop)":
+                       if user.avatar.get("gender") == "male":
+                               text = string.replace(text, macro, "him")
+                       elif user.avatar.get("gender") == "female":
+                               text = string.replace(text, macro, "her")
+                       else:
+                               text = string.replace(text, macro, "it")
+
+               # third person possessive pronoun
+               elif macro == "$(tppp)":
+                       if user.avatar.get("gender") == "male":
+                               text = string.replace(text, macro, "his")
+                       elif user.avatar.get("gender") == "female":
+                               text = string.replace(text, macro, "hers")
+                       else:
+                               text = string.replace(text, macro, "its")
+
                # if we get here, log and replace it with null
                else:
                        text = string.replace(text, macro, "")
@@ -203,6 +239,7 @@ def on_pulse():
        if check_time("frequency_save"):
                muffvars.save()
                for user in muffvars.userlist: user.save()
+               muffuniv.universe.save()
 
        # pause for a configurable amount of time (decimal seconds)
        time.sleep(muffconf.getfloat("time", "increment"))