Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#3477 closed enhancement (fixed)

[PATCH] Add a meta-cheat to abbreviate others

Reported by: elexis Owned by: elexis
Priority: Nice to Have Milestone: Alpha 20
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

When doing test-games with cheats enabled, you have to type many sentences in order to activate all required cheats. If you have to repeat this process a couple of times (for example when reproducing a given bug) it becomes annoying quickly.

The usual cheats are:

  • "the hive master" (full population capacity)
  • "i am too busy" (build structures fast)
  • 2x "back to the future" (advance phase)

A new cheat could be introduced that acts as an abbreviation for those three cheats. It would make some sense to add the following cheats too, if we introduce such a meta-cheat:

  • i want pizza 100000 (add resources: food)
  • bring me my axe 100000 (add resources: wood)
  • your money or your life 100000 (add resources: metal)
  • i see a mountain here 100000 (add resources: stone)
  • TARDIS (500 population capacity)

This way you would have the additional benefit of not having to start with deathmatch resources.

See wiki:Manual_Cheats

Attachments (3)

ticket3477_metacheat.diff (3.7 KB ) - added by bb 9 years ago.
Working patch, implenting a metacheat "gift from the gods". Using exsisting functions (could change to direct cheating) and a loop around the resources might be needed.
ticket3477_metacheat_2.diff (7.2 KB ) - added by bb 9 years ago.
Improved style of "Cheat.js"
ticket3477_metacheat_3.diff (7.2 KB ) - added by bb 9 years ago.
Some more style improvements

Download all attachments as: .zip

Change History (11)

by bb, 9 years ago

Attachment: ticket3477_metacheat.diff added

Working patch, implenting a metacheat "gift from the gods". Using exsisting functions (could change to direct cheating) and a loop around the resources might be needed.

comment:1 by bb, 9 years ago

Keywords: patch review added
Milestone: BacklogAlpha 20
Summary: Add a meta-cheat to abbreviate others[PATCH] Add a meta-cheat to abbreviate others

comment:2 by elexis, 9 years ago

Looks good to me and it could probably be committed like that. The code could be simplified a bit more though:

  • AddResource:
    • Why have a type variable if you can just use the strings directly as the function argument?
    • using input.parameter as the second argument is good, but you could just add DefaultParameter to the JSON file instead of defining it in the javascript. Makes it a bit cleaner and the user could also change that value. (Also add the IsNumeric property then)
  • To further improve the style: Instead of manipulating the existing input object, use the cheat function like Cheat({ "action": "maxpopulation" }); Notice the whitespace (see @wiki:Coding_Conventions)
  • The early returns are good

Thank you for working on this! :)

in reply to:  2 comment:3 by bb, 9 years ago

  • To further improve the style: Instead of manipulating the existing input object, use the cheat function like Cheat({ "action": "maxpopulation" });

Changed the other things in my local version but when I change the statement above, I get crashes in the checks above the switch in "Cheat.js" when executing the function.

WARNING: JavaScript warning: simulation/helpers/Cheat.js line 4 reference to undefined property input.player

Probably because the "input" structure is not fully in the argument. So the "input.player" is not defined.

Notice the whitespace (see @wiki:Coding_Conventions)

Checked the code in "Cheat.js" on this and improved it :)

comment:4 by elexis, 9 years ago

Right, you will need to pass the "player" attribute too (maybe others too, didn't look at it), i.e.

Cheat({
   "player": input.player,
   "action": "maxpopulation"
});

(I think you could replace the calls to AddResources with a calls to Cheat too. Would be a bit more coherent, but that's not really needed)

by bb, 9 years ago

Attachment: ticket3477_metacheat_2.diff added

Improved style of "Cheat.js"

comment:5 by elexis, 9 years ago

Thanks for the cleanup, the existing code and your new code look even better than before.

  • case "addresource": I think we can remove the for-loop and text.input change, not used, only one resource will be added.
  • case "metacheat": wrong indentation
  • Cheat: misssing semicolons

by bb, 9 years ago

Attachment: ticket3477_metacheat_3.diff added

Some more style improvements

comment:6 by elexis, 8 years ago

Owner: set to elexis
Resolution: fixed
Status: newclosed

In 17329:

Adds a new cheat as an abbreviation for most other cheats. Also cleans the code.
Fixes #3477. Patch by bb.

comment:7 by elexis, 8 years ago

Keywords: review removed

Thanks for the patch! :-) I removed some of the comments as the code should be clear enough already, one space after a return and one tab before 'case "metaCheat":'. Also I used a loop so we don't repeat code.

comment:8 by elexis, 8 years ago

In 17330:

Forgot to add the JSON file. Refs #3477.

Note: See TracTickets for help on using tickets.