9 """A class the provides a query mechanism, for each
10 instance, that will return the specified system's
11 faction, name, or parent sector."""
22 """Returns the information corresponding to the
23 given class variable."""
25 [sec, sys] = self.system.split(
'/')
31 elif inf_type == self.
SECTOR:
35 elif inf_type == self.
SYSTEM:
40 raise ValueError(
"Invalid information type specified")
44 newname=VS.LookupUnitStat(oldname,faction,
"Name")
51 """Provides functions that handle the translation of a
52 news item using a relevant event tuple."""
53 STARDATE_TEXT =
"\\\\\\\This story was first broadcast on: "
62 """Returns the information corresponding to the
63 given var and tag pair."""
65 return self.
vars[var][tag]
68 results = self.dynamic_data.getFactionData(self.
vars[var][
'faction'], tag)
70 st =
'ERROR_%s_%s'%(var,tag)
72 results=[
'ERROR_%s_%s'%(var,tag)]
73 return results[self.
rand_int % len(results)]
76 """Determines if the word given is a variable set,
77 and if so returns the substitute information."""
78 if word.find(
'VAR_') == -1:
81 [pre,var,tag] = word.split(
"_")
84 pre = pre[:pre.find(
'VAR')]
87 if letter
not in string.punctuation:
94 """Using the given item and information, returns a
95 fully translated version of the item."""
96 self.
rand_int = news_tuple[NewsManager.RANDOM_INTEGER_INDEX]
100 if news_tuple[NewsManager.STARDATE_INDEX] == 0:
101 stardat_[
'value'] = VS.getStarTime()
103 stardat_[
'value'] = news_tuple[NewsManager.STARDATE_INDEX]
104 self.
vars[
'stardate'] = stardat_
106 aggressor[
'faction'] = news_tuple[NewsManager.AGGRESSOR_INDEX]
107 aggressor[
'FG'] = news_tuple[NewsManager.AGGRESSOR_FLIGHTGROUP_INDEX]
108 aggressor[
'FGtype'] =
LookupRealName(news_tuple[NewsManager.AGGRESSOR_SHIPTYPE_INDEX],aggressor[
'faction'])
109 self.
vars[
'aggressor'] = aggressor
111 defender[
'faction'] = news_tuple[NewsManager.DEFENDER_INDEX]
112 defender[
'FG'] = news_tuple[NewsManager.DEFENDER_FLIGHTGROUP_INDEX]
113 defender[
'FGtype'] =
LookupRealName(news_tuple[NewsManager.DEFENDER_SHIPTYPE_INDEX],defender[
'faction'])
114 self.
vars[
'defender'] = defender
116 dockeda_[
'faction'] = docked_faction
117 self.
vars[
'dockedat'] = dockeda_
120 syste_[
'system'] = system.getInfo(system.SYSTEM)
121 syste_[
'sector'] = system.getInfo(system.SECTOR)
122 self.
vars[
'system'] = syste_
123 for i
in range(len(self.
item)):
127 def formatText(self, text, punc=[' ' , '_' , '.'], capitalise=True):
128 """Runs a quick formatting algorithm over the
129 provided text, using the punc list as a guide to
132 tex = text.split(pun)
133 for i
in range(len(tex)):
142 """Each instance of this class acts as an accessor to
143 the faction specific information stored for the purpose
144 of translating news stories."""
146 import dynamic_news_content
151 """Return the variable information stored for this
158 debug.error(
"ERROR: FACTION LOOKUP ERROR faction %s variable %s" % (faction, variable))
161 debug.error(
"ERROR: VARIABLE LOOKUP ERROR faction %s variable %s" % (faction, variable))
162 return "VARIABLE LOOKUP ERROR"
165 """Translates the information from the stored
166 values to those used to lookup items in the item
169 if variable == NewsManager.KEYWORD_DEFAULT:
171 elif variable == NewsManager.TYPE_SIEGE:
173 elif variable == NewsManager.TYPE_EXPLORATION:
174 replace =
"exploration"
175 elif variable == NewsManager.TYPE_BATTLE:
177 elif variable == NewsManager.TYPE_FLEETBATTLE:
178 replace =
"fleetbattle"
179 elif variable == NewsManager.TYPE_DESTROYED:
180 replace =
"destroyed"
181 elif variable == NewsManager.STAGE_BEGIN:
183 elif variable == NewsManager.STAGE_MIDDLE:
185 elif variable == NewsManager.STAGE_END:
187 elif variable == NewsManager.SUCCESS_WIN:
189 elif variable == NewsManager.SUCCESS_DRAW:
191 elif variable == NewsManager.SUCCESS_LOSS:
193 elif variable == NewsManager.POV_GOOD:
195 elif variable == NewsManager.POV_BAD:
197 elif variable == NewsManager.POV_NEUTRAL:
200 raise TypeError(
"Unrecognised variable")
204 """Creates a list of the structure used to store
207 key_list.append(news_faction)
208 key_list.append(news_list[NewsManager.EVENT_TYPE_INDEX])
209 key_list.append(news_list[NewsManager.EVENT_STAGE_INDEX])
215 """Searches the item dictionary to find matching
216 items for this given event."""
220 key_list[0] =
"neutral"
222 story_list = story_list[key]
228 """From the provided list of stories, return the
229 item who's \"scale\" most closely matches that of
230 the given event (minimise variance)."""
232 for story
in stories:
233 if story[1] == varlist[NewsManager.EVENT_KEYWORD_INDEX]:
234 kw_stories.append(story)
235 if not len(kw_stories):
236 debug.error(
"ERROR: NO KEYWORD STORIES AVAILABLE FOR "+
str(varlist))
238 if len(kw_stories) == 1:
240 scale_stories = list()
241 scale_stories.append(kw_stories[0])
242 diff = abs(int(1000*scale_stories[0][0]) - int(1000*varlist[NewsManager.EVENT_SCALE_INDEX]))
244 for story
in kw_stories:
245 if abs(int(1000*scale_stories[0][0]) - int(1000*varlist[NewsManager.EVENT_SCALE_INDEX])) < diff:
246 scale_stories = list()
247 scale_stories.append(story)
248 elif abs(int(1000*scale_stories[0][0]) - int(1000*varlist[NewsManager.EVENT_SCALE_INDEX])) == diff:
249 scale_stories.append(story)
250 return scale_stories[varlist[NewsManager.RANDOM_INTEGER_INDEX] % len(scale_stories)]
253 """This class is used to manage dynamic news, it is
254 designed to be used as a global object, but can be used
257 RANDOM_INTEGER_INDEX = 0
260 EVENT_STAGE_INDEX = 3
263 AGGRESSOR_SUCCESS_INDEX = 6
264 EVENT_SCALE_INDEX = 7
265 EVENT_SYSTEM_INDEX = 8
266 EVENT_KEYWORD_INDEX = 9
267 AGGRESSOR_FLIGHTGROUP_INDEX = 10
268 AGGRESSOR_SHIPTYPE_INDEX = 11
269 DEFENDER_FLIGHTGROUP_INDEX = 12
270 DEFENDER_SHIPTYPE_INDEX = 13
272 KEYWORD_DEFAULT =
"all"
275 TYPE_EXPLORATION =
"exploration"
276 TYPE_BATTLE =
"battle"
277 TYPE_FLEETBATTLE =
"fleetbattle"
278 TYPE_DESTROYED =
"destroyed"
280 STAGE_BEGIN =
"start"
281 STAGE_MIDDLE =
"middle"
301 """Takes an argument, of type str (this is not checked),
302 that is of the same format as that stored by
303 self.writeDynamicString(varlist)"""
308 stories = self.data.getNewsList(keys)
310 stories = self.data.getNewsList(keys,
True)
313 item = self.data.getBestMatch(stories, varlist)
320 """Returns the corresponding POV_* class variable
321 for the reaction of the dockedat faction to the status
325 success = varlist[NewsManager.AGGRESSOR_SUCCESS_INDEX]
328 elif relatdef > relatagg:
335 elif relatdef < relatagg:
343 debug.debug(
"ERROR: VS is returning -0 for relationship relatagg number")
347 """Converts a stored dynamic news string into a
348 variable list usable by other methods and classes."""
349 varlist = s.split(
',')
356 """Updates the current self.dockedat_faction to its
357 current value. Should be called before translating
358 a batch of stores."""
364 if (un.isDocked(playa)
or playa.isDocked(un)):
365 if not (un.isPlanet()
or (un.getFactionName() ==
"neutral")):
366 fac = un.getFactionName()
370 retfac = VS.GetGalaxyFaction(VS.getSystemFile())
375 """Is the event in this string relevant to the current
376 system and dockedat faction?"""
384 syslist = [VS.getSystemFile()]
385 done_syslist = list()
387 if event_sys
in syslist:
390 done_syslist+=syslist
393 for i
in range(VS.GetNumAdjacentSystems(syst)):
394 sy = VS.GetAdjacentSystem(syst,i)
395 if sy
not in done_syslist:
396 new_syslist.append(sy)
397 syslist = new_syslist
402 """Stores a news story list into the \"dynamic news\"
403 key in the save game."""
406 Director.pushSaveString(0,
"dynamic_news",varlist)