Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
DynamicNewsData Class Reference

Public Member Functions

def __init__
 
def getFactionData
 
def translateKeyToDictionary
 
def makeNewsKeyList
 
def getNewsList
 
def getBestMatch
 

Data Fields

 faction_dict
 
 news_dict
 

Detailed Description

Each instance of this class acts as an accessor to
the faction specific information stored for the purpose
of translating news stories.

Definition at line 141 of file dynamic_news.py.

Constructor & Destructor Documentation

def __init__ (   self)

Definition at line 145 of file dynamic_news.py.

146  def __init__(self):
147  import dynamic_news_content

Member Function Documentation

def getBestMatch (   self,
  stories,
  varlist 
)
From the provided list of stories, return the
item who's \"scale\" most closely matches that of
the given event (minimise variance).

Definition at line 227 of file dynamic_news.py.

References debug.error, and locale.str().

228  def getBestMatch(self, stories, varlist):
229  """From the provided list of stories, return the
230  item who's \"scale\" most closely matches that of
231  the given event (minimise variance)."""
232  kw_stories = list()
233  for story in stories:
234  if story[1] == varlist[NewsManager.EVENT_KEYWORD_INDEX]:
235  kw_stories.append(story)
236  if not len(kw_stories):
237  debug.error("ERROR: NO KEYWORD STORIES AVAILABLE FOR "+str(varlist))
238  return False
239  if len(kw_stories) == 1:
240  return kw_stories[0]
241  scale_stories = list()
242  scale_stories.append(kw_stories[0])
243  diff = abs(int(1000*scale_stories[0][0]) - int(1000*varlist[NewsManager.EVENT_SCALE_INDEX]))
244  kw_stories.pop(0)
245  for story in kw_stories:
246  if abs(int(1000*scale_stories[0][0]) - int(1000*varlist[NewsManager.EVENT_SCALE_INDEX])) < diff:
247  scale_stories = list()
248  scale_stories.append(story)
249  elif abs(int(1000*scale_stories[0][0]) - int(1000*varlist[NewsManager.EVENT_SCALE_INDEX])) == diff:
250  scale_stories.append(story)
251  return scale_stories[varlist[NewsManager.RANDOM_INTEGER_INDEX] % len(scale_stories)]
def getFactionData (   self,
  faction,
  variable 
)
Return the variable information stored for this
faction.

Definition at line 150 of file dynamic_news.py.

References debug.error, and DynamicNewsData.faction_dict.

151  def getFactionData(self, faction, variable):
152  """Return the variable information stored for this
153  faction."""
154  if variable in self.faction_dict["alltags"]:
155  try:
156  return self.faction_dict[faction][variable]
157  except:
158  # raise ValueError("Invalid Faction Specified")
159  debug.error("ERROR: FACTION LOOKUP ERROR faction %s variable %s" % (faction, variable))
160  return self.faction_dict['unknown'][variable]
161  else:
162  debug.error("ERROR: VARIABLE LOOKUP ERROR faction %s variable %s" % (faction, variable))
163  return "VARIABLE LOOKUP ERROR"
def getNewsList (   self,
  key_list,
  get_neutral = False 
)
Searches the item dictionary to find matching
items for this given event.

Definition at line 214 of file dynamic_news.py.

References DynamicNewsData.news_dict.

215  def getNewsList(self, key_list, get_neutral=False):
216  """Searches the item dictionary to find matching
217  items for this given event."""
218  story_list = self.news_dict
219  try:
220  if get_neutral:
221  key_list[0] = "neutral"
222  for key in key_list:
223  story_list = story_list[key]
224  except:
225  return list()
226  return story_list
def makeNewsKeyList (   self,
  news_list,
  news_faction,
  pov 
)
Creates a list of the structure used to store
each news event.

Definition at line 203 of file dynamic_news.py.

References DynamicNewsData.translateKeyToDictionary().

204  def makeNewsKeyList(self, news_list, news_faction, pov):
205  """Creates a list of the structure used to store
206  each news event."""
207  key_list = list()
208  key_list.append(news_faction)
209  key_list.append(news_list[NewsManager.EVENT_TYPE_INDEX])
210  key_list.append(news_list[NewsManager.EVENT_STAGE_INDEX])
211  key_list.append(self.translateKeyToDictionary(news_list[NewsManager.AGGRESSOR_SUCCESS_INDEX]))
212  key_list.append(self.translateKeyToDictionary(pov))
213  return key_list
def translateKeyToDictionary (   self,
  variable 
)
Translates the information from the stored
values to those used to lookup items in the item
dictionary.

Definition at line 164 of file dynamic_news.py.

165  def translateKeyToDictionary(self, variable):
166  """Translates the information from the stored
167  values to those used to lookup items in the item
168  dictionary."""
169  replace = ""
170  if variable == NewsManager.KEYWORD_DEFAULT:
171  replace = "all"
172  elif variable == NewsManager.TYPE_SIEGE:
173  replace = "siege"
174  elif variable == NewsManager.TYPE_EXPLORATION:
175  replace = "exploration"
176  elif variable == NewsManager.TYPE_BATTLE:
177  replace = "battle"
178  elif variable == NewsManager.TYPE_FLEETBATTLE:
179  replace = "fleetbattle"
180  elif variable == NewsManager.TYPE_DESTROYED:
181  replace = "destroyed"
182  elif variable == NewsManager.STAGE_BEGIN:
183  replace = "start"
184  elif variable == NewsManager.STAGE_MIDDLE:
185  replace = "middle"
186  elif variable == NewsManager.STAGE_END:
187  replace = "end"
188  elif variable == NewsManager.SUCCESS_WIN:
189  replace = "success"
190  elif variable == NewsManager.SUCCESS_DRAW:
191  replace = "draw"
192  elif variable == NewsManager.SUCCESS_LOSS:
193  replace = "loss"
194  elif variable == NewsManager.POV_GOOD:
195  replace = "good"
196  elif variable == NewsManager.POV_BAD:
197  replace = "bad"
198  elif variable == NewsManager.POV_NEUTRAL:
199  replace = "neutral"
200  else:
201  raise TypeError("Unrecognised variable")
202  return replace

Field Documentation

faction_dict

Definition at line 147 of file dynamic_news.py.

news_dict

Definition at line 148 of file dynamic_news.py.


The documentation for this class was generated from the following file: