{"action":"created","issue":{"url":"https://api.github.com/repos/pioneerspacesim/pioneer/issues/3254","labels_url":"https://api.github.com/repos/pioneerspacesim/pioneer/issues/3254/labels{/name}","comments_url":"https://api.github.com/repos/pioneerspacesim/pioneer/issues/3254/comments","events_url":"https://api.github.com/repos/pioneerspacesim/pioneer/issues/3254/events","html_url":"https://github.com/pioneerspacesim/pioneer/pull/3254","id":49724824,"number":3254,"title":"Law and order to lua","user":{"login":"impaktor","id":619390,"avatar_url":"https://avatars.githubusercontent.com/u/619390?v=3","gravatar_id":"","url":"https://api.github.com/users/impaktor","html_url":"https://github.com/impaktor","followers_url":"https://api.github.com/users/impaktor/followers","following_url":"https://api.github.com/users/impaktor/following{/other_user}","gists_url":"https://api.github.com/users/impaktor/gists{/gist_id}","starred_url":"https://api.github.com/users/impaktor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/impaktor/subscriptions","organizations_url":"https://api.github.com/users/impaktor/orgs","repos_url":"https://api.github.com/users/impaktor/repos","events_url":"https://api.github.com/users/impaktor/events{/privacy}","received_events_url":"https://api.github.com/users/impaktor/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pioneerspacesim/pioneer/labels/in%20progress","name":"in progress","color":"ededed"},{"url":"https://api.github.com/repos/pioneerspacesim/pioneer/labels/New%20feature","name":"New feature","color":"005000"},{"url":"https://api.github.com/repos/pioneerspacesim/pioneer/labels/Savegame%20bump","name":"Savegame bump","color":"ff7fff"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2014-11-21T17:32:15Z","updated_at":"2015-09-15T17:49:21Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/pioneerspacesim/pioneer/pulls/3254","html_url":"https://github.com/pioneerspacesim/pioneer/pull/3254","diff_url":"https://github.com/pioneerspacesim/pioneer/pull/3254.diff","patch_url":"https://github.com/pioneerspacesim/pioneer/pull/3254.patch"},"body":"# Move Law to Lua\r\n\r\nThis moves the law enforcement from `Polit.cpp` (which is almost empty now) to lua. I worked on this about 6 months ago, but I got stuck due to a segfault when loading a game, but it seems to have fixed itself now (after updating branch to master).\r\n\r\n__Update:__ as of 2015-08 I'm continuing this due to #887 being \"fixed\". \r\n\r\n\r\n## Changed/New features\r\n\r\nSome of the changes in how police will behave now:\r\n\r\n1. Police number, and how quickly they react to your crimes (police launch probability) depends on system lawlessness.\r\n2. However, police will not launch until player has amassed high enough fines. I.e. threshold isn't `fine = 0` anymore, but `maxFineTolerated=1e3`\r\n3. Lowered fine on piracy to `1e5`, and weapons discharge to `1e2`, allowing the latter to be below the `maxFineTolerated` level.\r\n4. Dumping illegal goods or goods with negative price (close to station) is an offense.\r\n5. Crime record now lists _how many_ of each crime type the player has.\r\n6. Player has two crimerecords for each faction, one with \"outstanding fines\", and one \"Crimerecord\" with past history.\r\n7. A police ship destroyed at a station remains so until player hyperjumps back (same as before I believe); i.e. limited number of police ships in station.\r\n8. Police ships are different for different factions. Default: sinonatrix, CIW: pumpkinseed, SolFed: kanara.\r\n\r\n\r\n## Design / Code\r\n\r\nI'm not sure about what code to put in which file, i.e. how to structure it. Current structure reflects a lot of the development history during my work on this.\r\n\r\n- I've introduced a `libs/Legal.Lua` that holds the crime constants, and a `notifyOfCrime()` which was previously in `Polit.cpp`.\r\n\r\n- I've introduced a  `modules/CrimeTracking` to be symmetric with our `modules/StatsTracking`. It has the event triggers (`onShip<ActionX>`) for killing, firing, jettison, etc. and it holds the `doLawAndOrder()` (previously in `SpaceStation.cpp`).\r\n\r\n- `libs/Player.lua` has a local CrimeRecord class, which the player has two copies of for each faction (current crimes, and past crimes). There are also Player:AddCrime() and such.\r\n\r\n-  In the old (current master) code, each space station upholds the law (every frame) by calling the function DoLawAndOrder. I could implement it the same way in `libs/SpaceStation.lua`, but thought it needs only be called _once_ (about every 5 seconds), at which point a check is made to find the closest space station (calls a new method: `Ship:GetLawEnforcingStations()`, returns stations within \"law range\"), thus you will not be fined twice for one single illegal action done within range of both stations. (I still have to check the distance of the player to all stations every call.)\r\n\r\n- \"law range\" is a new attribute: `Station.lawEnforcedRange` (100 km).\r\n\r\n- Stations have a `SpaceStation:LaunchPolice(targetShip)` and `Station:LandPolice()`.\r\n\r\n\r\n## Progress\r\n\r\n- [x] 1. Remove all crime handling from c++\r\n- [x] 2. Implement crime handling in Lua (kind of done), closes #1055\r\n- [x] 3. Crime record shows number of violations of each type\r\n- [x] 4. Police ship set by faction definition, fixes #1237\r\n- [x] 5. Deny launch clearance if player has unpaid fines, fixes #62\r\n- [x] 6. Dumping cargo with negative price (close to station) is a crime, fixes #873\r\n- [x] 7. Police is launched first after some threshold of illegal actions is passed, closes #1731\r\n- [x] 8. Crime record in Lua is a class\r\n- [x] 9. Better methods for getting at the player's crimes in the `Player.record` table?\r\n- [x] 10. Fix frequent crashes when a police ship is dead (#887)\r\n- [x] 11. Implement a `Player:ClearCrimeFine`, and clean up comments in `lib/Player.lua`\r\n- [x] 12. Test-test-test: Save/Load when chased by police and killed police and test again\r\n- [x] 13. Moved Crime constants work in translation system\r\n- [x] 14. Store settled crimes in an old crime record and still remember them\r\n- [x] 15. Check natural doc rendering of API documenting strings\r\n\r\n## For another separate pull request:\r\n\r\nWhen this is merged, I'll be looking into:\r\n\r\n1. Label police ships after the police name used by the faction, requires JSON to faction (It is really cool when the launched police is labeled as \"Confederate Police\" instead of just \"Police\".) see: #2867\r\n2. Fix legal footer, #2863.\r\n3. Find a better way of compounding fines in `NotifyOfCrime`. For now: works as it used to.\r\n4. taking off when denied launch clearance is a crime\r\n5. Number of available police ships should depend on station size?\r\n6. Pay fines remotely by F4.\r\n7. `IsCommodityLegal` should be in lua? "},"comment":{"url":"https://api.github.com/repos/pioneerspacesim/pioneer/issues/comments/140480191","html_url":"https://github.com/pioneerspacesim/pioneer/pull/3254#issuecomment-140480191","issue_url":"https://api.github.com/repos/pioneerspacesim/pioneer/issues/3254","id":140480191,"user":{"login":"fluffyfreak","id":825083,"avatar_url":"https://avatars.githubusercontent.com/u/825083?v=3","gravatar_id":"","url":"https://api.github.com/users/fluffyfreak","html_url":"https://github.com/fluffyfreak","followers_url":"https://api.github.com/users/fluffyfreak/followers","following_url":"https://api.github.com/users/fluffyfreak/following{/other_user}","gists_url":"https://api.github.com/users/fluffyfreak/gists{/gist_id}","starred_url":"https://api.github.com/users/fluffyfreak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fluffyfreak/subscriptions","organizations_url":"https://api.github.com/users/fluffyfreak/orgs","repos_url":"https://api.github.com/users/fluffyfreak/repos","events_url":"https://api.github.com/users/fluffyfreak/events{/privacy}","received_events_url":"https://api.github.com/users/fluffyfreak/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T17:49:21Z","updated_at":"2015-09-15T17:49:21Z","body":"Ok, I have `278 Unlaful weapon discharge` and a `$178` fine but no police have come after me yet."}}