~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/scripting/lua_map.cc

  • Committer: The Widelands Bunnybot
  • Date: 2021-08-28 12:54:46 UTC
  • Revision ID: bunnybot@widelands.org-20210828125446-vpkewmaans3rbg3t
Support having more than 2 carriers on a road (#4938)

(by Noordfrees)
d355de63cb10d08ed55f348d165d53f139588841

Show diffs side-by-side

added added

removed removed

Lines of Context:
320
320
        if (r.descr().type() == Widelands::MapObjectType::WATERWAY) {
321
321
                valid_workers.insert(WorkerAmount(r.owner().tribe().ferry(), 1));
322
322
        } else {
323
 
                valid_workers.insert(WorkerAmount(r.owner().tribe().carrier(), 1));
324
323
                upcast(const Widelands::Road, road, &r);
325
324
                assert(road);
326
325
                if (road->is_busy()) {
327
 
                        valid_workers.insert(WorkerAmount(r.owner().tribe().carrier2(), 1));
 
326
                        for (Widelands::DescriptionIndex c : r.owner().tribe().carriers()) {
 
327
                                valid_workers.insert(WorkerAmount(c, 1));
 
328
                        }
 
329
                } else {
 
330
                        valid_workers.insert(WorkerAmount(r.owner().tribe().carriers()[0], 1));
328
331
                }
329
332
        }
330
333
 
1792
1795
const PropertyType<LuaTribeDescription> LuaTribeDescription::Properties[] = {
1793
1796
   PROP_RO(LuaTribeDescription, buildings),
1794
1797
   PROP_RO(LuaTribeDescription, builder),
 
1798
   PROP_RO(LuaTribeDescription, carriers),
1795
1799
   PROP_RO(LuaTribeDescription, carrier),
1796
1800
   PROP_RO(LuaTribeDescription, carrier2),
1797
1801
   PROP_RO(LuaTribeDescription, ferry),
1861
1865
}
1862
1866
 
1863
1867
/* RST
 
1868
   .. attribute:: carriers
 
1869
 
 
1870
      .. versionadded:: 1.1
 
1871
 
 
1872
      (RO) An :class:`array` of the internal names of the carrier types that this tribe uses as
 
1873
      :class:`string`.
 
1874
*/
 
1875
 
 
1876
int LuaTribeDescription::get_carriers(lua_State* L) {
 
1877
        const Widelands::TribeDescr& tribe = *get();
 
1878
        lua_newtable(L);
 
1879
        int counter = 0;
 
1880
        for (Widelands::DescriptionIndex c : tribe.carriers()) {
 
1881
                lua_pushinteger(L, ++counter);
 
1882
                lua_pushstring(L, tribe.get_worker_descr(c)->name());
 
1883
                lua_settable(L, -3);
 
1884
        }
 
1885
        return 1;
 
1886
}
 
1887
 
 
1888
/* RST
1864
1889
   .. attribute:: carrier
1865
1890
 
 
1891
      .. deprecated:: 1.1 Use :attr:`carriers` instead.
 
1892
 
1866
1893
      (RO) The internal name of the carrier type that this tribe uses as
1867
1894
      :class:`string`.
1868
1895
*/
1869
1896
 
1870
1897
int LuaTribeDescription::get_carrier(lua_State* L) {
1871
 
        lua_pushstring(L, get_egbase(L).descriptions().get_worker_descr(get()->carrier())->name());
 
1898
        lua_pushstring(L, get_egbase(L).descriptions().get_worker_descr(get()->carriers()[0])->name());
1872
1899
        return 1;
1873
1900
}
1874
1901
 
1875
1902
/* RST
1876
1903
   .. attribute:: carrier2
1877
1904
 
1878
 
      (RO) The internal name of the carrier2 type that this tribe uses as
 
1905
      .. deprecated:: 1.1 Use :attr:`carriers` instead.
 
1906
 
 
1907
      (RO) The internal name of the secondary carrier type that this tribe uses as
1879
1908
      :class:`string`.
1880
1909
*/
1881
1910
 
1882
1911
int LuaTribeDescription::get_carrier2(lua_State* L) {
1883
 
        lua_pushstring(L, get_egbase(L).descriptions().get_worker_descr(get()->carrier2())->name());
 
1912
        lua_pushstring(L, get_egbase(L).descriptions().get_worker_descr(get()->carriers()[1])->name());
1884
1913
        return 1;
1885
1914
}
1886
1915