成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Paradox 的數(shù)據(jù)文件格式

開發(fā) 開發(fā)工具
Paradox 是我很喜歡的一個游戲公司,在所謂 P 社 5 萌中,十字軍之王和鋼鐵雄心都只有淺嘗,但在維多利亞和群星上均投入了大量時間和精力。

[[201283]]

Paradox 是我很喜歡的一個游戲公司,在所謂 P 社 5 萌中,十字軍之王和鋼鐵雄心都只有淺嘗,但在維多利亞和群星上均投入了大量時間和精力。 這些游戲基于同一套引擎,所以數(shù)據(jù)文件格式也是共通的。P 社開放了 Mod ,允許玩家來修改游戲,所以數(shù)據(jù)文件都是明文文本存放在文件系統(tǒng)中,這給了我們一個極好的學(xué)習(xí)機(jī)會:對于游戲從業(yè)者,我很有興趣看看成熟引擎是如何管理游戲數(shù)據(jù)和游戲邏輯的。

據(jù)我所接觸到的國內(nèi)游戲公司,包括我們自己公司在內(nèi),游戲數(shù)據(jù)大都是基于 excel 這種二維表來表達(dá)的。我把它稱為 csv 模式。這種模式的特點是,基礎(chǔ)數(shù)據(jù)結(jié)構(gòu)基于若干張二維表,每張表有不確定的行數(shù),但每行有固定了列數(shù)。用它做基礎(chǔ)數(shù)據(jù)結(jié)構(gòu)的缺陷是很明顯的,比如它很難表達(dá)樹狀層級結(jié)構(gòu)。這往往就依賴做一個中間層,規(guī)范一些使用格式,在其上模擬出復(fù)雜數(shù)據(jù)結(jié)構(gòu)。

另一種在軟件行業(yè)廣泛使用的基礎(chǔ)數(shù)據(jù)結(jié)構(gòu)是 json/xml 模式。json 比 xml 要簡單。它的特點就是定義了兩種基礎(chǔ)的復(fù)合結(jié)構(gòu),字典和數(shù)組,允許結(jié)構(gòu)嵌套。基于這種模式管理游戲數(shù)據(jù)的我也見過一些。不過對于策劃來說,編輯樹結(jié)構(gòu)的數(shù)據(jù)終究不如 excel 拉表方便。查看起來也沒有特別好的可視化工具,所以感覺用的人要少一些。

最開始,我以為 P 社的數(shù)據(jù)文件是偏向于后一種 json 模式。但實際研究下來又覺得有很大的不同。今天我嘗試用 lpeg 寫了一個簡單的 parser 試圖把它讀進(jìn) lua vm ,寫完 parser 后突然醒悟過來,其實它就是基于的嵌套 list ,不正是 lisp 嗎?想明白這點后,有種醍醐灌頂?shù)母杏X,的確 lisp 模式要比 json 模式簡潔的多,并不比 csv 模式復(fù)雜。但表達(dá)能力卻強(qiáng)于它們兩者,的確是一個更好的數(shù)據(jù)組織方案。

我們來看一個從群星中隨便摘錄的例子(有點長,但挺有代表性):

  1. country_event = { 
  2.     id = primitive.16 
  3.     hide_window = yes 
  4.  
  5.     trigger = { 
  6.         is_country_type = primitive 
  7.         has_country_flag = early_space_age 
  8.         #NOT = { has_country_flag = recently_advanced } 
  9.         OR = { 
  10.             AND = { 
  11.                 exists = from 
  12.                 from = { 
  13.                     OR = { 
  14.                         is_country_type = default 
  15.                         is_country_type = awakened_fallen_empire 
  16.                     } 
  17.                 } 
  18.             } 
  19.             years_passed > 25 
  20.         } 
  21.     } 
  22.  
  23.     mean_time_to_happen = { 
  24.         years = 100 
  25.  
  26.         modifier = { 
  27.             factor = 0.6 
  28.             has_country_flag = acquired_tech 
  29.         } 
  30.     } 
  31.  
  32.     immediate = { 
  33.         remove_country_flag = early_space_age 
  34.         set_country_flag = primitives_can_into_space 
  35.         set_country_type = default 
  36.         change_country_flag = random 
  37.         if = { 
  38.             limit = { is_species_class = MAM } 
  39.             set_graphical_culture = mammalian_01 
  40.         } 
  41.         if = { 
  42.             limit = { is_species_class = REP } 
  43.             set_graphical_culture = reptilian_01 
  44.         } 
  45.         if = { 
  46.             limit = { is_species_class = AVI } 
  47.             set_graphical_culture = avian_01 
  48.         } 
  49.         if = { 
  50.             limit = { is_species_class = ART } 
  51.             set_graphical_culture = arthropoid_01 
  52.         } 
  53.         if = { 
  54.             limit = { is_species_class = MOL } 
  55.             set_graphical_culture = molluscoid_01 
  56.         } 
  57.         if = { 
  58.             limit = { is_species_class = FUN } 
  59.             set_graphical_culture = fungoid_01 
  60.         } 
  61.         change_government = { 
  62.             authority = random 
  63.             civics = random 
  64.         } 
  65.         set_name = random 
  66.         if = { 
  67.             limit = { 
  68.                 home_planet = { 
  69.                     has_observation_outpost = yes 
  70.                 } 
  71.             } 
  72.             home_planet = { 
  73.                 observation_outpost_owner = { 
  74.                     country_event = { id = primitive.17 } 
  75.                 } 
  76.             } 
  77.         } 
  78.         add_minerals = 1000 # enough for a spaceport and then some 
  79.         add_energy = 500 
  80.         add_influence = 300 
  81.         capital_scope = { 
  82.             every_tile = { 
  83.                 limit = { 
  84.                     has_blocker = yes 
  85.                     NOR = { 
  86.                         has_blocker = tb_decrepit_dwellings 
  87.                         has_blocker = tb_failing_infrastructure 
  88.                     } 
  89.                 } 
  90.                 remove_blocker = yes 
  91.             } 
  92.             while = { 
  93.                 limit = {  
  94.                     num_pops < 8 
  95.                     any_tile = { 
  96.                         has_grown_pop = no 
  97.                         has_growing_pop = no 
  98.                         has_blocker = no 
  99.                     } 
  100.                 } 
  101.                 random_tile = { 
  102.                     limit = { 
  103.                         has_grown_pop = no 
  104.                         has_growing_pop = no 
  105.                         has_blocker = no 
  106.                     } 
  107.                     create_pop = { 
  108.                         species = owner 
  109.                     } 
  110.                 } 
  111.             } 
  112.             random_tile = { 
  113.                 limit = { 
  114.                     has_grown_pop = yes 
  115.                     OR = { 
  116.                         has_building = "building_primitive_farm" 
  117.                         has_building = "building_primitive_factory" 
  118.                         has_building = no 
  119.                     } 
  120.                 } 
  121.                 clear_deposits = yes 
  122.                 add_deposit = d_mineral_food_deposit 
  123.                 set_building = "building_capital_2" 
  124.             } 
  125.             random_tile = { 
  126.                 limit = { 
  127.                     has_grown_pop = yes 
  128.                     OR = { 
  129.                         has_building = "building_primitive_farm" 
  130.                         has_building = "building_primitive_factory" 
  131.                         has_building = no 
  132.                     } 
  133.                 } 
  134.                 clear_deposits = yes 
  135.                 add_deposit = d_mineral_deposit 
  136.                 set_building = "building_mining_network_1" 
  137.             } 
  138.             random_tile = { 
  139.                 limit = { 
  140.                     has_grown_pop = yes 
  141.                     OR = { 
  142.                         has_building = "building_primitive_farm" 
  143.                         has_building = "building_primitive_factory" 
  144.                         has_building = no 
  145.                     } 
  146.                 } 
  147.                 clear_deposits = yes 
  148.                 add_deposit = d_mineral_deposit 
  149.                 set_building = "building_mining_network_1" 
  150.             } 
  151.             random_tile = { 
  152.                 limit = { 
  153.                     has_grown_pop = yes 
  154.                     OR = { 
  155.                         has_building = "building_primitive_farm" 
  156.                         has_building = "building_primitive_factory" 
  157.                         has_building = no 
  158.                     } 
  159.                 } 
  160.                 clear_deposits = yes 
  161.                 add_deposit = d_farmland_deposit 
  162.                 set_building = "building_hydroponics_farm_1" 
  163.             } 
  164.             random_tile = { 
  165.                 limit = { 
  166.                     has_grown_pop = yes 
  167.                     OR = { 
  168.                         has_building = "building_primitive_farm" 
  169.                         has_building = "building_primitive_factory" 
  170.                         has_building = no 
  171.                     } 
  172.                 } 
  173.                 clear_deposits = yes 
  174.                 add_deposit = d_farmland_deposit 
  175.                 set_building = "building_hydroponics_farm_1" 
  176.             } 
  177.             random_tile = { 
  178.                 limit = { 
  179.                     has_grown_pop = yes 
  180.                     OR = { 
  181.                         has_building = "building_primitive_farm" 
  182.                         has_building = "building_primitive_factory" 
  183.                         has_building = no 
  184.                     } 
  185.                 } 
  186.                 clear_deposits = yes 
  187.                 add_deposit = d_energy_deposit 
  188.                 set_building = "building_power_plant_1" 
  189.             } 
  190.             random_tile = { 
  191.                 limit = { 
  192.                     has_grown_pop = yes 
  193.                     OR = { 
  194.                         has_building = "building_primitive_farm" 
  195.                         has_building = "building_primitive_factory" 
  196.                         has_building = no 
  197.                     } 
  198.                 } 
  199.                 clear_deposits = yes 
  200.                 add_deposit = d_energy_deposit 
  201.                 set_building = "building_power_plant_1" 
  202.             } 
  203.             random_tile = { 
  204.                 limit = { 
  205.                     has_grown_pop = yes 
  206.                     OR = { 
  207.                         has_building = "building_primitive_farm" 
  208.                         has_building = "building_primitive_factory" 
  209.                         has_building = no 
  210.                     } 
  211.                 } 
  212.                 clear_deposits = yes 
  213.                 add_deposit = d_energy_deposit 
  214.                 set_building = "building_power_plant_1" 
  215.             } 
  216.             remove_all_armies = yes 
  217.             create_army = { 
  218.                 name = random 
  219.                 owner = PREV 
  220.                 species = owner_main_species 
  221.                 type = "defense_army" 
  222.             } 
  223.             create_army = { 
  224.                 name = random 
  225.                 owner = PREV 
  226.                 species = owner_main_species 
  227.                 type = "defense_army" 
  228.             } 
  229.             create_army = { 
  230.                 name = random 
  231.                 owner = PREV 
  232.                 species = owner_main_species 
  233.                 type = "defense_army" 
  234.             } 
  235.             create_army = { 
  236.                 name = random 
  237.                 owner = PREV 
  238.                 species = owner_main_species 
  239.                 type = "defense_army" 
  240.             } 
  241.         } 
  242.         random_owned_ship = { 
  243.             limit = { is_ship_size = primitive_space_station } 
  244.             fleet = { destroy_fleet = THIS } 
  245.         } 
  246.     } 

起初,我很疑惑在這個格式中,為啥賦值和相等都用的 = ,這不是容易引起歧義么?但是你從 lisp 的角度來看就簡單了。等于號只是為了便于策劃書寫和閱讀的一個變形。所謂 id = primitive.16 你可以理解為 ( id, primitive.16 ) 而 iscountrytype = default 一樣可以理解為 ( iscountrytype , default ) 。 而

  1. create_army = { 
  2.                 name = random 
  3.                 owner = PREV 
  4.                 species = owner_main_species 
  5.                 type = "defense_army" 
  6.             } 

本質(zhì)上是 ( create_army , ( ( name, random ) , (owner, PREV), (species, owner_main_species), (type, "defense_army") ) )。

基礎(chǔ)數(shù)據(jù)結(jié)構(gòu)只要能表達(dá)出來,怎么理解這些 list 是更上層的工作,這就和我們在 csv 中去模擬樹結(jié)構(gòu)是一樣的道理。只不過 years_passed > 25 這樣的東西,被翻譯成 ( years_passed, > , 25 ) 有三個元素。上層解析的時候,如果確定它是一個邏輯表達(dá)式,就很容易在 2 個元素的 list 中間插入一個 = 補(bǔ)全。

這種結(jié)構(gòu)很容易描述一些控制結(jié)構(gòu),比如上面例子中的 if 。我還在其它數(shù)據(jù)中發(fā)現(xiàn)了 repeat while 等控制結(jié)構(gòu),這些都是上層的工作,和底層數(shù)據(jù)模型無關(guān)。但不得不說,lisp 模式比 csv 模式更容易做此類控制結(jié)構(gòu)。

把這種數(shù)據(jù)結(jié)構(gòu)翻譯成 lua 也很容易:只需要用 lua table 的 array 來保存即可。但為了使用方便,可以加一個代理結(jié)構(gòu)。如果上層業(yè)務(wù)想把一個 list 解析成字典,就在 cache 中臨時生成一個 hash 表加快查詢即可。我們甚至可以把它直接存在 C 內(nèi)存中,只在 lua 中暴露出遍歷以及高層的訪問方法。所謂高層的訪問方法指,可以直接讀取 if repeat 等控制結(jié)構(gòu),或是把帶 AND OR 這樣的復(fù)合 list 直接翻譯成一個條件表達(dá)式。

原文鏈接:https://blog.codingnow.com/2017/07/paradox_data_format.html#more

【本文為51CTO專欄作者“云風(fēng)”的原創(chuàng)稿件,轉(zhuǎn)載請通過51CTO聯(lián)系原作者獲取授權(quán)】

責(zé)任編輯:xinxiaoliang 來源: 51CTO專欄
相關(guān)推薦

2019-11-18 09:00:10

大數(shù)據(jù)數(shù)據(jù)格式文件格式

2012-05-29 09:06:32

Hadoop文件格式

2012-05-29 09:48:21

Hadoop

2016-12-01 14:47:20

2010-08-03 15:40:30

NFS文件格式

2023-11-02 09:54:21

ODT文件

2021-09-29 15:52:26

計算機(jī)配置文件語言

2010-07-13 14:09:07

SQL Server數(shù)

2010-11-03 15:15:26

DB2數(shù)據(jù)移動

2020-04-26 10:49:37

大數(shù)據(jù)Hadoop文件格式

2010-08-02 14:19:28

DB2數(shù)據(jù)庫

2017-06-16 09:58:34

Hive格式壓縮算法

2011-03-03 10:48:36

DB2數(shù)據(jù)庫外部文件

2010-08-02 11:38:43

DB2外部文件格式

2009-06-02 14:12:26

Hibernate配置文件格式

2024-03-17 19:14:28

2010-10-29 14:03:39

Oracle移動數(shù)據(jù)文

2010-10-13 14:02:01

MySQL數(shù)據(jù)文件

2009-07-20 09:44:31

DB2外部文件格式

2010-04-30 16:01:17

點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 在线观看黄视频 | 亚洲欧洲成人 | 午夜影院 | 国产乱码精品1区2区3区 | 亚洲成av | 国产精品久久久久久一区二区三区 | 亚洲精品在线视频 | 99精品免费久久久久久日本 | 精品一区二区在线观看 | 亚洲一区二区精品 | 欧美成人精品 | 日韩国产在线观看 | 欧美综合国产精品久久丁香 | 国产在线观看一区 | 自拍偷拍精品 | 亚洲免费一区二区 | 中文字幕高清视频 | 亚洲精品福利视频 | 精品一区二区三区在线视频 | 精品国产乱码久久久久久闺蜜 | 亚洲国产精品一区二区久久 | 日韩免费视频 | 亚洲逼院| av大片| 日韩a视频 | 久久久久久国产精品免费免费狐狸 | 久久99精品国产自在现线小黄鸭 | 人人干人人玩 | 欧美日韩精品免费观看 | 久久久久亚洲精品中文字幕 | 91久久久久久久久 | 国产精品高潮呻吟久久久久 | 亚洲综合色自拍一区 | 国内毛片毛片毛片毛片 | 日韩视频在线观看一区二区 | 特级黄一级播放 | 国产一区二区三区精品久久久 | 精品国产成人 | 在线观看中文字幕 | 美女张开腿露出尿口 | 国产成人精品久久二区二区 |