Skip to content

Instantly share code, notes, and snippets.

@livibetter
Created February 27, 2011 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save livibetter/846173 to your computer and use it in GitHub Desktop.
Save livibetter/846173 to your computer and use it in GitHub Desktop.
Cheating on Widelands
map = wl.Game().map
my_name = map.player_slots[1].name
my_tribe = map.player_slots[1].tribe
bar_goods = {
"raw_stone", "fish", "coal", "pick", "axe",
"trunk", "meat", "ironore", "felling_axe", "sharpaxe",
"blackwood", "water", "iron", "shovel", "broadaxe",
"grout", "wheat", "goldstone", "hammer", "bronzeaxe",
"thatchreed", "pittabread", "gold", "fishing_rod", "battleaxe",
"cloth", "beer", "hunting_spear", "warriorsaxe",
"strongbeer", "scythe", "helm",
"ration", "bakingtray", "mask",
"snack", "kitchen_tools", "warhelmet",
"meal", "fire_tongs",
}
emp_goods = {
"stone", "fish", "marble", "pick", "wood_lance",
"trunk", "meat", "marblecolumn", "axe", "lance",
"wood", "water", "coal", "saw", "advanced_lance",
"wool", "wheat", "ironore", "shovel", "heavy_lance",
"cloth", "flour", "iron", "hammer", "war_lance",
"bread", "goldstone", "fishing_rod", "helm",
"beer", "gold", "hunting_spear", "armour",
"grape", "scythe", "chain_armour",
"wine", "bakingtray", "plate_armour",
"ration", "basket",
"meal", "kitchen_tools",
"fire_tongs",
}
atl_goods = {
"stone", "fish", "quartz", "pick", "light_trident",
"trunk", "smoked_fish", "diamond", "saw", "long_trident",
"planks", "meat", "coal", "shovel", "steel_trident",
"spideryarn", "smoked_meat", "ironore", "hammer", "double_trident",
"spidercloth", "water", "iron", "milking_tongs", "heavy_double_trident",
"corn", "goldore", "fishing_net", "steel_shield",
"cornflour", "gold", "bucket", "advanced_shield",
"blackroot", "hunting_bow", "tabard",
"blackrootflour", "hook_pole", "goldyarn",
"bread", "scythe", "golden_tabard",
"bakingtray",
"fire_tongs",
}
good_tribes = {
barbarians = bar_goods,
empire = emp_goods,
atlanteans = atl_goods,
}
goods = {}
for _, good in ipairs(good_tribes[my_tribe]) do
if (my_tribe == 'barbarians' and good == 'axe') or
(my_tribe == 'empire' and good == 'wood_lance') or
(my_tribe == 'atlanteans' and good == 'tabard') then
-- Make sure no chicken soliders {0, 0, 0, 0}
goods[good] = 0
else
goods[good] = 999
end
end
solider_tribes = {
barbarians = {3,5,0,2},
empire = {4,4,0,2},
atlanteans = {1,4,2,2},
}
soliders = solider_tribes[my_tribe]
-- 999 in warehouse
function w999()
p = wl.Game().players[1]
whs = p:get_buildings('warehouse')
for _, hq in ipairs(p:get_buildings('headquarters')) do table.insert(whs, hq) end
-- for _, hq in ipairs(p:get_buildings('headquarters_interim')) do table.insert(whs, hq) end
for _, wh in ipairs(whs) do wh:set_wares(goods) end
end
-- soldiers warehouse
function sw(count)
count = count or 100
p = wl.Game().players[1]
whs = p:get_buildings('warehouse')
for _, hq in ipairs(p:get_buildings('headquarters')) do table.insert(whs, hq) end
-- for _, hq in ipairs(p:get_buildings('headquarters_interim')) do table.insert(whs, hq) end
for _, wh in ipairs(whs) do wh:set_soldiers({[soliders] = count}) end
end
-- soldiers military
function sm()
ims = {}
for x = 0, map.width-1 do
for y = 0, map.height-1 do
f = map:get_field(x, y)
im = f.immovable
if im and f.owner and f.owner.name == my_name then
main_field = im.fields[1].x + im.fields[1].y * map.width
if im.type == 'militarysite' and ims[main_field] == nil then
im:set_soldiers({[soliders] = im.max_soldiers})
ims[main_field] = true
end
end
end
end
end
-- no tress, no stones
function ntns()
ims = {}
for x = 0, map.width-1 do
for y = 0, map.height-1 do
f = map:get_field(x, y)
im = f.immovable
if im and f.owner and f.owner.name == my_name then
if string.find(im.name, 'tree') or string.find(im.name, 'stones') then
im:remove()
end
end
end
end
end
-- aspca (anti-spca)
function aspca()
bobs = {}
for _, bob in ipairs({'brownbear', 'bunny', 'chamois', 'deer', 'duck', 'elk', 'fox', 'lynx', 'marten', 'reindeer', 'sheep', 'wisent', 'wolf'}) do
bobs[bob] = 1
end
for x = 0, map.width-1 do
for y = 0, map.height-1 do
f = map:get_field(x, y)
if f.owner and f.owner.name == my_name then
for _, bob in pairs(f.bobs) do
-- if bob.name ~= 'carrier' and bob.name ~= 'soldier' then
-- print(bob.name)
-- end
if bobs[bob.name] then
bob:remove()
end
end
end
end
end
end
-- Causes Segmentation fault :(
function suicidalbob()
players = wl.Game().players
my_team = players[1].team
names = {}
for idx = 2, #players do
if my_team == 0 or my_team ~= players[idx].team then
names[players[idx].name] = true
end
end
for x = 0, map.width-1 do
for y = 0, map.height-1 do
f = map:get_field(x, y)
if f.owner and names[f.owner.name] then
for _, bob in pairs(f.bobs) do
if bob.name == 'carrier' then
bob:remove()
end
end
end
end
end
end
-- Causes Segmentation fault :(
function ghosttown()
players = wl.Game().players
my_team = players[1].team
names = {}
for idx = 2, #players do
if my_team == 0 or my_team ~= players[idx].team then
names[players[idx].name] = true
end
end
for x = 0, map.width-1 do
for y = 0, map.height-1 do
f = map:get_field(x, y)
if f.owner and names[f.owner.name] then
for _, bob in pairs(f.bobs) do
bob:remove()
end
end
end
end
end
function blacksheepwall()
wl.Game().players[1].see_all = true
end
function blind()
wl.Game().players[1].see_all = false
end
function manovergame()
end
function controlfreak()
wl.Game().players[1]:conquer(
map:get_field(math.floor(map.width/2), math.floor(map.height/2)),
math.max(map.width, map.height)
)
end
-- Full house
function fh()
w999()
sm()
ntns()
aspca()
end
function letenemiesdothehardwork()
end
function burnbabyburn()
end
function asteroid()
end
function cq(plr, x, y, r)
-- FIXME need to remove everything doesn't belong to plr, or game may exits.
wl.Game().players[plr]:conquer(wl.Game().map:get_field(x, y), r)
end
function pb(plr, name, x, y)
wl.Game().players[plr]:place_building(name, wl.Game().map:get_field(x, y))
end
function rmim(x, y)
wl.Game().map:get_field(x, y).immovable:remove()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment